Nix: Nix symlinks to non-existent profile in multi-user setup

Created on 20 Aug 2019  路  6Comments  路  Source: NixOS/nix

I've installed Nix 2.2.2 in multi-user using --daemon on a Linux host but when I source the /etc/profile.d/nix.sh it creates a symlink at ~/.nix-profile to a non-existent profile:

 $ ls -l ~/.nix-profile 
lrwxrwxrwx 1 test test 46 Aug 19 20:22 /home/test/.nix-profile -> /nix/var/nix/profiles/per-user/test/profile
 $ ls -l /nix/var/nix/profiles/per-user/test/profile
ls: cannot access '/nix/var/nix/profiles/per-user/test/profile': No such file or directory 

I don't get how this is supposed to work.
Is there some command I have to run to create a profile for this user?

Most helpful comment

@matthewbauer If the requirement here is that the user should restart their computer after installing nix, it would be useful if this were logged somewhere in the installer's finish_success message. I was just saying we can't actually do nix-env -iA nixpkgs.hello to workaround this problem immediately after installation because we don't have nix-env on the PATH yet.

All 6 comments

I believe you only have to install something for that user:

$ nix-env -iA nixpkgs.hello

You're right, that did create it. Thank you!

 $ ls -l ~/.nix-profile/
ls: cannot access '/home/jenkins/.nix-profile/': No such file or directory
 $ nix-env -iA nixpkgs.hello
installing 'hello-2.10'
 $ ls -l ~/.nix-profile/
total 8
lrwxrwxrwx 1 root root 58 Jan  1  1970 bin -> /nix/store/94qwaibxqn26q41byczq06b0pgdhia9a-hello-2.10/bin
lrwxrwxrwx 1 root root 60 Jan  1  1970 manifest.nix -> /nix/store/8amc0nnr0hwigwb2g4xpvdjznl6gkm20-env-manifest.nix
lrwxrwxrwx 1 root root 60 Jan  1  1970 share -> /nix/store/94qwaibxqn26q41byczq06b0pgdhia9a-hello-2.10/share

I think it would be prudent to include a note about this in the multi-user docs section:
https://nixos.org/nix/manual/#sect-multi-user-installation
Or even better, create some kind of default profile during installation. It's weird it does not.

@matthewbauer This behavior is a little strange, because in my user profile (.profile) I import $HOME/.nix-profile/etc/profile.d/nix.sh, which is what gives me access to nix-env. So it seems like a bit of a chicken and egg problem.

@matthewbauer This behavior is a little strange, because in my user profile (.profile) I import $HOME/.nix-profile/etc/profile.d/nix.sh, which is what gives me access to nix-env. So it seems like a bit of a chicken and egg problem.

Yeah, multi-user intentionally avoids messing with individual user profile's. This way, you don't have to run the installer again every time you rerun the installer. The profile setup should happen in /etc/profile, /etc/zshrc, and /etc/bash. You can also just use /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh instead of $HOME/.nix-profile/etc/profile.d/nix.sh.

@matthewbauer If the requirement here is that the user should restart their computer after installing nix, it would be useful if this were logged somewhere in the installer's finish_success message. I was just saying we can't actually do nix-env -iA nixpkgs.hello to workaround this problem immediately after installation because we don't have nix-env on the PATH yet.

Use version 2.3.10, face the same problem.
Run the following script

nix-env -iA nixpkgs.hello

It create a symbol link $HOME/.nix-profile but which link to a non-existent profile.

Was this page helpful?
0 / 5 - 0 ratings