nixpkgs/nixos/modules
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
..
config Merge pull request #168168 from fedeinthemix/home-mode 2022-05-23 12:27:49 +02:00
hardware nixos: don't put non-firmware in hardware.firmware 2022-05-12 15:17:51 +00:00
i18n/input-method nixos/fcitx5: add the setting of RIME_DATA_DIR and options for rime-data 2022-04-25 13:39:19 +08:00
installer Merge #172668: installation-cd: add more guest tools to NixOS graphical installation base 2022-05-19 12:12:10 +02:00
misc nixos/locate: clarification in warning message (#173247) 2022-05-17 16:47:33 +02:00
profiles Merge pull request #169113 from ElvishJerricco/systemd-stage-1-installer-tests 2022-04-30 13:18:57 -07:00
programs nixos/gnupg: default to a reasonable pinentry program on headless systems 2022-05-18 18:31:34 +02:00
security Merge pull request #156822 from xfix/wrapper-assert-argc-at-least-one 2022-05-16 18:52:51 +02:00
services nixos/timetagger: drop non-evaluating service files 2022-05-25 21:24:48 +02:00
system nixos/stage-1: Fix library path in libraries also 2022-05-26 22:17:02 +02:00
tasks Merge pull request #171650 from helsinki-systems/feat/config-systemd-package 2022-05-09 10:23:04 +02:00
testing nixos/version: Warn about using the default of system.stateVersion 2022-05-05 12:22:31 +02:00
virtualisation Merge pull request #172131 from euank/ena-2.7.1 2022-05-12 01:38:24 +03:00
module-list.nix Merge pull request #153481 from Tchekda/submit/bird-lg 2022-05-25 18:20:58 +02:00
rename.nix nixos/ssmtp: drop module 2022-04-17 00:44:50 +02:00