From 4c92bb8bdf2a95c5c9028785cf9d4964fd5a13fd Mon Sep 17 00:00:00 2001 From: happysalada Date: Mon, 6 Sep 2021 12:13:43 +0900 Subject: [PATCH] stdenv: fix nix_build_cores guess - use builtin arithmetic instead of external expr - simplify logic with bash builtins --- pkgs/stdenv/generic/setup.sh | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) 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