diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 244fdbc47..0329a256c 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -1165,10 +1165,15 @@ struct CmdFlakeShow : FlakeCommand, MixJSON if ((attrPathS[0] == "apps" || attrPathS[0] == "checks" || attrPathS[0] == "devShells" || attrPathS[0] == "legacyPackages" || attrPathS[0] == "packages") && (attrPathS.size() == 1 || attrPathS.size() == 2)) { - for (const auto & subAttr : visitor2->getAttrs()) { - if (hasContent(*visitor2, attrPath2, subAttr)) { - return true; + try { + for (const auto & subAttr : visitor2->getAttrs()) { + if (hasContent(*visitor2, attrPath2, subAttr)) { + return true; + } } + } catch (IFDError & e) { + // allow IFD errors here; as we handle them during `visit()` + return true; } return false; } @@ -1176,10 +1181,14 @@ struct CmdFlakeShow : FlakeCommand, MixJSON if ((attrPathS.size() == 1) && (attrPathS[0] == "formatter" || attrPathS[0] == "nixosConfigurations" || attrPathS[0] == "nixosModules" || attrPathS[0] == "overlays")) { - for (const auto & subAttr : visitor2->getAttrs()) { - if (hasContent(*visitor2, attrPath2, subAttr)) { - return true; + try { + for (const auto & subAttr : visitor2->getAttrs()) { + if (hasContent(*visitor2, attrPath2, subAttr)) { + return true; + } } + } catch (IFDError & e) { + return true; } return false; } @@ -1216,9 +1225,22 @@ struct CmdFlakeShow : FlakeCommand, MixJSON if (!json) logger->cout("%s", headerPrefix); std::vector attrs; - for (const auto & attr : visitor.getAttrs()) { - if (hasContent(visitor, attrPath, attr)) - attrs.push_back(attr); + try { + for (const auto & attr : visitor.getAttrs()) { + if (hasContent(visitor, attrPath, attr)) + attrs.push_back(attr); + } + if (!json) + logger->cout("%s", headerPrefix); + } catch (IFDError & e) { + if (!json) { + logger->cout( + fmt("%s " ANSI_WARNING "omitted due to use of import from derivation" ANSI_NORMAL, + headerPrefix)); + } else { + logger->warn(fmt( + "%s omitted due to use of import from derivation", concatStringsSep(".", attrPathS))); + } } for (const auto & [i, attr] : enumerate(attrs)) { diff --git a/tests/functional/flakes/common.sh b/tests/functional/flakes/common.sh index 77bc03060..7d3cf4535 100644 --- a/tests/functional/flakes/common.sh +++ b/tests/functional/flakes/common.sh @@ -96,6 +96,8 @@ writeIfdFlake() { { outputs = { self }: { packages.$system.default = import ./ifd.nix; + checks.$system = import ./ifd.nix; + formatter = import ./ifd.nix; }; } EOF diff --git a/tests/functional/flakes/show.sh b/tests/functional/flakes/show.sh index a08db115a..eb44614fd 100755 --- a/tests/functional/flakes/show.sh +++ b/tests/functional/flakes/show.sh @@ -105,5 +105,7 @@ nix eval --impure --expr ' let show_output = builtins.fromJSON (builtins.readFile ./show-output.json); in assert show_output.packages.${builtins.currentSystem}.default == { }; +assert show_output.checks.${builtins.currentSystem} == { }; +assert show_output.formatter == { }; true '