diff --git a/nixos/modules/services/system/zram-generator.nix b/nixos/modules/services/system/zram-generator.nix index 7eb3fdda46d3..afdb8d86e831 100644 --- a/nixos/modules/services/system/zram-generator.nix +++ b/nixos/modules/services/system/zram-generator.nix @@ -36,7 +36,18 @@ in ]; systemd.packages = [ cfg.package ]; - systemd.services."systemd-zram-setup@".path = [ pkgs.util-linux ]; # for mkswap + systemd.services."systemd-zram-setup@" = { + path = [ pkgs.util-linux ]; # for mkswap + # Restart on switch does swapoff -> reset -> reconfigure -> swapon. + # Besides risking OOM when swap is in use, the reset races with udev + # still holding /dev/zramN open after swapoff: the kernel rejects the + # reset with EBUSY (disk_openers > 0), the device stays initialized, + # and the following ExecStart fails to write comp_algorithm/disksize + # (systemd/zram-generator#226). The unit only "changes" due to store + # path churn, so keep the device across switches; real config changes + # need a reboot or manual restart. + restartIfChanged = false; + }; environment.etc."systemd/zram-generator.conf".source = settingsFormat.generate "zram-generator.conf" cfg.settings;