libstore: diagnose local build failure in goal

this should be done where we're actually trying to build something, not
in the main worker loop that shouldn't have to be aware of such details

Change-Id: I07276740c0e2e5591a8ce4828a4bfc705396527e
This commit is contained in:
eldritch horrors 2024-08-25 13:41:56 +02:00
parent 04b591dc1d
commit cae260a158
4 changed files with 39 additions and 14 deletions

View file

@ -1,6 +1,7 @@
#include "local-derivation-goal.hh"
#include "indirect-root-store.hh"
#include "hook-instance.hh"
#include "machines.hh"
#include "store-api.hh"
#include "worker.hh"
#include "builtins.hh"
@ -159,8 +160,22 @@ Goal::WorkResult LocalDerivationGoal::tryLocalBuild(bool inBuildSlot)
if (!inBuildSlot) {
state = &DerivationGoal::tryToBuild;
outputLocks.unlock();
if (0U != settings.maxBuildJobs) {
return WaitForSlot{};
}
if (getMachines().empty()) {
throw Error(
"unable to start any build; either set '--max-jobs' to a non-zero value or enable "
"remote builds.\n"
"https://docs.lix.systems/manual/lix/stable/advanced-topics/distributed-builds.html"
);
} else {
throw Error(
"unable to start any build; remote machines may not have all required system features.\n"
"https://docs.lix.systems/manual/lix/stable/advanced-topics/distributed-builds.html"
);
}
}
assert(derivationType);

View file

@ -1,5 +1,4 @@
#include "charptr-cast.hh"
#include "machines.hh"
#include "worker.hh"
#include "substitution-goal.hh"
#include "drv-output-substitution-goal.hh"
@ -381,18 +380,6 @@ void Worker::run(const Goals & _topGoals)
if (!children.empty() || !waitingForAWhile.empty())
waitForInput();
else {
if (awake.empty() && 0U == settings.maxBuildJobs)
{
if (getMachines().empty())
throw Error("unable to start any build; either increase '--max-jobs' "
"or enable remote builds."
"\nhttps://docs.lix.systems/manual/lix/stable/advanced-topics/distributed-builds.html");
else
throw Error("unable to start any build; remote machines may not have "
"all required system features."
"\nhttps://docs.lix.systems/manual/lix/stable/advanced-topics/distributed-builds.html");
}
assert(!awake.empty());
}
}

View file

@ -0,0 +1,22 @@
source common.sh
drv='
builtins.derivation {
name = "foo";
builder = /bin/sh;
system = builtins.currentSystem;
requiredSystemFeatures = [ "glitter" ];
}
'
# -j0 without remote machines diagnoses build start failure
! out="$(nix-build 2>&1 -j0 --expr "$drv" \
--builders '' \
--system-features 'glitter')"
<<<"$out" grepQuiet 'error: unable to start any build; either set '\''--max-jobs'\'' to a non-zero value or enable remote builds.'
# -j0 with remote machines and missing features also diagnoses
! out="$(nix-build 2>&1 -j0 --expr "$drv" \
--builders "ssh://localhost?remote-store=$TEST_ROOT/machine1" \
--system-features 'glitter')"
<<<"$out" grepQuiet 'error: unable to start any build; remote machines may not have all required system features.'

View file

@ -130,6 +130,7 @@ functional_tests_scripts = [
'build-remote-trustless-should-pass-2.sh',
'build-remote-trustless-should-pass-3.sh',
'build-remote-trustless-should-fail-0.sh',
'build-jobless.sh',
'nar-access.sh',
'impure-eval.sh',
'pure-eval.sh',