Dear NixOS/Nix community!
This post is a follow-up to my previous help request here. As a quick reminder, I want to use Nix as a package manager for an unprivileged user with no system-wide Nix installation.
I have discovered that when I use a static build of Nix (currently experimenting with the following builds: maintenance-2.32 and master), from inside the nix shell many system files are seen as owned by nodoby:nobody, which breaks some of the host programs.
More specifically, I am running a Fedora 42 host, I downloaded a static build of Nix from one of the links above (reproducible with either of them), put it into ~/.local/bin and made it executable. Then, I created ~/.config/nix/nix.conf with the following contents:
extra-experimental-features = nix-command flakes
and created a flake directory, ~/flake, with the following in ~/flake/flake.nix:
{
outputs = { self, nixpkgs }: {
packages.x86_64-linux.default = with nixpkgs.legacyPackages.x86_64-linux; buildEnv {
name = "project";
paths = [
yazi
btop
];
};
};
}
When I enter the Nix shell by doing nix shell ~/flake, yazi and btop binaries become available as expected, with /nix/store/j993rn8ppsrqbyi5j4q2cgr7aqc799z9-project/bin/ in the $PATH, and /nix visible as owned by user_main:user_main (my unprivileged user that I run all commands as). /nix doesn’t exist outside of the Nix shell.
I discovered an issue when I put a similar nix shell invocation in my ~/.bashrc to ensure that all the binaries from the flake are available to me right away on every login. When I later tried to perform a git push, I ran into an SSH error, which I was able to pin down to the following:
[user_main@libvirt-fedora-experiments ~]$ ssh user_main@localhost
Bad owner or permissions on /etc/ssh/ssh_config.d/20-systemd-ssh-proxy.conf
[user_main@libvirt-fedora-experiments ~]$ ls -la /etc/ssh/ssh_config.d/20-systemd-ssh-proxy.conf
lrwxrwxrwx. 1 nobody nobody 63 Oct 12 20:00 /etc/ssh/ssh_config.d/20-systemd-ssh-proxy.conf -> ../../../usr/lib/systemd/ssh_config.d/20-systemd-ssh-proxy.conf
[user_main@libvirt-fedora-experiments ~]$ ls -la /
total 60
drwxr-xr-x. 20 user_main user_main 480 Dec 1 08:10 .
drwxr-xr-x. 20 user_main user_main 480 Dec 1 08:10 ..
dr-xr-xr-x. 2 nobody nobody 4096 Jul 29 20:00 afs
lrwxrwxrwx. 1 user_main user_main 7 Dec 1 08:10 bin -> usr/bin
dr-xr-xr-x. 6 nobody nobody 4096 Nov 30 08:50 boot
drwxr-xr-x. 19 nobody nobody 3880 Dec 1 07:53 dev
drwxr-xr-x. 84 nobody nobody 4096 Nov 30 08:50 etc
drwxr-xr-x. 3 nobody nobody 4096 Oct 20 15:30 home
lrwxrwxrwx. 1 user_main user_main 7 Dec 1 08:10 lib -> usr/lib
lrwxrwxrwx. 1 user_main user_main 9 Dec 1 08:10 lib64 -> usr/lib64
drwx------. 2 nobody nobody 16384 Oct 20 15:28 lost+found
drwxr-xr-x. 2 nobody nobody 4096 Jul 29 20:00 media
drwxr-xr-x. 2 nobody nobody 4096 Jul 29 20:00 mnt
drwxr-xr-x. 3 user_main user_main 60 Dec 1 08:10 nix
drwxr-xr-x. 2 nobody nobody 4096 Jul 29 20:00 opt
dr-xr-xr-x. 264 nobody nobody 0 Dec 1 07:53 proc
dr-xr-x---. 4 nobody nobody 4096 Oct 20 16:38 root
drwxr-xr-x. 36 nobody nobody 860 Dec 1 07:53 run
lrwxrwxrwx. 1 user_main user_main 8 Dec 1 08:10 sbin -> usr/sbin
drwxr-xr-x. 2 nobody nobody 4096 Jul 29 20:00 srv
dr-xr-xr-x. 13 nobody nobody 0 Dec 1 07:53 sys
drwxrwxrwt. 15 nobody nobody 320 Dec 1 08:10 tmp
drwxr-xr-x. 11 nobody nobody 4096 Oct 20 15:28 usr
drwxr-xr-x. 18 nobody nobody 4096 Oct 20 16:26 var
As can be seen from the listing above, one of the SSH configuration files is visible as owned by nobody:nobody from within the Nix shell, which prevents normal SSH functioning. Apparently, this is also the case for many other system files.
If I exit the Nix shell, the permissions are back to expected:
[user_main@libvirt-fedora-experiments ~]$ exit
exit
[user_main@libvirt-fedora-experiments ~]$ ls -la /etc/ssh/ssh_config.d/20-systemd-ssh-proxy.conf
lrwxrwxrwx. 1 root root 63 Oct 12 20:00 /etc/ssh/ssh_config.d/20-systemd-ssh-proxy.conf -> ../../../usr/lib/systemd/ssh_config.d/20-systemd-ssh-proxy.conf
[user_main@libvirt-fedora-experiments ~]$ ls -la /
total 33554504
dr-xr-xr-x. 19 root root 4096 Oct 20 16:37 .
dr-xr-xr-x. 19 root root 4096 Oct 20 16:37 ..
dr-xr-xr-x. 2 root root 4096 Jul 29 20:00 afs
lrwxrwxrwx. 1 root root 7 Jul 29 20:00 bin -> usr/bin
dr-xr-xr-x. 6 root root 4096 Nov 30 08:50 boot
drwxr-xr-x. 19 root root 3880 Dec 1 07:53 dev
drwxr-xr-x. 84 root root 4096 Nov 30 08:50 etc
drwxr-xr-x. 3 root root 4096 Oct 20 15:30 home
lrwxrwxrwx. 1 root root 7 Jul 29 20:00 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Jul 29 20:00 lib64 -> usr/lib64
drwx------. 2 root root 16384 Oct 20 15:28 lost+found
drwxr-xr-x. 2 root root 4096 Jul 29 20:00 media
drwxr-xr-x. 2 root root 4096 Jul 29 20:00 mnt
drwxr-xr-x. 2 root root 4096 Jul 29 20:00 opt
dr-xr-xr-x. 263 root root 0 Dec 1 07:53 proc
dr-xr-x---. 4 root root 4096 Oct 20 16:38 root
drwxr-xr-x. 36 root root 860 Dec 1 07:53 run
lrwxrwxrwx. 1 root root 8 Jul 29 20:00 sbin -> usr/sbin
drwxr-xr-x. 2 root root 4096 Jul 29 20:00 srv
-rw-------. 1 root root 34359738368 Oct 20 16:37 swapfile
dr-xr-xr-x. 13 root root 0 Dec 1 07:53 sys
drwxrwxrwt. 15 root root 320 Dec 1 08:10 tmp
drwxr-xr-x. 11 root root 4096 Oct 20 15:28 usr
drwxr-xr-x. 18 root root 4096 Oct 20 16:26 var
I wonder is anything can be done to achieve a similar workflow of binaries installed with Nix being readily available in $PATH, but with minimal disruptions to the rest of the system?
I have little knowledge of the inner workings of Nix, but I suspect that this may be related to the Nix sandbox and UID remapping via user namespaces. I have experimented with various nix.conf options discovered here, including:
extra-experimental-features = nix-command flakes auto-allocate-uids
auto-allocate-uids = true
sandbox = false
system-features = uid-range
but to no avail.
I would appreciate some guidance.
Thank you so much!