1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

add layers to catching IFDs in nix flake show

This commit is contained in:
Uluc Sengil 2025-06-10 14:14:43 +02:00
parent 68839b9545
commit 68987761ef
No known key found for this signature in database

View file

@ -1153,22 +1153,31 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
if ((attrPathS[0] == "apps" || attrPathS[0] == "checks" || attrPathS[0] == "devShells" if ((attrPathS[0] == "apps" || attrPathS[0] == "checks" || attrPathS[0] == "devShells"
|| attrPathS[0] == "legacyPackages" || attrPathS[0] == "packages") || attrPathS[0] == "legacyPackages" || attrPathS[0] == "packages")
&& (attrPathS.size() == 1 || attrPathS.size() == 2)) { && (attrPathS.size() == 1 || attrPathS.size() == 2)) {
try {
for (const auto & subAttr : visitor2->getAttrs()) { for (const auto & subAttr : visitor2->getAttrs()) {
if (hasContent(*visitor2, attrPath2, subAttr)) { if (hasContent(*visitor2, attrPath2, subAttr)) {
return true; return true;
} }
} }
} catch (IFDError & e) {
// allow IFD errors here; as we handle them during `visit()`
return true;
}
return false; return false;
} }
if ((attrPathS.size() == 1) if ((attrPathS.size() == 1)
&& (attrPathS[0] == "formatter" || attrPathS[0] == "nixosConfigurations" && (attrPathS[0] == "formatter" || attrPathS[0] == "nixosConfigurations"
|| attrPathS[0] == "nixosModules" || attrPathS[0] == "overlays")) { || attrPathS[0] == "nixosModules" || attrPathS[0] == "overlays")) {
try {
for (const auto & subAttr : visitor2->getAttrs()) { for (const auto & subAttr : visitor2->getAttrs()) {
if (hasContent(*visitor2, attrPath2, subAttr)) { if (hasContent(*visitor2, attrPath2, subAttr)) {
return true; return true;
} }
} }
} catch (IFDError & e) {
return true;
}
return false; return false;
} }
@ -1204,10 +1213,23 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
if (!json) if (!json)
logger->cout("%s", headerPrefix); logger->cout("%s", headerPrefix);
std::vector<Symbol> attrs; std::vector<Symbol> attrs;
try {
for (const auto & attr : visitor.getAttrs()) { for (const auto & attr : visitor.getAttrs()) {
if (hasContent(visitor, attrPath, attr)) if (hasContent(visitor, attrPath, attr))
attrs.push_back(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)) { for (const auto & [i, attr] : enumerate(attrs)) {
const auto & attrName = state->symbols[attr]; const auto & attrName = state->symbols[attr];