1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-19 00:39:37 +01:00

Merge pull request #8871 from teto/flake_show_attr

nix flake show: name attribute that must be a derivation
This commit is contained in:
Sergei Zimmerman 2025-11-16 19:48:15 +00:00 committed by GitHub
commit 5462c5eedd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View file

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

View file

@ -107,3 +107,26 @@ in
assert show_output.packages.${builtins.currentSystem}.default == { };
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
'