Skip to content

Commit b158718

Browse files
Selective eval of meta for provenance
1 parent bccd6a4 commit b158718

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/libexpr/include/nix/expr/eval.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ struct StaticEvalSymbols
228228
line, column, functor, toString, right, wrong, structuredAttrs, json, allowedReferences, allowedRequisites,
229229
disallowedReferences, disallowedRequisites, maxSize, maxClosureSize, builder, args, contentAddressed, impure,
230230
outputHash, outputHashAlgo, outputHashMode, recurseForDerivations, description, self, epsilon, startSet,
231-
operator_, key, path, prefix, outputSpecified, __meta;
231+
operator_, key, path, prefix, outputSpecified, __meta, identifiers, license, licenses;
232232

233233
Expr::AstSymbols exprSymbols;
234234

@@ -282,6 +282,9 @@ struct StaticEvalSymbols
282282
.prefix = alloc.create("prefix"),
283283
.outputSpecified = alloc.create("outputSpecified"),
284284
.__meta = alloc.create("__meta"),
285+
.identifiers = alloc.create("identifier"),
286+
.license = alloc.create("license"),
287+
.licenses = alloc.create("licenses"),
285288
.exprSymbols = {
286289
.sub = alloc.create("__sub"),
287290
.lessThan = alloc.create("__lessThan"),

src/libexpr/primops.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,19 +1576,25 @@ static void derivationStrictInternal(EvalState & state, std::string_view drvName
15761576
break;
15771577
case EvalState::s.__meta.getId():
15781578
if (experimentalFeatureSettings.isEnabled(Xp::Provenance)) {
1579-
auto meta = printValueAsJSON(state, true, *i->value, pos, context);
1579+
state.forceAttrs(*i->value, pos, "");
1580+
auto meta = i->value->attrs();
1581+
auto obj = nlohmann::json();
15801582

1581-
for (auto it = meta.begin(); it != meta.end();) {
1582-
if (it.key() == "identifiers" || it.key() == "license" || it.key() == "licenses") {
1583-
it++;
1583+
for (auto & i : meta->lexicographicOrder(state.symbols)) {
1584+
auto key = state.symbols[i->name];
1585+
switch (i->name.getId()) {
1586+
case EvalState::s.identifiers.getId():
1587+
case EvalState::s.license.getId():
1588+
case EvalState::s.licenses.getId():
1589+
obj.emplace(key, printValueAsJSON(state, true, *i->value, pos, context));
1590+
break;
1591+
default:
15841592
continue;
15851593
}
1586-
1587-
it = meta.erase(it);
15881594
}
15891595

15901596
provenance =
1591-
std::make_shared<const DerivationProvenance>(provenance, make_ref<nlohmann::json>(meta));
1597+
std::make_shared<const DerivationProvenance>(provenance, make_ref<nlohmann::json>(obj));
15921598
}
15931599
break;
15941600
/* The `args' attribute is special: it supplies the

0 commit comments

Comments
 (0)