Unlike the general linux case, we know that Mac OS is running launchd and it's fairly easy to make sure the Nix daemon runs automatically at startup. I imagine the install script wouldn't need much adjustment to register the Nix plist with launchd and set the right permissions on the nix store.
cc @grahamc and @shlevy
:+1:
How would this be implemented? A custom Mac version of install-nix-from-closure.sh might be needed?
Another step that might be useful for the installer:
Set /etc/paths.d/nix to /nix/var/nix/profiles/default/bin for system-wide profiles.
okay, here's a script to convert your Nix setup to multi-user on mac:
https://raw.githubusercontent.com/matthewbauer/macNixOS/master/install-macNixOS.sh
It's not very well tested yet but it seems to run correctly on my machine. It will move your current profile to /nix/var/nix/profiles/per-user/$USER.
The biggest issue is that there really isn't a way to tell in your profile whether you are multi-user or single-user. Right now, to determine whether it's multi-user I just check whether the owner of /nix/ is root.
Yesterday I made this script: https://gitlab.com/grahamc/mac-nix-multi-user/blob/master/install.sh it takes a Mac installation with _no_ Nix installed at all, and goes directly to a multi-user install.
There is no middle point of having a single-user Nix installation. It doesn't use the default single-user nix install.sh, instead I read the source to the single-user installer, nixos-install, and the various NixOS modules that handle installing and configuring Nix on NixOS.
I have tested this several times on a computer without any Nix on it, and it ended up working great for me. I need more testers, though, and would love to make the default nix installer do this on Darwin.
You can see me run it, and the output here: https://grahamc.gitlab.io/mac-nix-multi-user/
@grahamc Can you open a PR to change the install.sh to do that by default?
@shlevy I would be happy to! but first:
Given this feedback, do you feel now is the time to make that PR?
IMO 1) is completely fine, switching on darwin vs linux is necessary already to get the right tarball anyway.
2)... I'm less sure. Don't know how many nixops on darwin users there are or how easy it would be to output the instructions meaningfully. But I'm hesitant to say that's a blocker, maybe we should just open an issue on nixops in the mean time
3) Yeah, let's definitely get some testing. Can you set up a gist or something that we can point darwin users to to quickly test and, if needed, revert? I've got a bunch of people in mind who would be good testers.
1: sounds good
2: I agree (cc @LnL7 @cleverca22 @domenkozar)
3:
Users can already get https://gitlab.com/grahamc/mac-nix-multi-user/raw/master/install.sh and start testing :) reverting involves:
Uninstalling nix:
1. If /Library/LaunchDaemons/org.nixos.nix-daemon.plist exists:
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist
2. If /etc/profile.nix-bak exists:
sudo mv /etc/profile.nix-bak /etc/profile
(after this one, you may need to re-open any terminals that were
opened while it existed.)
3. Delete the files Nix added to your system:
sudo rm -rf /etc/nix /nix /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels /Users/graham/.nix-profile /Users/graham/.nix-defexpr /Users/graham/.nix-channels
and that is it.
(described in the output of the installer, see a full run here: https://grahamc.gitlab.io/mac-nix-multi-user/index.html) followed by reinstalling the standard installer.
FYI: I'm tracking successful installations here: https://gitlab.com/grahamc/mac-nix-multi-user/issues/2
Some suggested documentation for after installation, something along the lines of:
If you use remote binary caches, add them to /etc/nix/nix.conf field trusted-binay-caches field, and restart the daemon
sudo launchctl stop org.nixos.nix-daemon
sudo launchctl start org.nixos.nix-daemon
This has been merged in #1453 for Nix 1.11.12, now just needs another PR for master.
This can be closed now.
What is the plan for NixOps on MacOS -- this is an important feature (to me).
That belongs to https://github.com/NixOS/nixops/issues/560
Most helpful comment
Some suggested documentation for after installation, something along the lines of:
If you use remote binary caches, add them to
/etc/nix/nix.conffieldtrusted-binay-cachesfield, and restart the daemon