From 4a2de1dbabd28b432b46e4b448e2ca2f46daefeb Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 14 Aug 2025 00:39:00 -0400 Subject: [PATCH] `DerivationGoal` Make some fields immutable We can set both during construction, yay! --- src/libstore/build/derivation-goal.cc | 12 +++++++----- .../include/nix/store/build/derivation-goal.hh | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index 13ea6019e..30a247777 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -33,7 +33,13 @@ DerivationGoal::DerivationGoal( : Goal(worker, haveDerivation()) , drvPath(drvPath) , wantedOutput(wantedOutput) - , outputHash{Hash::dummy} // will be updated + , outputHash{[&] { + if (auto * mOutputHash = get(staticOutputHashes(worker.evalStore, drv), wantedOutput)) + return *mOutputHash; + else + throw Error( + "derivation '%s' does not have output '%s'", worker.store.printStorePath(drvPath), wantedOutput); + }()} , buildMode(buildMode) { this->drv = std::make_unique(drv); @@ -79,10 +85,6 @@ Goal::Co DerivationGoal::haveDerivation() if (i.second.second) worker.store.addTempRoot(*i.second.second); - if (auto * mOutputHash = get(staticOutputHashes(worker.evalStore, *drv), wantedOutput)) { - outputHash = *mOutputHash; - } - /* We don't yet have any safe way to cache an impure derivation at this step. */ if (drv->type().isImpure()) { diff --git a/src/libstore/include/nix/store/build/derivation-goal.hh b/src/libstore/include/nix/store/build/derivation-goal.hh index 8417ea64f..589c3fd58 100644 --- a/src/libstore/include/nix/store/build/derivation-goal.hh +++ b/src/libstore/include/nix/store/build/derivation-goal.hh @@ -70,14 +70,14 @@ private: */ std::unique_ptr drv; + const Hash outputHash; + + const BuildMode buildMode; + /** * The remainder is state held during the build. */ - Hash outputHash; - - BuildMode buildMode; - std::unique_ptr> mcExpectedBuilds; /**