lilyball / nix-env.fish

Nix environment setup for the fish shell
The Unlicense
278 stars 15 forks source link

Multiuser mode is always assumed #3

Closed nightkr closed 4 years ago

nightkr commented 4 years ago

dffcee7997f1d361b2744b27c8162b9dd5bdbd06 adds a check for whether to use daemon/multiuser mode by checking whether /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh exists. But that always triggers, since nix-daemon.sh is a part of the nixpkgs.nix package, which is always installed for single-user installs:

 teo  ~  stat (nix path-info nixpkgs.nix)/etc/profile.d/nix-daemon.sh                                                                                                                                                
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
  File: /nix/store/43822pavpsvlnx6cfph58pxnhndjnmdd-nix-2.3.6/etc/profile.d/nix-daemon.sh
  Size: 1334            Blocks: 8          IO Block: 4096   regular file
Device: 10303h/66307d   Inode: 16648927    Links: 1
Access: (0444/-r--r--r--)  Uid: ( 1000/     teo)   Gid: ( 1000/     teo)
Access: 2020-06-08 09:34:44.325693143 +0200
Modify: 1970-01-01 01:00:01.000000000 +0100
Change: 2020-06-08 09:33:37.459140843 +0200
 Birth: 2020-06-08 09:33:37.359135320 +0200
lilyball commented 4 years ago

What does ~/.nix-profile point to on your machine?

lilyball commented 4 years ago

According to the implementation the default value of ~/.nix-profile is only /nix/var/nix/profiles/default if the current user is root; for any other user it's a per-user profile. So there's only 3 ways for /nix/var/nix/profiles-default/etc/profile.d/nix-daemon.sh to exist on a single-user install that I can think of:

  1. Your single-user install is for root, not for a regular user.
  2. You manually switched your .nix-profile to point to /nix/var/nix/profiles/default (and installed nix there).
  3. You ran something like nix-env -iA nixpkgs.nix -p /nix/var/nix/profiles/default to manually install nix into the default profile despite it not being the active profile (or even included in PATH by default on a single-user install).

I'd love to know which scenario applies to your setup.

nightkr commented 4 years ago

What does ~/.nix-profile point to on your machine?

 teo  ~  stat ~/.nix-profile                                                                                                                                                                                         
  File: /home/teo/.nix-profile -> /nix/var/nix/profiles/default
  Size: 29              Blocks: 0          IO Block: 4096   symbolic link
Device: 10303h/66307d   Inode: 8395116     Links: 1
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/     teo)   Gid: ( 1000/     teo)
Access: 2020-06-08 21:51:24.497910343 +0200
Modify: 2015-11-29 04:23:35.353859443 +0100
Change: 2015-11-29 04:23:35.353859443 +0100
 Birth: 2015-11-29 04:23:35.353859443 +0100
  1. Your single-user install is for root, not for a regular user.

Nope, as plain a user as can be.

  1. You manually switched your .nix-profile to point to /nix/var/nix/profiles/default (and installed nix there).

Nope, I have not mucked the symlinks by hand.

  1. You ran something like nix-env -iA nixpkgs.nix -p /nix/var/nix/profiles/default to manually install nix into the default profile despite it not being the active profile (or even included in PATH by default on a single-user install).

Nope, didn't even know about the -p argument.

Could it be that the Nix installer script sets up the profile differently as part of the bootstrapping? Or at the behaviour has changed in the last couple of years, this is a pretty old install.

nightkr commented 4 years ago

Okay, I tried doing an install into a clean ubuntu docker image, and it seems to have created a per-user profile:

$ stat .nix-profile
  File: .nix-profile -> /nix/var/nix/profiles/per-user/foo/profile
  Size: 42              Blocks: 0          IO Block: 4096   symbolic link
Device: 44h/68d Inode: 7772686     Links: 1
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/     foo)   Gid: ( 1000/     foo)
Access: 2020-06-09 06:52:07.148961326 +0000
Modify: 2020-06-09 06:52:07.145628014 +0000
Change: 2020-06-09 06:52:07.145628014 +0000
 Birth: -

So I'm starting to guess that it's a legacy thing.

lilyball commented 4 years ago

It looks like the default single-user profile changed in Nix 2.0. Prior to that it did indeed default to /nix/var/nix/profiles/default.

So it looks like I need another way to detect multi-user setups. I don’t particularly want to check the owner of /nix because I assume someone somewhere wants a single-user install owned by root.

In the meantime I suggest either switching to a per-user profile (nix-env can copy from one profile to another) and blowing away the default one, or just modify your copy of this plugin until I can come up with an alternative reliable means of detection.

lilyball commented 4 years ago

I just pushed c239a69122c88797b34e3721659b2ba5060ca7e7 which implements a new detection mechanism. I tested this on my local single-user install (with a per-user profile) as well as a new single-user install in a Docker image where I set up the user profile to be /nix/var/nix/profiles/default. I don't have a non-NixOS multi-user install to test with so I hope I didn't just break that (I can't set one up in Docker because I can't install systemd in Docker on macOS AFAICT as it seems to need cgroup mapping and macOS doesn't have cgroups).