I’m trying to create a somewhat FHS compatible NixOS installation by symlinking /run/current-system/sw
to /usr
.
I’m using the configuration
{ pkgs, ... }: {
systemd.tmpfiles.rules = [ "L+ /usr - - - - /run/current-system/sw" ];
environment.systemPackages = [ pkgs.python3 pkgs.python3Packages.pip ];
}
and start a virtual machine built with this configuration with nixos-shell
which mounts my $HOME
folder to the VM.
For testing, I used a Hello World binary compiled in a Debian Bookworm chroot, that I copied to ~/hello_compiled_on_bookworm
.
On my host system I am using nix-ld, so I can execute that file. On my host system, ldd shows me
ldd ~/hello_compiled_on_bookworm
linux-vdso.so.1 (0x00007ffd2bbab000)
libc.so.6 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 (0x00007f6d9e4b3000)
/lib64/ld-linux-x86-64.so.2 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 (0x00007f6d9e6a0000)
On my experimental VM with the above config, when trying to run that binary I get
~/hello_compiled_on_bookworm
zsh: no such file or directory: /home/jan/hello_compiled_on_bookworm
In that VM, ldd shows me
~/mydocuments/computer/nix/nixos-fhs: ldd ~/hello_compiled_on_bookworm
linux-vdso.so.1 (0x00007ffea77ac000)
libc.so.6 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 (0x00007f7a508c7000)
/lib64/ld-linux-x86-64.so.2 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 (0x00007f7a50ab4000)
I don’t understand how ldd
in the VM understands that it has to search for files in the Nix store. LD_LIBRARY_PATH
is not set. The directory /lib64
does not exist. I suspect that nixos-shell
is leaking parts of my environment into the VM but I don’t understand which parts could be responsible for this.
In the Debian Bookworm chroot, ldd
yields
ldd a.out
linux-vdso.so.1 (0x00007ffea3f99000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd45f87a000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd45fa66000)
And I would have expected a similar output from ldd
inside the VM.