Skip to content

Commit 5462c5e

Browse files
authored
Merge pull request #8871 from teto/flake_show_attr
nix flake show: name attribute that must be a derivation
2 parents aec59a9 + 653d701 commit 5462c5e

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
@@ -1324,8 +1324,10 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
13241324
try {
13251325
if (visitor.isDerivation())
13261326
showDerivation();
1327-
else
1328-
throw Error("expected a derivation");
1327+
else {
1328+
auto name = visitor.getAttrPathStr(state->s.name);
1329+
logger->warn(fmt("%s is not a derivation", name));
1330+
}
13291331
} catch (IFDError & e) {
13301332
if (!json) {
13311333
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)