Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix profile [verb] failing on MacOS 14 with permission error #9702

Closed
n8henrie opened this issue Jan 6, 2024 · 8 comments
Closed

nix profile [verb] failing on MacOS 14 with permission error #9702

n8henrie opened this issue Jan 6, 2024 · 8 comments
Labels
bug macos Nix on macOS, aka OS X, aka darwin

Comments

@n8henrie
Copy link
Contributor

n8henrie commented Jan 6, 2024

Describe the bug

I have nix installed on my wife's laptop so I can do maintenance tasks. I don't feel like setting up nix-darwin since I only use these occasionally and want the rest of the system to work as usual.

A few utilities I had pinned can no longer be upgraded, removed, and nothing new can be installed, all with permissions errors:

Steps To Reproduce

$ nix profile remove 1
removing 'flake:nixpkgs#legacyPackages.aarch64-darwin.jq'
error: creating symlink from '/nix/var/nix/profiles/per-user/username/profile-7-link.tmp-22749-874578672' to '/nix/store/95zdhdn0198wr1f8pdzwb1l6sq5vygca-profile': Permission denied
$
$ ls -ld /nix/var/nix/profiles/per-user/username/
drwxr-xr-x 9 root nixbld 288 Jan 10  2023 /nix/var/nix/profiles/per-user/username/
$ ls -l /nix/var/nix/profiles/per-user/username/
total 0
lrwxr-xr-x 1 root nixbld 14 Jan 10  2023 profile -> profile-6-link
lrwxr-xr-x 1 root nixbld 51 Jan 10  2023 profile-1-link -> /nix/store/v8nfk141v59vbxgz9y74m9vrvsy0x0bm-profile
lrwxr-xr-x 1 root nixbld 51 Jan 10  2023 profile-2-link -> /nix/store/93a6qsws35i3x9zrc1rg2ckpp18sq13f-profile
lrwxr-xr-x 1 root nixbld 51 Jan 10  2023 profile-3-link -> /nix/store/wpjagz66frwf8f8fmiq51j5lv4db0yml-profile
lrwxr-xr-x 1 root nixbld 51 Jan 10  2023 profile-4-link -> /nix/store/gmvfx1k21x9h8i0hlc88j9zyyvnbc0fx-profile
lrwxr-xr-x 1 root nixbld 51 Jan 10  2023 profile-5-link -> /nix/store/mk683q0wpvb32vzffppq6gcyrm2784b6-profile
lrwxr-xr-x 1 root nixbld 51 Jan 10  2023 profile-6-link -> /nix/store/4iaqcdmpi5q34zlqg57ma17n0g97mssq-profile

Expected behavior

Can install / remove / upgrade pinned packages.

nix-env --version output

$ nix-env --version
nix-env (Nix) 2.19.2

Additional context

I might have had to reinstall nix a few months ago because it wasn't working after an OS upgrade? Can't remember.

Tried adding username to trusted-users and relaunching nix-daemon, didn't change anything.

Priorities

Add 👍 to issues you find important.

@n8henrie n8henrie added the bug label Jan 6, 2024
@n8henrie
Copy link
Contributor Author

n8henrie commented Jan 6, 2024

On my machine, permissions for /nix/var/nix/profiles/per-user/$user are $user:wheel instead of root:nixbld.

Should I just chmod these? Or perhaps there is a nix way to verify / fix permissions? Or maybe just reinstall again?

EDIT: Or maybe my machine is the one that's wrong, it's a much older install!

@fricklerhandwerk fricklerhandwerk added the macos Nix on macOS, aka OS X, aka darwin label Jan 15, 2024
@yannham
Copy link
Contributor

yannham commented Jan 25, 2024

FYI, I had the same issue on Debian (after nix couldn't be found in path anymore, I reinstalled it although my store and all config files were still around, and got this issue afterward - or maybe this was the original issue causing nix to not be in the path in the first place? anyway). chown-ing /nix/var/nix/profiles/per-user/$user seems to have fixed the error for the time being.

@n8henrie
Copy link
Contributor Author

I just reinstalled and now /nix/var/nix/profiles/per-user/$USER doesn't exist at all.

@n8henrie
Copy link
Contributor Author

Just tried sudo rm -r /nix/var/ and then reinstalling and I still have no user directory:

$ ls -A /nix/var/nix/profiles/per-user
root

@n8henrie
Copy link
Contributor Author

Reinstalled again, this time removing /nix/var/* and ~/.nix-*. Looks like there's an error during the installation that I probably missed:

~~> Setting up the nix-daemon LaunchDaemon
Load failed: 5: Input/output error
Try running `launchctl bootstrap` as root for richer errors.
Alright! We're done!
Try it! Open a new terminal, and type:

Seems to be coming from

task "Setting up the nix-daemon LaunchDaemon"

Looks like this should be the missing step:

$ NIX_DAEMON_DEST=/Library/LaunchDaemons/org.nixos.nix-daemon.plist
$ sudo /usr/bin/install -m -rw-r--r-- "/nix/var/nix/profiles/default$NIX_DAEMON_DEST" "$NIX_DAEMON_DEST"
$ sudo launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist
$ sudo launchctl kickstart -k system/org.nixos.nix-daemon

I get an error at:

$ sudo launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist
Load failed: 5: Input/output error
Try running `launchctl bootstrap` as root for richer errors.

Probably should be using bootstrap instead of load here, I guess (as bootstrap is used elsewhere and we're using the non-legacy kickstart just below that).

$ sudo launchctl bootstrap system /Library/LaunchDaemons/org.nixos.nix-daemon.plist
Bootstrap failed: 5: Input/output error

Ok, probably due to the prior installation.

$ sudo launchctl bootout system/org.nixos.nix-daemon
$ sudo launchctl bootout system/org.nixos.nix-daemon
Boot-out failed: 3: No such process

Yup, failed the second time, so I assume that's it.

$ sudo launchctl bootstrap system /Library/LaunchDaemons/org.nixos.nix-daemon.plist
$ echo $?
0

Good deal.

$ sudo launchctl kickstart -k system/org.nixos.nix-daemon

But still no user profile...

$ ls /nix/var/nix/profiles/per-user/
root

@n8henrie
Copy link
Contributor Author

Followed uninstall instructions from https://nixos.org/manual/nix/stable/installation/uninstall.html#macos and tried to reinstall again.

Got an error about ~/.local/state/nix/ -- removed that, repeated the uninstall instructions, repeated install...

$ ls /nix/var/nix/profiles/per-user/
root

Interestingly, according to https://nixos.wiki/wiki/User_Environment

~/.nix-profile is a symbolic link to the current user environment (an automatically generated package consisting of symlinks to installed packages).

❯ ls -l ~/.nix-profile
lrwxrwxrwx ... /home/username/.nix-profile -> /nix/var/nix/profiles/per-user/username/profile

But for me:

$ ls -l ~/.nix-profile
lrwxr-xr-x  1 username  staff  50 Jan 30 17:09 /Users/username/.nix-profile -> /Users/username/.local/state/nix/profiles/profile

@n8henrie
Copy link
Contributor Author

Related? #7984

Well my initial attempt to install home-manager failed due to this directory not existing, but this one succeeded even without the /nix/var/nix/profiles directory existing. So perhaps it's unnecessary. Oh well.

@thufschmitt
Copy link
Member

@n8henrie The wiki page is outdated it seems. /nix/var/nix/profiles/$USER doesn't exist any more on fresh installs and is replaced by ~/.local/state/nix/profiles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug macos Nix on macOS, aka OS X, aka darwin
Projects
None yet
Development

No branches or pull requests

4 participants