Macos permission issue on drv lock files and db files

Hi,

I have permission issues one macos with nix and home-manager.

Sometimes I got db error,

building the system configuration...
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: the store is not owned by this user, but /nix/var/nix/db is writable
If you are using the daemon:

    sudo chown -R /nix/var/nix/db

make: *** [mac_switch] Error 2

Sometimes I got permission errors on drv.lock files.

opening lock file '/nix/store/ky8w0qva2jgny30cnw3mzn4sjdihs7dn-launchd.drv.lock': Permission denied

I’m able to rebuild by changing the entire ownership of the nix folder with sudo chown -R $(whoami) /nix. But I don’t think that is the proper way.

Does anyone know what’s going on?

Thanks!

There may be others, but I recall two cases that might apply here:

  • If you have a single-user install and have been running Nix commands with sudo. The commands would work–but leave some files with root ownership around, which start causing problems when you run nix commands as your user. If you’ve done this, taking ownership and avoiding it in the future is right.
  • If you used a daemon install, but for some reason your Nix daemon isn’t/wasn’t running. You should be able to confirm this with launchctl, but I don’t recall the syntax off the top of my head.

I use a single-user install.

But there is a daemon required to run as well.

root             50958   0.0  0.0  4774564    272   ??  Ss   10:45PM   0:00.04 /nix/store/d0hz9vb2qjzcfm1ij8y2g02yd1r4yajv-nix-2.3.7/bin/nix-daemon

It’s running as root. That might be the root cause. But I have no idea how to fix it. Maybe home-manager has daemon options as well?

I realized I can just use the single user install without daemon. Then it works like a charm.

Thanks!