diff --git a/src/libstore/build/derivation-building-goal.cc b/src/libstore/build/derivation-building-goal.cc index f79a52400ce..b161bfb9900 100644 --- a/src/libstore/build/derivation-building-goal.cc +++ b/src/libstore/build/derivation-building-goal.cc @@ -396,13 +396,22 @@ Goal::Co DerivationBuildingGoal::tryToBuild(StorePathSet inputPaths) if (useHook) { co_return buildWithHook( std::move(inputPaths), std::move(initialOutputs), std::move(drvOptions), std::move(outputLocks)); - } else { + } else if (auto * localStoreP = dynamic_cast(&worker.store)) { co_return buildLocally( + *localStoreP, std::move(inputPaths), std::move(initialOutputs), std::move(drvOptions), std::move(outputLocks), externalBuilder); + } else { + throw Error( + R"( + Unable to build with a primary store that isn't a local store; + either pass a different '--store' or enable remote builds. + + For more information check 'man nix.conf' and search for '/machines'. + )"); } } @@ -611,6 +620,7 @@ Goal::Co DerivationBuildingGoal::buildWithHook( } Goal::Co DerivationBuildingGoal::buildLocally( + LocalStore & localStore, StorePathSet inputPaths, std::map initialOutputs, DerivationOptions drvOptions, @@ -619,16 +629,6 @@ Goal::Co DerivationBuildingGoal::buildLocally( { co_await yield(); - if (!dynamic_cast(&worker.store)) { - throw Error( - R"( - Unable to build with a primary store that isn't a local store; - either pass a different '--store' or enable remote builds. - - For more information check 'man nix.conf' and search for '/machines'. - )"); - } - #ifdef _WIN32 // TODO enable `DerivationBuilder` on Windows throw UnimplementedError("building derivations is not yet implemented on Windows"); #else @@ -708,9 +708,6 @@ Goal::Co DerivationBuildingGoal::buildLocally( } }; - auto * localStoreP = dynamic_cast(&worker.store); - assert(localStoreP); - decltype(DerivationBuilderParams::defaultPathsInChroot) defaultPathsInChroot = settings.sandboxPaths.get(); DesugaredEnv desugaredEnv; @@ -756,12 +753,12 @@ Goal::Co DerivationBuildingGoal::buildLocally( already be created, so we don't need to create it again. */ builder = externalBuilder ? makeExternalDerivationBuilder( - *localStoreP, + localStore, std::make_unique(*this, openLogFile, closeLogFile), std::move(params), *externalBuilder) : makeDerivationBuilder( - *localStoreP, + localStore, std::make_unique(*this, openLogFile, closeLogFile), std::move(params)); } diff --git a/src/libstore/include/nix/store/build/derivation-building-goal.hh b/src/libstore/include/nix/store/build/derivation-building-goal.hh index d8fb967aedf..ea874e83fac 100644 --- a/src/libstore/include/nix/store/build/derivation-building-goal.hh +++ b/src/libstore/include/nix/store/build/derivation-building-goal.hh @@ -2,10 +2,10 @@ ///@file #include "nix/store/derivations.hh" +#include "nix/store/local-store.hh" #include "nix/store/parsed-derivations.hh" #include "nix/store/derivation-options.hh" #include "nix/store/build/derivation-building-misc.hh" -#include "nix/store/outputs-spec.hh" #include "nix/store/store-api.hh" #include "nix/store/pathlocks.hh" #include "nix/store/build/goal.hh" @@ -75,6 +75,7 @@ private: DerivationOptions drvOptions, PathLocks outputLocks); Co buildLocally( + LocalStore & localStore, StorePathSet inputPaths, std::map initialOutputs, DerivationOptions drvOptions,