From 11a19109b687ea8f263870effe0513f2225771b1 Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Tue, 6 Feb 2024 11:15:03 +0100 Subject: [PATCH] stdenv: disregard xz exit status in order to fix subtle decompression issues There is a subtle bug with unpacking `tar.xz` archives which seems to happen only on some setups, and sometimes not in a reproducible manner (https://github.com/NixOS/nixpkgs/issues/278130, https://github.com/NixOS/nixpkgs/issues/20950). On the last occurrence, it could be tracked down to `xz` failing from a `SIGPIPE`, which can happen when it's connected to `tar` through a pipe and `tar` exits earlier (see e.g. https://www.linuxquestions.org/questions/slackware-14/%5Bpatch%5D-tar-issuing-a-sigpipe-in-installpkg-4175637923/ or https://bugs.gentoo.org/573642#c5). Since `tar` should be able by itself to detect whether the archive is complete, I suggest to disregard the exit code from the `xz` invocation, done in this PR. Fixes https://github.com/NixOS/nixpkgs/issues/278130 (script tested here: https://github.com/NixOS/nixpkgs/pull/286579) Probably also fixes https://github.com/NixOS/nixpkgs/issues/20950 (issue not reproduced here, feedback therefore welcome) --- pkgs/stdenv/generic/setup.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index efb233312b57..80c53e64f172 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1073,7 +1073,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