1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

nix flake show: log attribute name that "must be a derivation"

I would run `nix flake show` on a flake than hit:

===
        ├───ihaskell: package 'ihaskell-wrapper'
        ├───ihaskell-96: package 'ihaskell-wrapper'
        ├───ihaskell-96-dev: package 'ghc-shell-for-ihaskell-0.10.4.0'
error: expected a derivation
===
and it is not obvious what package is the culprit here since nix stops
rightaway.


Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
Matthieu Coudron 2023-08-27 00:29:05 +02:00 committed by teto
parent ef8218f2e3
commit ac9d2a5b06
2 changed files with 27 additions and 2 deletions

View file

@ -1303,8 +1303,10 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
try { try {
if (visitor.isDerivation()) if (visitor.isDerivation())
showDerivation(); showDerivation();
else else {
throw Error("expected a derivation"); auto name = visitor.getAttrPathStr(state->s.name);
logger->warn(fmt("%s is not a derivation", name));
}
} catch (IFDError & e) { } catch (IFDError & e) {
if (!json) { if (!json) {
logger->cout( logger->cout(

View file

@ -107,3 +107,26 @@ in
assert show_output.packages.${builtins.currentSystem}.default == { }; assert show_output.packages.${builtins.currentSystem}.default == { };
true true
' '
# Test that nix keeps going even when packages.$SYSTEM contains not derivations
cat >flake.nix <<EOF
{
outputs = inputs: {
packages.$system = {
drv1 = import ./simple.nix;
not-a-derivation = 42;
drv2 = import ./simple.nix;
};
};
}
EOF
nix flake show --json --all-systems > show-output.json
# shellcheck disable=SC2016
nix eval --impure --expr '
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
in
assert show_output.packages.${builtins.currentSystem}.not-a-derivation == {};
true
'