From 644415d3912633773d2c8f219572fbfa452f4b56 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Thu, 24 Jun 2021 15:06:07 +0200 Subject: [PATCH] Perform input rewrites only in LocalDerivationGoal --- src/libstore/build/local-derivation-goal.cc | 11 ++++++++++- src/libstore/parsed-derivations.cc | 11 ++--------- src/libstore/parsed-derivations.hh | 2 +- src/nix-build/nix-build.cc | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc index 15a7cb4ac..259134eba 100644 --- a/src/libstore/build/local-derivation-goal.cc +++ b/src/libstore/build/local-derivation-goal.cc @@ -1086,8 +1086,17 @@ void LocalDerivationGoal::initEnv() void LocalDerivationGoal::writeStructuredAttrs() { - if (auto structAttrsJson = parsedDrv->prepareStructuredAttrs(inputRewrites, worker.store, inputPaths)) { + if (auto structAttrsJson = parsedDrv->prepareStructuredAttrs(worker.store, inputPaths)) { auto json = structAttrsJson.value(); + nlohmann::json rewritten; + for (auto & [i, v] : json["outputs"].get()) { + /* The placeholder must have a rewrite, so we use it to cover both the + cases where we know or don't know the output path ahead of time. */ + rewritten[i] = rewriteStrings(v, inputRewrites); + } + + json["outputs"] = rewritten; + auto jsonSh = writeStructuredAttrsShell(json); writeFile(tmpDir + "/.attrs.sh", rewriteStrings(jsonSh, inputRewrites)); diff --git a/src/libstore/parsed-derivations.cc b/src/libstore/parsed-derivations.cc index f021e4de3..ee6bbb045 100644 --- a/src/libstore/parsed-derivations.cc +++ b/src/libstore/parsed-derivations.cc @@ -124,7 +124,7 @@ bool ParsedDerivation::substitutesAllowed() const } static std::regex shVarName("[A-Za-z_][A-Za-z0-9_]*"); -std::optional ParsedDerivation::prepareStructuredAttrs(std::optional inputRewrites, Store & store, const StorePathSet & inputPaths) +std::optional ParsedDerivation::prepareStructuredAttrs(Store & store, const StorePathSet & inputPaths) { auto structuredAttrs = getStructuredAttrs(); if (!structuredAttrs) return std::nullopt; @@ -134,14 +134,7 @@ std::optional ParsedDerivation::prepareStructuredAttrs(std::opti /* Add an "outputs" object containing the output paths. */ nlohmann::json outputs; for (auto & i : drv.outputs) { - if (inputRewrites) { - /* The placeholder must have a rewrite, so we use it to cover both the - cases where we know or don't know the output path ahead of time. */ - outputs[i.first] = rewriteStrings(hashPlaceholder(i.first), inputRewrites.value()); - } else { - /* This case is only relevant for the nix-shell */ - outputs[i.first] = hashPlaceholder(i.first); - } + outputs[i.first] = hashPlaceholder(i.first); } json["outputs"] = outputs; diff --git a/src/libstore/parsed-derivations.hh b/src/libstore/parsed-derivations.hh index 8061e3a8b..5e3fb93ca 100644 --- a/src/libstore/parsed-derivations.hh +++ b/src/libstore/parsed-derivations.hh @@ -37,7 +37,7 @@ public: bool substitutesAllowed() const; - std::optional prepareStructuredAttrs(std::optional inputRewrites, Store & store, const StorePathSet & inputPaths); + std::optional prepareStructuredAttrs(Store & store, const StorePathSet & inputPaths); }; std::string writeStructuredAttrsShell(nlohmann::json & json); diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index 459876465..519cbd5bb 100755 --- a/src/nix-build/nix-build.cc +++ b/src/nix-build/nix-build.cc @@ -444,7 +444,7 @@ static void main_nix_build(int argc, char * * argv) drv ); - if (auto structAttrs = parsedDrv.prepareStructuredAttrs(std::nullopt, *store, inputs)) { + if (auto structAttrs = parsedDrv.prepareStructuredAttrs(*store, inputs)) { auto json = structAttrs.value(); structuredAttrsRC = writeStructuredAttrsShell(json);