Skip to content

Commit

Permalink
Set up for testing multiple Nix versions
Browse files Browse the repository at this point in the history
While the parent commit makes it use a fixed Nix version,
we should also run test for other Nix versions.
  • Loading branch information
infinisil committed Jul 19, 2024
1 parent f55f7a6 commit c208c3e
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
lib,
rustPlatform,
nix,
nixVersions,
clippy,
makeWrapper,

nixVersionsToTest ? [
nix
nixVersions.stable
],

nixpkgsLibPath,
initNix,
runtimeExprPath,
Expand All @@ -28,15 +34,28 @@ rustPlatform.buildRustPackage {
};
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = [
nix
clippy
makeWrapper
];
env.NIX_CHECK_BY_NAME_EXPR_PATH = "${runtimeExprPath}";
env.NIX_CHECK_BY_NAME_NIX_PACKAGE = lib.getBin nix;
env.NIX_PATH = "test-nixpkgs=${testNixpkgsPath}:test-nixpkgs/lib=${nixpkgsLibPath}";
preCheck = initNix;
postCheck = ''
checkPhase = ''
# This path will be symlinked to the current version that is being tested
nixPackage=$(mktemp -d)/nix
# For initNix
export PATH=$nixPackage/bin:$PATH
# This is what nixpkgs-check-by-name uses
export NIX_CHECK_BY_NAME_NIX_PACKAGE=$nixPackage
${lib.concatMapStringsSep "\n" (nix: ''
ln -s ${lib.getBin nix} "$nixPackage"
echo "Testing with $(nix --version)"
${initNix}
runHook cargoCheckHook
rm "$nixPackage"
'') (lib.unique nixVersionsToTest)}
# --tests or --all-targets include tests for linting
cargo clippy --all-targets -- -D warnings
'';
Expand Down

0 comments on commit c208c3e

Please sign in to comment.