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

Add lazy evaluation for experimental feature reasons

Wrap fmt() calls in lambdas to defer string formatting until the
feature check fails. This avoids unnecessary string formatting in
the common case where the feature is enabled.

Addresses performance concern raised by xokdvium in PR review.
This commit is contained in:
Robert Hensing 2025-10-14 16:49:59 +02:00
parent 39c4665488
commit 1b96a704d3
4 changed files with 23 additions and 6 deletions

View file

@ -426,7 +426,9 @@ Derivation parseDerivation(
if (*versionS == "xp-dyn-drv"sv) {
// Only version we have so far
version = DerivationATermVersion::DynamicDerivations;
xpSettings.require(Xp::DynamicDerivations, fmt("derivation '%s', ATerm format version 'xp-dyn-drv'", name));
xpSettings.require(Xp::DynamicDerivations, [&] {
return fmt("derivation '%s', ATerm format version 'xp-dyn-drv'", name);
});
} else {
throw FormatError("Unknown derivation ATerm format version '%s'", *versionS);
}
@ -1454,7 +1456,8 @@ Derivation Derivation::fromJSON(const nlohmann::json & _json, const Experimental
node.value = getStringSet(valueAt(json, "outputs"));
auto drvs = getObject(valueAt(json, "dynamicOutputs"));
for (auto & [outputId, childNode] : drvs) {
xpSettings.require(Xp::DynamicDerivations, fmt("dynamic output '%s' in JSON", outputId));
xpSettings.require(
Xp::DynamicDerivations, [&] { return fmt("dynamic output '%s' in JSON", outputId); });
node.childMap[outputId] = doInput(childNode);
}
return node;