Installing from another Linux distribution as root

Subsection 2.5.4 of the NixOS manual describes how to install NixOS from another Linux distribution, working in general as an ordinary user and becoming root occasionally via sudo. Is it also possible to execute this whole installation procedure as root?

The background of my question is that when I install NixOS, I install it from a rescue system where no ordinary user initially exists. I wouldn’t like to create such a user if it isn’t necessary.

It seems that the Nix installation script doesn’t work for root; so the answer to my question seems to be “no”.

Which part “doesn’t work”? What does “doesn’t work” mean, there is an error maybe?

As far as I remember, the installer script bails out with “don’t run me as root”.

It doesn’t bail out. It merely shows a warning that says you shouldn’t run it as root and fails a little bit later with an error message, which I have forgotton (and which wasn’t obvious to me).

Hm. Seems like a scenario we ought to support, in my opinion. (But I don’t know the context of why it’s warned against.)

1 Like

This is the output I get when running curl -L https://nixos.org/nix/install | sh as root on a fresh rescue system from my server provider:

Hardware data:

   CPU1: […]
   Memory:  […]
   Disk /dev/sda: 4000 GB (=> 3726 GiB) 
   Disk /dev/sdb: 4000 GB (=> 3726 GiB) 
   Total capacity 7452 GiB with 2 Disks

Network data:
   eth0  LINK: yes
         MAC:  […]
         IP:   […]
         IPv6: […]
         Intel(R) PRO/1000 Network Driver

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  2699  100  2699    0     0  46534      0 --:--:-- --:--:-- --:--:-- 46534
downloading Nix 2.3.10 binary tarball for x86_64-linux from 'https://releases.nixos.org/nix/nix-2.3.10/nix-2.3.10-x86_64-linux.tar.xz' to '/tmp/nix-binary-tarball-unpack.XhTPY6MlPk'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 16.4M  100 16.4M    0     0  40.6M      0 --:--:-- --:--:-- --:--:-- 40.6M
Note: a multi-user installation is possible. See https://nixos.org/nix/manual/#sect-multi-user-installation
warning: installing Nix as root is not supported by this script!
performing a single-user installation of Nix...
directory /nix does not exist; creating it by running 'mkdir -m 0755 /nix && chown root /nix' using sudo
copying Nix to /nix/store......................................
warning: the group 'nixbld' specified in 'build-users-group' does not exist
warning: the group 'nixbld' specified in 'build-users-group' does not exist
installing 'nix-2.3.10'
error: the group 'nixbld' specified in 'build-users-group' does not exist
/tmp/nix-binary-tarball-unpack.XhTPY6MlPk/unpack/nix-2.3.10-x86_64-linux/install: unable to install Nix into your default profile
2 Likes

weird, that error’s a bit confusing – you’re root, so you’d be able to make that group if needed, and running it as a normal user wouldn’t make that group magically be available.

related: Nix installation failing in ubuntu docker image · Issue #4219 · NixOS/nix · GitHub (I’m guessing they’re running docker with default settings and landing as root in the container).

1 Like

This comment has a workaround. If you can just create a temporary user to run the script, that might be safer. curl | sh requires some trust in any case. That way you can at least be sure that everything works as intended, while also limiting the amount of damage that a bug in the script can do.

There’s now a follow-up on this.