blob: 8836da1f403f1e75e1f15fb972b85e5efca77ea6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
{
lib,
rustPlatform,
nix,
rustfmt,
clippy,
mkShell,
makeWrapper,
runCommand,
}:
let
runtimeExprPath = ./src/eval.nix;
nixpkgsLibPath = ../../../lib;
testNixpkgsPath = ./tests/mock-nixpkgs.nix;
# Needed to make Nix evaluation work inside nix builds
initNix = ''
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
# 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
'';
fs = lib.fileset;
package =
rustPlatform.buildRustPackage {
name = "nixpkgs-check-by-name";
src = fs.toSource {
root = ./.;
fileset = fs.unions [
./Cargo.lock
./Cargo.toml
./src
./tests
];
};
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = [
nix
rustfmt
clippy
makeWrapper
];
env.NIX_CHECK_BY_NAME_EXPR_PATH = "${runtimeExprPath}";
env.NIX_PATH = "test-nixpkgs=${testNixpkgsPath}:test-nixpkgs/lib=${nixpkgsLibPath}";
preCheck = initNix;
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.NIX_PATH = "test-nixpkgs=${toString testNixpkgsPath}:test-nixpkgs/lib=${toString nixpkgsLibPath}";
inputsFrom = [ package ];
};
# Tests the tool on the current Nixpkgs tree, this is a good sanity check
passthru.tests.nixpkgs = runCommand "test-nixpkgs-check-by-name" {
nativeBuildInputs = [
package
nix
];
nixpkgsPath = lib.cleanSource ../../..;
} ''
${initNix}
nixpkgs-check-by-name --base "$nixpkgsPath" "$nixpkgsPath"
touch $out
'';
};
in
package
|