nixpkgs/pkgs/test/nixpkgs-check-by-name/default.nix
Silvan Mosberger aa7dd0b596 tests.nixpkgs-check-by-name: Improve lib path handling in tests
nix-build failed because the tests assume to run in a CWD equal to the
project root, which is not the case in the derivation build.

This commit fixes it by not using hacky `..` references to paths,
and instead uses NIX_PATH for all implicit Nix testing path
dependencies.

Also the root of the `lib` path gets passed in from the `default.nix`
file, so all the relative path handling is done by Nix during evaluation
already, and in the Nix store when possible.
2024-01-15 18:34:16 +01:00

56 lines
1.5 KiB
Nix

{
lib,
rustPlatform,
nix,
rustfmt,
clippy,
mkShell,
makeWrapper,
}:
let
runtimeExprPath = ./src/eval.nix;
nixpkgsLibPath = ../../../lib;
package =
rustPlatform.buildRustPackage {
name = "nixpkgs-check-by-name";
src = lib.cleanSource ./.;
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = [
nix
rustfmt
clippy
makeWrapper
];
env.NIX_CHECK_BY_NAME_EXPR_PATH = "${runtimeExprPath}";
# Needed to make Nix evaluation work inside the nix build
preCheck = ''
export TEST_ROOT=$(pwd)/test-tmp
export NIX_CONF_DIR=$TEST_ROOT/etc
export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
export NIX_STATE_DIR=$TEST_ROOT/var/nix
export NIX_STORE_DIR=$TEST_ROOT/store
export NIXPKGS_LIB_PATH=${nixpkgsLibPath}
# Ensure that even if tests run in parallel, we don't get an error
# We'd run into https://github.com/NixOS/nix/issues/2706 unless the store is initialised first
nix-store --init
'';
postCheck = ''
cargo fmt --check
cargo clippy -- -D warnings
'';
postInstall = ''
wrapProgram $out/bin/nixpkgs-check-by-name \
--set NIX_CHECK_BY_NAME_EXPR_PATH "$NIX_CHECK_BY_NAME_EXPR_PATH"
'';
passthru.shell = mkShell {
env.NIX_CHECK_BY_NAME_EXPR_PATH = toString runtimeExprPath;
env.NIXPKGS_LIB_PATH = toString nixpkgsLibPath;
inputsFrom = [ package ];
};
};
in
package