What are the specific differences between (and perhaps use cases for) single-user and multi-user Nix installations?

Tried to find any kind of resource that breaks down the facts (and not pros/cons, performance comparisons, etc.) how the two modes of installation differ, but no joy:

  • The discussion in the issue Manual: Explain pros and cons of single and multi user installation #2799 doesn’t contain much information.

  • The reddit thread single user vs multi user installation simply suggets that “single-user is semi-deprecated”. (I have only ever used multi-user Nix installs, so I wonder: does single-user install have valid use cases?)

  • 3.2 Installing a Binary Distribution section in the Nix Reference Manual mentions that

    [single-user install] will perform a single-user installation of Nix, meaning that /nix is owned by the invoking user.

    but one will still need root access to create the default path of /nix(1,2). It is suggested here that root access can be avoided by setting a different Nix store path, but that option is available to multi-user Nix installs as well. (Although, a multi-user install also creates build users so that would also need root, right?..)

Anyway, it would be nice to document what these install modes do exactly so that users can make an informed decision. (And, if single-user mode is indeed not used and there also no valid use cases for it, shouldn’t it be explicitly deprecated? There are also very compelling reasons to avoid single-user mode in the thread Change my mind: I still want single-user on macOS.)


edit: This question came up while trying to create a simple PR to document the Nix installer’s options (see thread), but couldn’t help myself from looking at the details… Speaking of which, making a note here that 3.3 Installing Nix from Source feels incomplete: it gets to a point of how to build Nix, but it never brings up the topic of single-user and multi-user. I know that if one does everything by themselves then they can set up their system in a way that is not as black and white, but it would be nice to mention that after simply building Nix, one effectively has a single-user install (I think). At least, if someone reads that section to learn, they could use the previously learned terminologies (i.e., single-user & multi-user) as mental anchors.

3 Likes

I’m not aware of any usecases of single user nix, except for containers, where you usually do not want to run additional services.

Also it makes some sense on systems that do not run an init system that was supported out of the box.

2 Likes

The biggest reason to go with single-user is when you’re working on a system that doesn’t have easy compatibility with the multi-user setup.

A single user install has almost no dependencies or interaction with the host system at all. I needs root to create /nix, and it needs some really basic utilities, like coreutils and tar, for the installer to run. It also needs to add ~/.nix-profile to PATH in your init scripts. After that, it makes no demands on the host userspace at all.

The multi-user installer needs to do all those things, as well as install a service on the host system, add additional users for the service to run builds as, set up a socket to reach the service at, etc. All of that requires interacting a lot more deeply with how the host system is set up. If you don’t have systemd as your init on linux, I doubt the multi-user install can work at all without quite a bit of manual work.

As an example, if you have rooted your android phone to be able to create /nix, you can use the single-user install from termux and it should just work. A multi-user install has essentially no hope of working and is pointless in that environment anyway.

7 Likes

See my reply here The "How did you install Nix" poll - #5 by alexv

1 Like

so continues my dream of a nixos phone!

1 Like