From c040a9d8e47f254f988a74616bca48b335704f12 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Thu, 19 Feb 2026 22:26:59 +0100 Subject: [PATCH] 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 --- lix/libstore/build/local-derivation-goal.cc | 4 ++++ lix/libstore/build/worker.cc | 15 ++++++++++++++- lix/libstore/build/worker.hh | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index 38b287c19..a7414fb1e 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -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"); diff --git a/lix/libstore/build/worker.cc b/lix/libstore/build/worker.cc index 672985c65..138bfd6e9 100644 --- a/lix/libstore/build/worker.cc +++ b/lix/libstore/build/worker.cc @@ -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() { diff --git a/lix/libstore/build/worker.hh b/lix/libstore/build/worker.hh index cd3b27f61..2d1a214a8 100644 --- a/lix/libstore/build/worker.hh +++ b/lix/libstore/build/worker.hh @@ -120,6 +120,7 @@ public: private: bool running = false; + bool buildSupportEnsured = false; template 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();