From 0fc68c3c6b0bd204c687ec1063b752765361498d Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Mon, 10 Feb 2025 23:09:38 -0800 Subject: [PATCH] Add rejectSystemFeatures to derivations --- src/libstore/parsed-derivations.cc | 12 ++++++++++++ src/libstore/parsed-derivations.hh | 2 ++ src/libstore/unix/build/local-derivation-goal.cc | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/libstore/parsed-derivations.cc b/src/libstore/parsed-derivations.cc index d8459d4d71c2..35620a26fe09 100644 --- a/src/libstore/parsed-derivations.cc +++ b/src/libstore/parsed-derivations.cc @@ -98,6 +98,15 @@ StringSet ParsedDerivation::getRequiredSystemFeatures() const return res; } +StringSet ParsedDerivation::getRejectSystemFeatures() const +{ + // FIXME: cache this? + StringSet res; + for (auto & i : getStringsAttr("rejectSystemFeatures").value_or(Strings())) + res.insert(i); + return res; +} + bool ParsedDerivation::canBuildLocally(Store & localStore) const { if (drv.platform != settings.thisSystem.get() @@ -112,6 +121,9 @@ bool ParsedDerivation::canBuildLocally(Store & localStore) const for (auto & feature : getRequiredSystemFeatures()) if (!localStore.systemFeatures.get().count(feature)) return false; + for (auto & feature : getRejectSystemFeatures()) + if (localStore.systemFeatures.get().count(feature)) return false; + return true; } diff --git a/src/libstore/parsed-derivations.hh b/src/libstore/parsed-derivations.hh index 71085a604d4d..187a768632a8 100644 --- a/src/libstore/parsed-derivations.hh +++ b/src/libstore/parsed-derivations.hh @@ -33,6 +33,8 @@ public: StringSet getRequiredSystemFeatures() const; + StringSet getRejectSystemFeatures() const; + bool canBuildLocally(Store & localStore) const; bool willBuildLocally(Store & localStore) const; diff --git a/src/libstore/unix/build/local-derivation-goal.cc b/src/libstore/unix/build/local-derivation-goal.cc index 06a2f85be848..dfa6be7175d5 100644 --- a/src/libstore/unix/build/local-derivation-goal.cc +++ b/src/libstore/unix/build/local-derivation-goal.cc @@ -532,9 +532,10 @@ void LocalDerivationGoal::startBuilder() /* Right platform? */ if (!parsedDrv->canBuildLocally(worker.store)) - throw Error("a '%s' with features {%s} is required to build '%s', but I am a '%s' with features {%s}", + throw Error("a '%s' with features {%s} & not {%s} is required to build '%s', but I am a '%s' with features {%s}", drv->platform, concatStringsSep(", ", parsedDrv->getRequiredSystemFeatures()), + concatStringsSep(", ", parsedDrv->getRejectSystemFeatures()), worker.store.printStorePath(drvPath), settings.thisSystem, concatStringsSep(", ", worker.store.systemFeatures));