From 73910d39d13e2e06911df41c5e792b16f261c653 Mon Sep 17 00:00:00 2001 From: Uluc Sengil Date: Tue, 10 Jun 2025 14:14:43 +0200 Subject: [PATCH] add layers to catching IFDs in `nix flake show` --- src/nix/flake.cc | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 95cf85663..6d8468461 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -1206,10 +1206,15 @@ struct CmdFlakeShow : FlakeCommand, MixJSON || 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; } @@ -1220,10 +1225,14 @@ struct CmdFlakeShow : FlakeCommand, MixJSON || 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; } @@ -1261,12 +1270,20 @@ struct CmdFlakeShow : FlakeCommand, MixJSON try { auto recurse = [&]() { - 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)) {