diff --git a/src/libstore-tests/derivation-advanced-attrs.cc b/src/libstore-tests/derivation-advanced-attrs.cc index 588ee952160..16988613c63 100644 --- a/src/libstore-tests/derivation-advanced-attrs.cc +++ b/src/libstore-tests/derivation-advanced-attrs.cc @@ -193,8 +193,6 @@ TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_defaults) EXPECT_EQ(options, advancedAttributes_defaults); - EXPECT_EQ(options.canBuildLocally(*this->store, got), false); - EXPECT_EQ(options.willBuildLocally(*this->store, got), false); EXPECT_EQ(options.substitutesAllowed(settings.getWorkerSettings()), true); EXPECT_EQ(options.useUidRange(got), false); }); @@ -335,8 +333,6 @@ TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_structuredAttrs_d EXPECT_EQ(options, advancedAttributes_structuredAttrs_defaults); - EXPECT_EQ(options.canBuildLocally(*this->store, got), false); - EXPECT_EQ(options.willBuildLocally(*this->store, got), false); EXPECT_EQ(options.substitutesAllowed(settings.getWorkerSettings()), true); EXPECT_EQ(options.useUidRange(got), false); }); @@ -402,8 +398,6 @@ TYPED_TEST(DerivationAdvancedAttrsBothTest, advancedAttributes_structuredAttrs) EXPECT_EQ(options, expected); - EXPECT_EQ(options.canBuildLocally(*this->store, got), false); - EXPECT_EQ(options.willBuildLocally(*this->store, got), false); EXPECT_EQ(options.substitutesAllowed(settings.getWorkerSettings()), false); EXPECT_EQ(options.useUidRange(got), true); }); diff --git a/src/libstore/build/derivation-building-goal.cc b/src/libstore/build/derivation-building-goal.cc index 1ce01fb81c2..e3295d673c2 100644 --- a/src/libstore/build/derivation-building-goal.cc +++ b/src/libstore/build/derivation-building-goal.cc @@ -325,10 +325,25 @@ Goal::Co DerivationBuildingGoal::tryToBuild(StorePathSet inputPaths) } } + bool canBuildLocally = [&] { + if (drv->platform != settings.thisSystem.get() && !settings.extraPlatforms.get().count(drv->platform) + && !drv->isBuiltin()) + return false; + + if (worker.settings.maxBuildJobs.get() == 0 && !drv->isBuiltin()) + return false; + + for (auto & feature : drvOptions.getRequiredSystemFeatures(*drv)) + if (!worker.store.config.systemFeatures.get().count(feature)) + return false; + + return true; + }(); + /* Don't do a remote build if the derivation has the attribute `preferLocalBuild' set. Also, check and repair modes are only supported for local builds. */ - bool buildLocally = (buildMode != bmNormal || drvOptions.willBuildLocally(worker.store, *drv)) + bool buildLocally = (buildMode != bmNormal || (drvOptions.preferLocalBuild && canBuildLocally)) && worker.settings.maxBuildJobs.get() != 0; if (buildLocally) { @@ -363,7 +378,7 @@ Goal::Co DerivationBuildingGoal::tryToBuild(StorePathSet inputPaths) externalBuilder = settings.findExternalDerivationBuilderIfSupported(*drv); - if (!externalBuilder && !drvOptions.canBuildLocally(worker.store, *drv)) { + if (!externalBuilder && !canBuildLocally) { auto msg = fmt("Cannot build '%s'.\n" "Reason: " ANSI_RED "required system or feature not available" ANSI_NORMAL diff --git a/src/libstore/derivation-options.cc b/src/libstore/derivation-options.cc index e352e5a47a6..ff00065209f 100644 --- a/src/libstore/derivation-options.cc +++ b/src/libstore/derivation-options.cc @@ -6,7 +6,6 @@ #include "nix/store/store-api.hh" #include "nix/util/types.hh" #include "nix/util/util.hh" -#include "nix/store/globals.hh" #include "nix/util/variant-wrapper.hh" #include @@ -359,29 +358,6 @@ StringSet DerivationOptions::getRequiredSystemFeatures(const BasicDerivat return res; } -template -bool DerivationOptions::canBuildLocally(Store & localStore, const BasicDerivation & drv) const -{ - if (drv.platform != settings.thisSystem.get() && !settings.extraPlatforms.get().count(drv.platform) - && !drv.isBuiltin()) - return false; - - if (settings.getWorkerSettings().maxBuildJobs.get() == 0 && !drv.isBuiltin()) - return false; - - for (auto & feature : getRequiredSystemFeatures(drv)) - if (!localStore.config.systemFeatures.get().count(feature)) - return false; - - return true; -} - -template -bool DerivationOptions::willBuildLocally(Store & localStore, const BasicDerivation & drv) const -{ - return preferLocalBuild && canBuildLocally(localStore, drv); -} - template bool DerivationOptions::substitutesAllowed(const WorkerSettings & workerSettings) const { diff --git a/src/libstore/include/nix/store/derivation-options.hh b/src/libstore/include/nix/store/derivation-options.hh index 4d17f190f91..687c5c3904c 100644 --- a/src/libstore/include/nix/store/derivation-options.hh +++ b/src/libstore/include/nix/store/derivation-options.hh @@ -14,7 +14,6 @@ namespace nix { -class Store; struct StoreDirConfig; struct BasicDerivation; struct StructuredAttrs; @@ -184,16 +183,6 @@ struct DerivationOptions */ StringSet getRequiredSystemFeatures(const BasicDerivation & drv) const; - /** - * @param drv See note on `getRequiredSystemFeatures` - */ - bool canBuildLocally(Store & localStore, const BasicDerivation & drv) const; - - /** - * @param drv See note on `getRequiredSystemFeatures` - */ - bool willBuildLocally(Store & localStore, const BasicDerivation & drv) const; - bool substitutesAllowed(const WorkerSettings & workerSettings) const; /**