forked from lix-project/lix
Catch eval errors in hasContent
`legacyPackages` of nixpkgs trigger eval errors in `hasContent`, causing the whole `legacyPackages` being skipped. We should treat it as has-content in that case.
This commit is contained in:
parent
e00abd3f56
commit
2941a599fa
|
@ -1026,36 +1026,43 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
||||||
|
|
||||||
auto visitor2 = visitor.getAttr(attrName);
|
auto visitor2 = visitor.getAttr(attrName);
|
||||||
|
|
||||||
if ((attrPathS[0] == "apps"
|
try {
|
||||||
|| attrPathS[0] == "checks"
|
if ((attrPathS[0] == "apps"
|
||||||
|| attrPathS[0] == "devShells"
|
|| attrPathS[0] == "checks"
|
||||||
|| attrPathS[0] == "legacyPackages"
|
|| attrPathS[0] == "devShells"
|
||||||
|| attrPathS[0] == "packages")
|
|| attrPathS[0] == "legacyPackages"
|
||||||
&& (attrPathS.size() == 1 || attrPathS.size() == 2)) {
|
|| attrPathS[0] == "packages")
|
||||||
for (const auto &subAttr : visitor2->getAttrs()) {
|
&& (attrPathS.size() == 1 || attrPathS.size() == 2)) {
|
||||||
if (hasContent(*visitor2, attrPath2, subAttr)) {
|
for (const auto &subAttr : visitor2->getAttrs()) {
|
||||||
return true;
|
if (hasContent(*visitor2, attrPath2, subAttr)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((attrPathS.size() == 1)
|
if ((attrPathS.size() == 1)
|
||||||
&& (attrPathS[0] == "formatter"
|
&& (attrPathS[0] == "formatter"
|
||||||
|| attrPathS[0] == "nixosConfigurations"
|
|| attrPathS[0] == "nixosConfigurations"
|
||||||
|| attrPathS[0] == "nixosModules"
|
|| attrPathS[0] == "nixosModules"
|
||||||
|| attrPathS[0] == "overlays"
|
|| attrPathS[0] == "overlays"
|
||||||
)) {
|
)) {
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we don't recognize it, it's probably content
|
// If we don't recognize it, it's probably content
|
||||||
return true;
|
return true;
|
||||||
|
} catch (EvalError & e) {
|
||||||
|
// Some attrs may contain errors, eg. legacyPackages of
|
||||||
|
// nixpkgs. We still want to recurse into it, instead of
|
||||||
|
// skipping it at all.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::function<nlohmann::json(
|
std::function<nlohmann::json(
|
||||||
|
|
|
@ -64,3 +64,23 @@ in
|
||||||
assert show_output == { };
|
assert show_output == { };
|
||||||
true
|
true
|
||||||
'
|
'
|
||||||
|
|
||||||
|
# Test that legacyPackages with errors are handled correctly.
|
||||||
|
cat >flake.nix <<EOF
|
||||||
|
{
|
||||||
|
outputs = inputs: {
|
||||||
|
legacyPackages.$system = {
|
||||||
|
AAAAAASomeThingsFailToEvaluate = throw "nooo";
|
||||||
|
simple = import ./simple.nix;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
nix flake show --json --legacy --all-systems > show-output.json
|
||||||
|
nix eval --impure --expr '
|
||||||
|
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
|
||||||
|
in
|
||||||
|
assert show_output.legacyPackages.${builtins.currentSystem}.AAAAAASomeThingsFailToEvaluate == { };
|
||||||
|
assert show_output.legacyPackages.${builtins.currentSystem}.simple.name == "simple";
|
||||||
|
true
|
||||||
|
'
|
||||||
|
|
Loading…
Reference in a new issue