stdenv: fix nix_build_cores guess

- use builtin arithmetic instead of external expr
- simplify logic with bash builtins
This commit is contained in:
happysalada 2021-09-06 12:13:43 +09:00 committed by Raphael Megzari
parent 95a966c5b2
commit 4c92bb8bdf

View File

@ -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