about summary refs log tree commit diff
path: root/nixpkgs/pkgs/stdenv/generic/setup.sh
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/stdenv/generic/setup.sh')
-rw-r--r--nixpkgs/pkgs/stdenv/generic/setup.sh32
1 files changed, 14 insertions, 18 deletions
diff --git a/nixpkgs/pkgs/stdenv/generic/setup.sh b/nixpkgs/pkgs/stdenv/generic/setup.sh
index efb233312b57..9c918b12f96e 100644
--- a/nixpkgs/pkgs/stdenv/generic/setup.sh
+++ b/nixpkgs/pkgs/stdenv/generic/setup.sh
@@ -816,7 +816,7 @@ fi
 # Textual substitution functions.
 
 # only log once, due to max logging limit on hydra
-_substituteStream_has_warned_replace_deprecation=""
+_substituteStream_has_warned_replace_deprecation=false
 
 substituteStream() {
     local var=$1
@@ -824,24 +824,18 @@ substituteStream() {
     shift 2
 
     while (( "$#" )); do
-        local is_required=1
-        local is_quiet=""
+        local replace_mode="$1"
         case "$1" in
-            --replace-quiet)
-                is_quiet=1
-                ;&
             --replace)
                 # deprecated 2023-11-22
                 # this will either get removed, or switch to the behaviour of --replace-fail in the future
-                if [ -z "$_substituteStream_has_warned_replace_deprecation" ]; then
+                if ! "$_substituteStream_has_warned_replace_deprecation"; then
                     echo "substituteStream(): WARNING: '--replace' is deprecated, use --replace-{fail,warn,quiet}. ($description)" >&2
-                    _substituteStream_has_warned_replace_deprecation=1
+                    _substituteStream_has_warned_replace_deprecation=true
                 fi
+                replace_mode='--replace-warn'
                 ;&
-            --replace-warn)
-                is_required=""
-                ;&
-            --replace-fail)
+            --replace-quiet|--replace-warn|--replace-fail)
                 pattern="$2"
                 replacement="$3"
                 shift 3
@@ -850,11 +844,9 @@ substituteStream() {
                 eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}'
                 if [ "$pattern" != "$replacement" ]; then
                     if [ "${!var}" == "$savedvar" ]; then
-                        if [ -z "$is_required" ]; then
-                            if [ -z "$is_quiet" ]; then
-                                printf "substituteStream(): WARNING: pattern %q doesn't match anything in %s\n" "$pattern" "$description" >&2
-                            fi
-                        else
+                        if [ "$replace_mode" == --replace-warn ]; then
+                            printf "substituteStream(): WARNING: pattern %q doesn't match anything in %s\n" "$pattern" "$description" >&2
+                        elif [ "$replace_mode" == --replace-fail ]; then
                             printf "substituteStream(): ERROR: pattern %q doesn't match anything in %s\n" "$pattern" "$description" >&2
                             return 1
                         fi
@@ -1073,7 +1065,11 @@ _defaultUnpack() {
                 # stages. The XZ_OPT env var is only used by the full "XZ utils" implementation, which supports
                 # the --threads (-T) flag. This allows us to enable multithreaded decompression exclusively on
                 # that implementation, without the use of complex bash conditionals and checks.
-                XZ_OPT="--threads=$NIX_BUILD_CORES" xz -d < "$fn" | tar xf - --warning=no-timestamp
+                # Since tar does not control the decompression, we need to
+                # disregard the error code from the xz invocation. Otherwise,
+                # it can happen that tar exits earlier, causing xz to fail
+                # from a SIGPIPE.
+                (XZ_OPT="--threads=$NIX_BUILD_CORES" xz -d < "$fn"; true) | tar xf - --warning=no-timestamp
                 ;;
             *.tar | *.tar.* | *.tgz | *.tbz2 | *.tbz)
                 # GNU tar can automatically select the decompression method