DeterminateSystems / nix-installer

Install Nix and flakes with the fast and reliable Determinate Nix Installer, with over 7 million installs.
https://determinate.systems
GNU Lesser General Public License v2.1
2.19k stars 57 forks source link

bug(macos) `nix profile install 'nixpkgs#hello'` fails with a permissions issue #1246

Open mkatychev opened 1 week ago

mkatychev commented 1 week ago

Problem

After resolving the uninstall issues (https://github.com/DeterminateSystems/nix-installer/issues/1234#issuecomment-2433522881), I have proceeded to do a fresh reinstall using the latest curl approach:

$ curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

Attempting to install hello results in a permissions error:

$ nix profile install 'nixpkgs#hello'
error: filesystem error: in create_symlink: Permission denied ["/nix/store/phhb2r7x8vv2q19g0zgib79bnws26lm5-profile"] ["/nix/var/nix/profiles/default-2-link.tmp-21642-675601655"]

I could do a sudo chown -R $USER:staff /nix/store/ but that may break other functionality as it relates to upgrading nix itself.

Notes

current nix/profiles structure:

$ lst -la /nix/var/nix/profiles
drwxr-xr-x  - root 23 Oct 16:58 /nix/var/nix/profiles
lrwxr-xr-x@ - root 23 Oct 16:58 ├── default -> default-1-link
lrwxr-xr-x@ - root 23 Oct 16:58 ├── default-1-link -> /nix/store/3k8kskx5spyh8b3cpcgamxwa5b968nv2-user-environment
drwxr-xr-x@ - root 23 Oct 16:53 └── per-user
drwxr-xr-x  - root 23 Oct 16:53    └── root
lrwxr-xr-x  - root 23 Oct 16:53       ├── profile -> profile-2-link
lrwxr-xr-x  - root 23 Oct 16:53       ├── profile-1-link -> /nix/store/2jmz18bzl8aqzc3b3cw4i9m0lm31zfm3-user-environment
lrwxr-xr-x  - root 23 Oct 16:53       └── profile-2-link -> /nix/store/wa1h26xv52nh3833bl4x86fnhxqbi4y7-user-environment
$ nix profile list
Name:               nix
Store paths:        /nix/store/1n95r340s7p3vdwqh7m94q0a42crahqq-nix-2.24.9

Name:               nss-cacert
Store paths:        /nix/store/9x1bbfhmnsycfq8p5y790jylnjiv0yif-nss-cacert-3.101

Listing profiles also resulted in a permission error:

$ sudo       nix-env --list-generations
Password:
Sorry, try again.
Password:
warning: $HOME ('/Users/mkatychev') is not owned by you, falling back to the one defined in the 'passwd' file ('/var/root')
   1   2024-10-23 16:53:07
   2   2024-10-23 16:53:07   (current)

System:

OS: macOS 14.6.1 23G93 arm64
Host: MacBookPro17,1
Kernel: 23.6.0
Uptime: 1 min
Packages: 303 (brew), 51 (nix-user)
Shell: zsh 5.9
Resolution: 1440x900
DE: Aqua
WM: Rectangle
Terminal: tmux
CPU: Apple M1
GPU: Apple M1
Memory: 2300MiB / 16384MiB
grahamc commented 6 days ago

Hey @mkatychev, we're taking a look at this and will get a better reply sooner. But in the mean time, please don't do this:

I could do a sudo chown -R $USER:staff /nix/store/ but that may break other functionality as it relates to upgrading nix itself.

It won't help the problem, and will cause other problems :').

mkatychev commented 6 days ago

Agreed, I figured I would highlight it as a bad idea that could make things work temporarily :)

mkatychev commented 6 days ago

UPDATE: I've had to some manual removal for the profile install to work:

sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist
rm -rf ~/.nix-profile
rm -rf ~/.local/state/nix

This allows me to reinstall correctly, however the ~/.local/state/nix/profiles/profile symlink is dangling:

/Users/mkatychev/.nix-profile -> /Users/mkatychev/.local/state/nix/profiles/profile

https://nix.dev/manual/nix/2.18/command-ref/new-cli/nix3-profile

Using an absolute path for nix now profile installs without sudo:

 /nix/var/nix/profiles/default/bin/nix profile install 'github:NixOS/nixpkgs#hello'