pass eval.nix as a file instead of expression
- passing it as expression gives large error messages which are not very readable - this commits puts the file in nix-store and patches the final program to have access to the path to the file as env. - We simply pass this file to nix-instantiate
This commit is contained in:
parent
bab997db72
commit
437b2054f4
@ -5,8 +5,10 @@
|
|||||||
rustfmt,
|
rustfmt,
|
||||||
clippy,
|
clippy,
|
||||||
mkShell,
|
mkShell,
|
||||||
|
makeWrapper,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
runtimeExprPath = "${./src/eval.nix}";
|
||||||
package =
|
package =
|
||||||
rustPlatform.buildRustPackage {
|
rustPlatform.buildRustPackage {
|
||||||
name = "nixpkgs-check-by-name";
|
name = "nixpkgs-check-by-name";
|
||||||
@ -16,7 +18,9 @@ let
|
|||||||
nix
|
nix
|
||||||
rustfmt
|
rustfmt
|
||||||
clippy
|
clippy
|
||||||
|
makeWrapper
|
||||||
];
|
];
|
||||||
|
env.NIX_CHECK_BY_NAME_EXPR_PATH = runtimeExprPath;
|
||||||
# Needed to make Nix evaluation work inside the nix build
|
# Needed to make Nix evaluation work inside the nix build
|
||||||
preCheck = ''
|
preCheck = ''
|
||||||
export TEST_ROOT=$(pwd)/test-tmp
|
export TEST_ROOT=$(pwd)/test-tmp
|
||||||
@ -34,7 +38,12 @@ let
|
|||||||
cargo fmt --check
|
cargo fmt --check
|
||||||
cargo clippy -- -D warnings
|
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 {
|
passthru.shell = mkShell {
|
||||||
|
env.NIX_CHECK_BY_NAME_EXPR_PATH = runtimeExprPath;
|
||||||
inputsFrom = [ package ];
|
inputsFrom = [ package ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -35,8 +35,6 @@ enum AttributeVariant {
|
|||||||
Other,
|
Other,
|
||||||
}
|
}
|
||||||
|
|
||||||
const EXPR: &str = include_str!("eval.nix");
|
|
||||||
|
|
||||||
/// Check that the Nixpkgs attribute values corresponding to the packages in pkgs/by-name are
|
/// Check that the Nixpkgs attribute values corresponding to the packages in pkgs/by-name are
|
||||||
/// of the form `callPackage <package_file> { ... }`.
|
/// of the form `callPackage <package_file> { ... }`.
|
||||||
/// See the `eval.nix` file for how this is achieved on the Nix side
|
/// See the `eval.nix` file for how this is achieved on the Nix side
|
||||||
@ -60,9 +58,9 @@ pub fn check_values(
|
|||||||
attrs_file_path.display()
|
attrs_file_path.display()
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
|
let expr_path = std::env::var("NIX_CHECK_BY_NAME_EXPR_PATH")?;
|
||||||
// With restrict-eval, only paths in NIX_PATH can be accessed, so we explicitly specify the
|
// With restrict-eval, only paths in NIX_PATH can be accessed, so we explicitly specify the
|
||||||
// ones needed needed
|
// ones needed needed
|
||||||
|
|
||||||
let mut command = process::Command::new("nix-instantiate");
|
let mut command = process::Command::new("nix-instantiate");
|
||||||
command
|
command
|
||||||
// Inherit stderr so that error messages always get shown
|
// Inherit stderr so that error messages always get shown
|
||||||
@ -76,8 +74,6 @@ pub fn check_values(
|
|||||||
"--readonly-mode",
|
"--readonly-mode",
|
||||||
"--restrict-eval",
|
"--restrict-eval",
|
||||||
"--show-trace",
|
"--show-trace",
|
||||||
"--expr",
|
|
||||||
EXPR,
|
|
||||||
])
|
])
|
||||||
// Pass the path to the attrs_file as an argument and add it to the NIX_PATH so it can be
|
// Pass the path to the attrs_file as an argument and add it to the NIX_PATH so it can be
|
||||||
// accessed in restrict-eval mode
|
// accessed in restrict-eval mode
|
||||||
@ -96,6 +92,8 @@ pub fn check_values(
|
|||||||
command.arg("-I");
|
command.arg("-I");
|
||||||
command.arg(path);
|
command.arg(path);
|
||||||
}
|
}
|
||||||
|
command.args(["-I", &expr_path]);
|
||||||
|
command.arg(expr_path);
|
||||||
|
|
||||||
let result = command
|
let result = command
|
||||||
.output()
|
.output()
|
||||||
|
Loading…
Reference in New Issue
Block a user