systemd: ensure fsck Requires/After links are created in mount units

systemd-fsck-generator only produces these lines if it can find the
necessary fsck executable in its PATH.

fixes #29139.

Changed files
+32 -1
nixos
modules
tests
+1 -1
nixos/modules/system/boot/stage-2-init.sh
···
# Start systemd.
echo "starting systemd..."
-
PATH=/run/current-system/systemd/lib/systemd \
+
PATH=/run/current-system/systemd/lib/systemd:@fsPackagesPath@ \
LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive \
exec systemd
+1
nixos/modules/system/boot/stage-2.nix
···
pkgs.utillinux
pkgs.openresolv
];
+
fsPackagesPath = lib.makeBinPath config.system.fsPackages;
postBootCommands = pkgs.writeText "local-cmds"
''
${config.boot.postBootCommands}
+1
nixos/release.nix
···
tests.firefox = callTest tests/firefox.nix {};
tests.flatpak = callTest tests/flatpak.nix {};
tests.firewall = callTest tests/firewall.nix {};
+
tests.fsck = callTest tests/fsck.nix {};
tests.fwupd = callTest tests/fwupd.nix {};
tests.gdk-pixbuf = callTest tests/gdk-pixbuf.nix {};
#tests.gitlab = callTest tests/gitlab.nix {};
+29
nixos/tests/fsck.nix
···
+
import ./make-test.nix {
+
name = "fsck";
+
+
machine = { lib, ... }: {
+
virtualisation.emptyDiskImages = [ 1 ];
+
+
fileSystems = lib.mkVMOverride {
+
"/mnt" = {
+
device = "/dev/vdb";
+
fsType = "ext4";
+
autoFormat = true;
+
};
+
};
+
};
+
+
testScript = ''
+
$machine->waitForUnit('default.target');
+
+
subtest "root fs is fsckd", sub {
+
$machine->succeed('journalctl -b | grep "fsck.ext4.*/dev/vda"');
+
};
+
+
subtest "mnt fs is fsckd", sub {
+
$machine->succeed('journalctl -b | grep "fsck.*/dev/vdb.*clean"');
+
$machine->succeed('grep "Requires=systemd-fsck@dev-vdb.service" /run/systemd/generator/mnt.mount');
+
$machine->succeed('grep "After=systemd-fsck@dev-vdb.service" /run/systemd/generator/mnt.mount');
+
};
+
'';
+
}