From c59e11dc3e6b57dd11feabd3478e95bd384eebcb Mon Sep 17 00:00:00 2001 From: sterni Date: Sun, 31 Mar 2024 21:03:05 +0200 Subject: fix(nix/buildkite): solve bogus realpath errors if build steps fail - Set pipefail to make sure the correct exit code gets returned. - Don't let xargs(1) call realpath(1) if the build fails (and nothing is printed to stdout). Change-Id: I526a18df877601d884b83862da5f37336cdf52cd Reviewed-on: https://cl.tvl.fyi/c/depot/+/11312 Autosubmit: sterni Tested-by: BuildkiteCI Reviewed-by: flokli --- nix/buildkite/default.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'nix') diff --git a/nix/buildkite/default.nix b/nix/buildkite/default.nix index 6e158ae6c6c0..b7715e902f73 100644 --- a/nix/buildkite/default.nix +++ b/nix/buildkite/default.nix @@ -47,6 +47,9 @@ rec { # Create build command for an attribute path pointing to a derivation. mkBuildCommand = { attrPath, drvPath, outLink ? "result" }: concatStringsSep " " [ + # If the nix build fails, the Nix command's exit status should be used. + "set -o pipefail;" + # First try to realise the drvPath of the target so we don't evaluate twice. # Nix has no concept of depending on a derivation file without depending on # at least one of its `outPath`s, so we need to discard the string context @@ -55,7 +58,7 @@ rec { # To make this more uniform with how nix-build(1) works, we call realpath(1) # on nix-store(1)'s output since it has the habit of printing the path of the # out link, not the store path. - "(nix-store --realise '${drvPath}' --add-root '${outLink}' --indirect | xargs realpath)" + "(nix-store --realise '${drvPath}' --add-root '${outLink}' --indirect | xargs -r realpath)" # Since we don't gcroot the derivation files, they may be deleted by the # garbage collector. In that case we can reevaluate and build the attribute -- cgit 1.4.1