From 1bee79f9f7c4a66ac144944f72a02c2e14bd931b Mon Sep 17 00:00:00 2001 From: Ramses Date: Thu, 13 Jul 2023 17:12:54 +0200 Subject: nixos/swap: make sure all kernel modules are loaded before creating swap devices. (#239163) Co-authored-by: iliana etaoin --- nixos/modules/config/swap.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nixos/modules/config/swap.nix b/nixos/modules/config/swap.nix index 0a7e45bffb2..8989a640826 100644 --- a/nixos/modules/config/swap.nix +++ b/nixos/modules/config/swap.nix @@ -252,6 +252,11 @@ in 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 ] -- cgit 1.4.1