diff options
author | Isidor Zeuner <nix@quidecco.pl> | 2024-02-06 11:15:03 +0100 |
---|---|---|
committer | Isidor Zeuner <nix@quidecco.pl> | 2024-02-13 17:00:48 +0100 |
commit | 11a19109b687ea8f263870effe0513f2225771b1 (patch) | |
tree | 726b8c88c8a6e2eccd3faf0dce432f218bfb179f | |
parent | bb07433975c9c7617295005136ac0980ad424825 (diff) |
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)
-rw-r--r-- | pkgs/stdenv/generic/setup.sh | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index efb233312b571..80c53e64f1727 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 |