Skip to content

Commit

Permalink
nix flake check --json: Make AAAAAASomeThingsFailToEvaluate show up
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Jul 1, 2024
1 parent e8318bd commit 28a2641
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/nix/flake-schemas.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ using namespace eval_cache;
std::tuple<ref<eval_cache::EvalCache>, ref<AttrCursor>>
call(EvalState & state, std::shared_ptr<flake::LockedFlake> lockedFlake, std::optional<FlakeRef> defaultSchemasFlake);

std::vector<Symbol> toAttrPath(ref<AttrCursor> cursor);

std::string toAttrPathStr(ref<AttrCursor> cursor);

void forEachOutput(
Expand Down
10 changes: 9 additions & 1 deletion src/nix/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,15 @@ struct CmdFlakeShow : FlakeCommand, MixJSON, flake_schemas::MixFlakeSchemas
forEachChild([&](Symbol attrName, ref<eval_cache::AttrCursor> node, bool isLast)
{
auto j = nlohmann::json::object();
visit(node, j);
try {
visit(node, j);
} catch (EvalError & e) {
// FIXME: make it a flake schema attribute whether to ignore evaluation errors.
if (node->root->state.symbols[flake_schemas::toAttrPath(node)[0]] == "legacyPackages")
j.emplace("failed", true);
else
throw;
}
children.emplace(state->symbols[attrName], std::move(j));
});
obj.emplace("children", std::move(children));
Expand Down
3 changes: 1 addition & 2 deletions tests/functional/flakes/show.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ cat >flake.nix <<EOF
}
EOF
nix flake show --json --legacy --all-systems > show-output.json
jq < show-output.json
nix eval --impure --expr '
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
in
#assert show_output.legacyPackages.output.children.${builtins.currentSystem}.AAAAAASomeThingsFailToEvaluate == { };
assert show_output.legacyPackages.output.children.${builtins.currentSystem}.children.AAAAAASomeThingsFailToEvaluate.failed;
assert show_output.legacyPackages.output.children.${builtins.currentSystem}.children.simple.derivationName == "simple";
true
'

0 comments on commit 28a2641

Please sign in to comment.