Closed nightkr closed 4 years ago
What does ~/.nix-profile
point to on your machine?
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:
.nix-profile
to point to /nix/var/nix/profiles/default
(and installed nix
there).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.
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
- Your single-user install is for root, not for a regular user.
Nope, as plain a user as can be.
- 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.
- 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.
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.
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.
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).
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, sincenix-daemon.sh
is a part of thenixpkgs.nix
package, which is always installed for single-user installs: