nixpkgs/nixos/modules/system/boot
Klemens Nanni d33e52b253 nixos/stage-1: Fix library path in libraries also
`extra-utils` composes the set of programs and libraries needed by

1. copying over all programs
2. copying over all libraries any program directly links against
3. set the runtime path for every program to the library directory

It seems that this approach misses the case where a library itself links
against another library.  That is to say, `extra-utils` assumes that
either only progams link against libraries or that every library linked
to by a library is already linked to by a program.

`mount.zfs` linking against `libcrypto`, in turn linking against `libdl`
shows how the current approach falls short:

```
$ objdump -p $(which mount.zfs) | grep NEEDED | grep -e libdl -e libcrypto
  NEEDED               libcrypto.so.1.1
$ ldd (which mount.zfs) | grep libdl
        libdl.so.2 => /nix/store/ybkkrhdwdj227kr20vk8qnzqnmj7a06x-glibc-2.34-115/lib/libdl.so.2 (0x00007f9967a9a000
```

Using `mount.zfs` directly in stage 1 init still works since
`LD_LIBRARY_PATH` overrides this (as intended).

util-linux's `mount` however executes `mount.zfs` with LD_LIBRARY_PATH
removed from its environment as can be seen with strace(1) in an
interactive stage 1 init shell (`boot.shell_on_fail` kernel parameter):

```
 # env -i LD_LIBRARY_PATH=$LD_LIBRARY_PATH $(which strace) -ff -e trace=/exec -v -qqq $(which mount) /mnt-root
execve("/nix/store/3gqbb3swgiy749fxd5a4k6kirkr2jr9n-extra-utils/bin/mount", ["/nix/store/3gqbb3swgiy749fxd5a4k"..., "/mnt-root"], ["LD_LIBRARY_PATH=/nix/store/3gqbb"...]) = 0
[pid  1026] execve("/sbin/mount.zfs", ["/sbin/mount.zfs", "<redacted>", "/mnt-root", "-o", "rw,zfsutil"], []) = 0
/sbin/mount.zfs: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=1026, si_uid=0, si_status=127, si_utime=0, si_stime=0} ---
```

env(1) is used for clarity (hence subshells for absoloute paths).

While `mount` uses the right library path, `mount.zfs` is stripped of
it, so ld.so(8) fails resolve `libdl` (as required by `libcrypto`).

To fix this and not rely on `LD_LIBRARY_PATH` to be set, fix the library
path inside libraries as well.

This finally mounts all ZFS filesystems using `zfsutil` with correct and
intended mount options.
2022-05-26 22:17:02 +02:00
..
loader systemd-boot: use mktemp from coreutils in installer 2022-05-02 15:44:55 +03:00
systemd nixos/systemd: Package only built component units 2022-05-16 16:52:25 +02:00
binfmt.nix nixos/nix-daemon: use structural settings 2022-01-26 21:04:50 -05:00
emergency-mode.nix
grow-partition.nix
initrd-network.nix
initrd-openvpn.nix
initrd-ssh.nix
kernel_config.nix
kernel.nix nixos: don't put non-firmware in hardware.firmware 2022-05-12 15:17:51 +00:00
kexec.nix
luksroot.nix nixos/systemd-stage-1: Remove unnecessary binaries 2022-04-30 14:50:02 +02:00
modprobe.nix treewide: pkgs.systemd -> config.systemd.package 2022-05-05 20:00:31 +02:00
networkd.nix nixos/networkd: allow RouteMetric for IPv6AcceptRA 2022-04-30 00:30:04 +02:00
pbkdf2-sha512.c
plymouth.nix nixos/plymouth: Fix non-systemd initrd boot 2022-05-23 11:17:21 +02:00
resolved.nix
shutdown.nix
stage-1-init.sh nixos/stage-1: Account for hardcoded executable paths 2022-05-26 22:17:02 +02:00
stage-1.nix nixos/stage-1: Fix library path in libraries also 2022-05-26 22:17:02 +02:00
stage-2-init.sh nixos/stage-1-systemd: Handover between the systemds directly 2022-04-11 20:04:33 +01:00
stage-2.nix Merge pull request #165453 from helsinki-systems/feat/systemd-manager-environment 2022-03-31 01:35:09 +02:00
systemd.nix nixos/systemd: Package only built component units 2022-05-16 16:52:25 +02:00
timesyncd.nix nixos/timesyncd: initialize clock file with current time 2022-03-05 21:27:45 +01:00
tmp.nix nixos/tmp: Fix format of /tmp mount options 2022-01-31 12:49:29 +01:00