libstore: only check cgroup support when actually building

not all operations that involve workers need to build. for example nix
copy --from calls instantiate thir worker with the *origin* store, not
the store they copy *into*. for binary cache stores this is not likely
to ever work if cgroups are enabled and the copy is run on normal user
credentials, even though no cgroups will ever be needed to copy things

fixes #1088

Change-Id: I065e29e1a1d0f58d81823609ef0701ff82cdd1d5
This commit is contained in:
eldritch horrors
2026-02-19 22:26:59 +01:00
parent 4fcb434998
commit c040a9d8e4
3 changed files with 24 additions and 1 deletions
@@ -225,6 +225,10 @@ retry:
assert(derivationType);
// check that all prerequisites for building locally are met (e.g. builds on linux
// when cgroups are configured requires the system to be set up in a certain way).
worker.requireBuildSupport();
/* Are we doing a chroot build? */
{
auto noChroot = parsedDrv->getBoolAttr("__noChroot");
+14 -1
View File
@@ -40,6 +40,18 @@ Worker::Worker(Store & store, Store & evalStore, AvailableNamespaces namespaces)
, namespaces(namespaces)
{
/* Debugging: prevent recursive workers. */
}
void Worker::requireBuildSupport()
{
if (buildSupportEnsured) {
return;
}
if (!useBuildUsers()) {
buildSupportEnsured = true;
return;
}
#ifdef __linux__
@@ -130,8 +142,9 @@ Worker::Worker(Store & store, Store & evalStore, AvailableNamespaces namespaces)
}
#undef CGROUPS_DISABLE_MSG
#endif
}
buildSupportEnsured = true;
}
Worker::~Worker()
{
+6
View File
@@ -120,6 +120,7 @@ public:
private:
bool running = false;
bool buildSupportEnsured = false;
template<typename G>
struct CachedGoal
@@ -236,6 +237,11 @@ public:
const AvailableNamespaces namespaces;
/**
* Check that the current store can *build*, not only substitute.
*/
void requireBuildSupport();
private:
Worker(Store & store, Store & evalStore, AvailableNamespaces namespaces);
~Worker();