Nix: Install Nix as root

Created on 13 Jun 2016  Â·  10Comments  Â·  Source: NixOS/nix

How do i install Nix (single-user mode) as root on Linux?

I don't want to do a full manual install (compile it).

I tried the default way, but it fails:

[root@ipfire ~]# curl https://nixos.org/nix/install | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1383  100  1383    0     0   4150      0 --:--:-- --:--:-- --:--:--  4190
unpacking Nix binary tarball for i686-linux from `https://nixos.org/releases/nix/nix-1.11.2/nix-1.11.2-i686-linux.tar.bz2'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 64.8M  100 64.8M    0     0  1438k      0  0:00:46  0:00:46 --:--:-- 1377k
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...........................
initialising Nix database...
warning: the group ‘nixbld’ specified in ‘build-users-group’ does not exist
warning: the group ‘nixbld’ specified in ‘build-users-group’ does not exist
creating /root/.nix-profile
warning: the group ‘nixbld’ specified in ‘build-users-group’ does not exist
installing ‘nix-1.11.2’
building path(s) ‘/nix/store/mk06d1iiyscqnr9zl23bf42jb2vds1gh-user-environment’
error: the group ‘nixbld’ specified in ‘build-users-group’ does not exist
nix-binary-tarball-unpack.HoMEIazdBT/nix-1.11.2-i686-linux/install: unable to install Nix into your default profile

warning: installing Nix as root is not supported by this script!

what is missing here? can i do the last steps manually?
could you support installing as root?

feature

Most helpful comment

$ echo "build-users-group =" > /etc/nix/nix.conf

Is there anything against making @mboes's suggestion part of the installer script?

It seems to work quite well for me.

All 10 comments

I found a fairly simple workaround:

$ echo "build-users-group =" > /etc/nix/nix.conf

before running the install script.

this suggests that the install script could be modified so that it creates this configuration file to override the defaults in case the install user is root.

sh: you do not have 'shasum' installed, which I need to verify the binary tarball

this must be a new dependency. i don't have it on that system :/

On CentOS at any rate you need to install perl-Digest-SHA.

I understand this functionality isn't currently supported, but it would allow building of singularity containers more easily using nix. Singularity containers are manipulated only as root at build-time, then the UID maps to $USER at run-time, where the container is read-only. I'm currently using docker://nixos/nix as a base image as a workaround, but it would be nice to be able to take any other base image and install nix at build-time.

@alexhrescale Installing single-user Nix under root is possible, you may find this build script useful, it sets up nix in a Debian image, and also properly initializes the nixbld* build users.

the build script creates users though, which is not the same as non-root single-user install

$ echo "build-users-group =" > /etc/nix/nix.conf

Is there anything against making @mboes's suggestion part of the installer script?

It seems to work quite well for me.

Does that work? A root installation without build users has serious security implications.

this would be helpful to allow us to test the behaviour of nix-shell on ubuntu/debian/etc. environments on CI (e.g. circle CI uses root user)

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/installing-from-another-linux-distribution-as-root/10657/9

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Infinisil picture Infinisil  Â·  3Comments

luc65r picture luc65r  Â·  3Comments

vizanto picture vizanto  Â·  3Comments

eqyiel picture eqyiel  Â·  3Comments

bgamari picture bgamari  Â·  3Comments