nixos/swap: make sure all kernel modules are loaded before creating swap devices. (#239163)

Co-authored-by: iliana etaoin <iliana@buttslol.net>

Ramses 1bee79f9 6e793842

Changed files
+5
nixos
modules
config
+5
nixos/modules/config/swap.nix
···
let realDevice' = escapeSystemdPath sw.realDevice;
in nameValuePair "mkswap-${sw.deviceName}"
{ description = "Initialisation of swap device ${sw.device}";
+
# The mkswap service fails for file-backed swap devices if the
+
# loop module has not been loaded before the service runs.
+
# We add an ordering constraint to run after systemd-modules-load to
+
# avoid this race condition.
+
after = [ "systemd-modules-load.service" ];
wantedBy = [ "${realDevice'}.swap" ];
before = [ "${realDevice'}.swap" ];
path = [ pkgs.util-linux pkgs.e2fsprogs ]