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)
This commit is contained in:
Isidor Zeuner 2024-02-06 11:15:03 +01:00
parent bb07433975
commit 11a19109b6

View File

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