From 0712339912a4b139efa87768fd3a38713e0e13ac Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 2 Jun 2025 14:28:43 -0700 Subject: [PATCH 1/2] `--keep-failed` with remote builders will keep the failed build directory on that builder --- src/build-remote/build-remote.cc | 9 ++++++++- tests/functional/build-remote.sh | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc index 60247b735..e79ee6a45 100644 --- a/src/build-remote/build-remote.cc +++ b/src/build-remote/build-remote.cc @@ -329,8 +329,15 @@ connected: drv.inputSrcs = store->parseStorePathSet(inputs); optResult = sshStore->buildDerivation(*drvPath, (const BasicDerivation &) drv); auto & result = *optResult; - if (!result.success()) + if (!result.success()) { + if (settings.keepFailed) { + warn( + "The failed build directory was kept on the remote builder due to `--keep-failed`. " + "If the build's architecture matches your host, you can re-run the command with `--builders ''` to disable remote building for this invocation." + ); + } throw Error("build of '%s' on '%s' failed: %s", store->printStorePath(*drvPath), storeUri, result.errorMsg); + } } else { copyClosure(*store, *sshStore, StorePathSet {*drvPath}, NoRepair, NoCheckSigs, substitute); auto res = sshStore->buildPathsWithResults({ diff --git a/tests/functional/build-remote.sh b/tests/functional/build-remote.sh index 3231341cb..2d3e874b1 100644 --- a/tests/functional/build-remote.sh +++ b/tests/functional/build-remote.sh @@ -85,6 +85,7 @@ out="$(nix-build 2>&1 failing.nix \ --arg busybox "$busybox")" || true [[ "$out" =~ .*"note: keeping build directory".* ]] +[[ "$out" =~ .*"The failed build directory was kept on the remote builder due to".* ]] build_dir="$(grep "note: keeping build" <<< "$out" | sed -E "s/^(.*)note: keeping build directory '(.*)'(.*)$/\2/")" [[ "foo" = $(<"$build_dir"/bar) ]] From 54aa73b19bd3bb3f86c1cfae7eaca669923c9313 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 3 Jun 2025 08:38:04 -0700 Subject: [PATCH 2/2] fixup: only show "you can rerun" message if the derivation's platform is supported on this machine --- src/build-remote/build-remote.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc index e79ee6a45..e0a6b2d8e 100644 --- a/src/build-remote/build-remote.cc +++ b/src/build-remote/build-remote.cc @@ -332,8 +332,10 @@ connected: if (!result.success()) { if (settings.keepFailed) { warn( - "The failed build directory was kept on the remote builder due to `--keep-failed`. " - "If the build's architecture matches your host, you can re-run the command with `--builders ''` to disable remote building for this invocation." + "The failed build directory was kept on the remote builder due to `--keep-failed`.%s", + (settings.thisSystem == drv.platform || settings.extraPlatforms.get().count(drv.platform) > 0) + ? " You can re-run the command with `--builders ''` to disable remote building for this invocation." + : "" ); } throw Error("build of '%s' on '%s' failed: %s", store->printStorePath(*drvPath), storeUri, result.errorMsg);