Skip to content

Commit ac9d2a5

Browse files
tetoroberth
andcommitted
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 <[email protected]>
1 parent ef8218f commit ac9d2a5

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/nix/flake.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,8 +1303,10 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
13031303
try {
13041304
if (visitor.isDerivation())
13051305
showDerivation();
1306-
else
1307-
throw Error("expected a derivation");
1306+
else {
1307+
auto name = visitor.getAttrPathStr(state->s.name);
1308+
logger->warn(fmt("%s is not a derivation", name));
1309+
}
13081310
} catch (IFDError & e) {
13091311
if (!json) {
13101312
logger->cout(

tests/functional/flakes/show.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,26 @@ in
107107
assert show_output.packages.${builtins.currentSystem}.default == { };
108108
true
109109
'
110+
111+
112+
# Test that nix keeps going even when packages.$SYSTEM contains not derivations
113+
cat >flake.nix <<EOF
114+
{
115+
outputs = inputs: {
116+
packages.$system = {
117+
drv1 = import ./simple.nix;
118+
not-a-derivation = 42;
119+
drv2 = import ./simple.nix;
120+
};
121+
};
122+
}
123+
EOF
124+
nix flake show --json --all-systems > show-output.json
125+
# shellcheck disable=SC2016
126+
nix eval --impure --expr '
127+
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
128+
in
129+
assert show_output.packages.${builtins.currentSystem}.not-a-derivation == {};
130+
true
131+
'
132+

0 commit comments

Comments
 (0)