Nix: Switch Mac installer to set up multi-user installation of Nix

Created on 13 Sep 2016  路  14Comments  路  Source: NixOS/nix

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

darwin

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.conf field trusted-binay-caches field, and restart the daemon

sudo launchctl stop org.nixos.nix-daemon
sudo launchctl start org.nixos.nix-daemon

All 14 comments

:+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:

  1. This only works on Darwin. It could be extended to Linuxes at some point, but that is definitely not my goal right now. We could embed this in the installer and switch over to it if the user is on Darwin.
  2. NixOps is a right pain to configure on Darwin with the daemon. NixOps can only work on Darwin if Nix is configured to use remote builders, which NixOps currently does by magic if you're not using the daemon: https://github.com/NixOS/nixops/blob/master/nixops/deployment.py#L598 Fixing this requires help output and guidance on how to setup reemote builders, and reducing the pain around configuring and debugging remote builders :P
  3. While the script works flawlessly for me every time I use it, I'd very much like to have other experienced Nix users test it, before inflicting it upon newbies. Note: You have to uninstall any nix already installed, prior to testing the installer. The installer guides you on how to do this. Remember, at the end it is easy to uninstall again, and go back to without a daemon! _Please test!_

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).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukego picture lukego  路  34Comments

lovesegfault picture lovesegfault  路  37Comments

cbarrett picture cbarrett  路  49Comments

matthewbauer picture matthewbauer  路  64Comments

pjotrp picture pjotrp  路  37Comments