diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 04d4ec8eb..5e3510a38 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -1303,8 +1303,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( diff --git a/tests/functional/flakes/show.sh b/tests/functional/flakes/show.sh index a08db115a..0cdbdb8f2 100755 --- a/tests/functional/flakes/show.sh +++ b/tests/functional/flakes/show.sh @@ -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 < 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 +' +