nixpkgs/nixos/modules/system
Will Fancher 208e953381 systemd-stage-1: Fully merge /bin and /sbin
In #327506, we stopped using `/sbin` in the `pathsToLink` of `initrdBinEnv`. This inadvertantly stopped including the `sbin` directory of the `initrdBin` packages, which meant that things like `mdadm`'s udev rules, which referred to binaries by their `sbin` paths, stopped working.

The purpose of #327506 was to fix the fact that `mount` was not calling mount helpers like `mount.ext4` unless they happened to be in `/sbin`. But this raised some questions for me, because I thought we set `managerEnvironment.PATH` to help util-linux find helpers for both `mount` and `fsck`. So I decided to look at how this works in stage 2 to figure it out, and it's a little cursed.

---

What I already knew is that we have [this](696a4e3758/nixos/modules/system/boot/systemd.nix (L624-L625))

```
        # util-linux is needed for the main fsck utility wrapping the fs-specific ones
        PATH = lib.makeBinPath (config.system.fsPackages ++ [cfg.package.util-linux]);
```

And I thought this was how `mount` finds the mount helpers. But if that were true, then `mount` should be finding helpers in stage 1 because of [this](696a4e3758/nixos/modules/system/boot/systemd/initrd.nix (L411))

```
      managerEnvironment.PATH = "/bin";
```

Turns out, `mount` _actually_ finds helpers with [this configure flag](696a4e3758/pkgs/os-specific/linux/util-linux/default.nix (L59))

```
    "--enable-fs-paths-default=/run/wrappers/bin:/run/current-system/sw/bin:/sbin"
```

Ok... so then why do we need the PATH? Because `fsck` has [this](a75c7a102e/disk-utils/fsck.c (L1659))

```
	fsck_path = xstrdup(path && *path ? path : FSCK_DEFAULT_PATH);
```

(`path` is `getenv("PATH")`)

So, tl;dr, `mount` and `fsck` have completely unrelated search paths for their helper programs

For `mount`, we have to use a configure flag to point to `/run/current-system`, and for `fsck` we can just set PATH

---

So, for systemd stage 1, we *do* want to include packages' `sbin` paths, because of the `mdadm` problem. But for `mount`, we need helpers to be on the search path, and right now that means putting it somewhere in `/run/wrappers/bin:/run/current-system/sw/bin:/sbin`.
2024-08-12 23:35:01 -04:00
..
activation Merge pull request #323613 from CyberShadow/fix-nix-path-without-channels-v2 2024-07-28 13:31:10 +02:00
boot systemd-stage-1: Fully merge /bin and /sbin 2024-08-12 23:35:01 -04:00
etc nixos/etc: handle mountpoints on top of /etc when switching 2024-07-18 21:28:53 +02:00
build.nix nixos: remove all uses of lib.mdDoc 2024-04-13 10:07:35 -07:00