NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.95k stars 1.53k forks source link

MacOS installer fails if GNU utilities precede MacOS on `PATH` #11570

Open n8henrie opened 2 months ago

n8henrie commented 2 months ago

Platform

Additional information

Reinstall of an existing multi-user nix installation (to deal with nixbld issues on MacOS 15 Sequoia): https://github.com/NixOS/nix/issues/10892 starting an issue as suggested in that thread.

$ sw_vers 
ProductName:        macOS
ProductVersion:     15.0
BuildVersion:       24A335
$ type -a tar
tar is /etc/profiles/per-user/n8henrie/bin/tar
tar is /run/current-system/sw/bin/tar
tar is /usr/bin/tar

Workaround: PATH=$(getconf PATH) sh <(curl -L https://nixos.org/nix/install)

Output

$ sh <(curl -L https://nixos.org/nix/install)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  4267  100  4267    0     0  10441      0 --:--:-- --:--:-- --:--:--     0
downloading Nix 2.24.7 binary tarball for aarch64-darwin from 'https://releases.nixos.org/nix/nix-2.24.7/nix-2.24.7-aarch64-darwin.tar.xz' to '/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/nix-binary-tarball-unpack.nJf7SW58hu'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 14.6M  100 14.6M    0     0  18.8M      0 --:--:-- --:--:-- --:--:-- 18.8M
tar (child): xz: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
/dev/fd/63: failed to unpack 'https://releases.nixos.org/nix/nix-2.24.7/nix-2.24.7-aarch64-darwin.tar.xz'

Priorities

Add :+1: to issues you find important.

n8henrie commented 2 months ago

Perhaps something like:

require_util tar "unpack the binary tarball"
- if [ "$(uname -s)" != "Darwin" ]; then
+ if [ "$(uname -s)" != "Darwin" ] || [ "$(command -v tar)" != /usr/bin/tar ]; then
    require_util xz "unpack the binary tarball"
fi

(or an explicit if Darwin && command -f tar / else if that's considered more readable.)

abathur commented 2 months ago

Context from other thread: It sounds like there was a previous attempt to address this, but I guess it was only a partial fix:

Perhaps something like: ...

I was imagining we could just use /usr/bin/tar when running on macOS (the other threads linked above discuss some reasons that it may not be ideal to send prospective users on a "just install xz" quest)

n8henrie commented 2 months ago

Alternatively, we could fix this and prevent similar surprises with other tools down the line by cleaning / exporting PATH early in the script (only on Darwin). That would help prevent issues with tools on the PATH from nix, homebrew, macports, etc.