Skip to content

Add Nix flake for deterministic Nix builds (attempt 2)#909

Open
ThatOtherAndrew wants to merge 2 commits intodigraphs:mainfrom
ThatOtherAndrew:nix
Open

Add Nix flake for deterministic Nix builds (attempt 2)#909
ThatOtherAndrew wants to merge 2 commits intodigraphs:mainfrom
ThatOtherAndrew:nix

Conversation

@ThatOtherAndrew
Copy link

Nix is a functional programming language used for deterministic builds, by pinning environment "inputs" (e.g. gcc) to a specific version. This allows for a universal and deterministic nix build command which replaces the need for autogen, configure, and make.

This is a recreation of a previous PR (#906) which was messed up due to accidentally committing multiple features to the main branch. I have learned from my mistake and one sleepless night later my changes are properly branched now. oops!

Copilot AI review requested due to automatic review settings March 20, 2026 07:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Nix flake support to enable deterministic nix build / nix develop workflows for building the GAP Digraphs package from this repository.

Changes:

  • Introduce flake.nix defining a digraphs derivation and a development shell.
  • Pin Nixpkgs via flake.lock for reproducible builds.
  • Ignore the default Nix build symlink (result) in .gitignore.

Reviewed changes

Copilot reviewed 1 out of 3 changed files in this pull request and generated 5 comments.

File Description
flake.nix Defines Nix flake outputs (package + devShell) and the build/install steps for Digraphs.
flake.lock Pins nixpkgs revision/hash to make builds deterministic.
.gitignore Ignores the result symlink created by nix build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +40 to +53
configurePhase = ''
runHook preConfigure

# Generate the configure script
mkdir -p gen
aclocal -Wall --force
autoconf -Wall -f
autoheader -Wall -f

# Run configure, pointing at the GAP root
./configure --with-gaproot=${gaproot}

runHook postConfigure
'';
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom configurePhase calls ./configure without passing the standard Nix configure flags (e.g., --prefix=$out, build/host flags, and any configureFlags), which can lead to incorrect paths and reduced portability (especially for cross builds). Prefer using the default configurePhase with configureFlags = [ "--with-gaproot=..." ]; or, if keeping a custom phase, invoke ./configure with the standard flags included.

Copilot uses AI. Check for mistakes.
nativeBuildInputs = with pkgs; [
autoconf
automake
gcc
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nativeBuildInputs includes gcc, but this flake advertises Darwin support as well; forcing gcc can cause toolchain mismatches or failures on macOS where the default stdenv compiler is clang. Consider relying on stdenv.cc (already provided by mkDerivation) and drop gcc, or select an appropriate stdenv/toolchain per-system.

Suggested change
gcc

Copilot uses AI. Check for mistakes.

buildPhase = ''
runHook preBuild
make
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overridden buildPhase runs plain make, which bypasses the standard stdenv make flags (including parallelism and any makeFlags). To keep builds consistent and faster under Nix, either use the default buildPhase or call make with the stdenv-provided flags.

Suggested change
make
make $makeFlags

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +54
configurePhase = ''
runHook preConfigure

# Generate the configure script
mkdir -p gen
aclocal -Wall --force
autoconf -Wall -f
autoheader -Wall -f

# Run configure, pointing at the GAP root
./configure --with-gaproot=${gaproot}

runHook postConfigure
'';

Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flake reimplements the repo's existing ./autogen.sh logic inline. Using the script directly (or autoreconfHook) would reduce drift if the autogen steps change in the future and keeps the build definition simpler.

Suggested change
configurePhase = ''
runHook preConfigure
# Generate the configure script
mkdir -p gen
aclocal -Wall --force
autoconf -Wall -f
autoheader -Wall -f
# Run configure, pointing at the GAP root
./configure --with-gaproot=${gaproot}
runHook postConfigure
'';
preConfigure = ''
./autogen.sh
'';
configureFlags = [
"--with-gaproot=${gaproot}"
];

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +84
# Copy GAP source files
cp -r gap "$out/digraphs/"
cp -r lib "$out/digraphs/" 2>/dev/null || true
cp -r doc "$out/digraphs/" 2>/dev/null || true
cp -r data "$out/digraphs/" 2>/dev/null || true
cp -r tst "$out/digraphs/" 2>/dev/null || true

# Copy the compiled shared object
cp -r bin "$out/digraphs/"

# Copy package metadata files
cp PackageInfo.g "$out/digraphs/"
cp init.g "$out/digraphs/"
cp read.g "$out/digraphs/"
cp -r makedoc.g "$out/digraphs/" 2>/dev/null || true
cp LICENSE "$out/digraphs/" 2>/dev/null || true
cp CHANGELOG.md "$out/digraphs/" 2>/dev/null || true
cp README.md "$out/digraphs/" 2>/dev/null || true

Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The installPhase uses cp ... 2>/dev/null || true to ignore missing paths, which can silently produce incomplete outputs if a directory unexpectedly disappears or is renamed. Prefer explicit if [ -d ... ]; then ...; fi (or a single copy of an explicit file list) so packaging failures are surfaced when the layout changes.

Suggested change
# Copy GAP source files
cp -r gap "$out/digraphs/"
cp -r lib "$out/digraphs/" 2>/dev/null || true
cp -r doc "$out/digraphs/" 2>/dev/null || true
cp -r data "$out/digraphs/" 2>/dev/null || true
cp -r tst "$out/digraphs/" 2>/dev/null || true
# Copy the compiled shared object
cp -r bin "$out/digraphs/"
# Copy package metadata files
cp PackageInfo.g "$out/digraphs/"
cp init.g "$out/digraphs/"
cp read.g "$out/digraphs/"
cp -r makedoc.g "$out/digraphs/" 2>/dev/null || true
cp LICENSE "$out/digraphs/" 2>/dev/null || true
cp CHANGELOG.md "$out/digraphs/" 2>/dev/null || true
cp README.md "$out/digraphs/" 2>/dev/null || true
# Copy GAP source files (required)
cp -r gap "$out/digraphs/"
# Copy optional GAP directories if they exist
if [ -d lib ]; then
cp -r lib "$out/digraphs/"
fi
if [ -d doc ]; then
cp -r doc "$out/digraphs/"
fi
if [ -d data ]; then
cp -r data "$out/digraphs/"
fi
if [ -d tst ]; then
cp -r tst "$out/digraphs/"
fi
# Copy the compiled shared object (required)
cp -r bin "$out/digraphs/"
# Copy required package metadata files
cp PackageInfo.g "$out/digraphs/"
cp init.g "$out/digraphs/"
cp read.g "$out/digraphs/"
# Copy optional metadata / documentation files if they exist
if [ -f makedoc.g ]; then
cp makedoc.g "$out/digraphs/"
fi
if [ -f LICENSE ]; then
cp LICENSE "$out/digraphs/"
fi
if [ -f CHANGELOG.md ]; then
cp CHANGELOG.md "$out/digraphs/"
fi
if [ -f README.md ]; then
cp README.md "$out/digraphs/"
fi

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.35%. Comparing base (1f56fb0) to head (8c8a9fd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #909   +/-   ##
=======================================
  Coverage   97.35%   97.35%           
=======================================
  Files          50       50           
  Lines       21045    21045           
  Branches      639      639           
=======================================
  Hits        20489    20489           
  Misses        491      491           
  Partials       65       65           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants