diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 29c44e9d711e..2d2a085ef933 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -658,15 +658,10 @@ export NIX_INDENT_MAKE=1 # means that we're supposed to try and auto-detect the number of # available CPU cores at run-time. -if [ -z "${NIX_BUILD_CORES:-}" ]; then - NIX_BUILD_CORES="1" -elif (( NIX_BUILD_CORES <= 0 )); then - NIX_BUILD_CORES=$(nproc 2>/dev/null || true) - if expr >/dev/null 2>&1 "$NIX_BUILD_CORES" : "^[0-9][0-9]*$"; then - : - else - NIX_BUILD_CORES="1" - fi +NIX_BUILD_CORES="${NIX_BUILD_CORES:-1}" +if ((NIX_BUILD_CORES <= 0)); then + guess=$(nproc 2>/dev/null || true) + ((NIX_BUILD_CORES = guess <= 0 ? 1 : guess)) fi export NIX_BUILD_CORES