diff options
Diffstat (limited to 'nixos/modules/config/zram.nix')
-rw-r--r-- | nixos/modules/config/zram.nix | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/nixos/modules/config/zram.nix b/nixos/modules/config/zram.nix index 4df646cf27966..991387ea9b2bd 100644 --- a/nixos/modules/config/zram.nix +++ b/nixos/modules/config/zram.nix @@ -82,12 +82,30 @@ in {command}`cat /sys/class/block/zram*/comp_algorithm` ''; }; + + writebackDevice = lib.mkOption { + default = null; + example = "/dev/zvol/tarta-zoot/swap-writeback"; + type = lib.types.nullOr lib.types.path; + description = lib.mdDoc '' + Write incompressible pages to this device, + as there's no gain from keeping them in RAM. + ''; + }; }; }; config = lib.mkIf cfg.enable { + assertions = [ + { + assertion = cfg.writebackDevice == null || cfg.swapDevices <= 1; + message = "A single writeback device cannot be shared among multiple zram devices"; + } + ]; + + system.requiredKernelConfig = with config.lib.kernelConfig; [ (isModule "ZRAM") ]; @@ -112,6 +130,8 @@ in zram-size = if cfg.memoryMax != null then "min(${size}, ${toString cfg.memoryMax} / 1024 / 1024)" else size; compression-algorithm = cfg.algorithm; swap-priority = cfg.priority; + } // lib.optionalAttrs (cfg.writebackDevice != null) { + writeback-device = cfg.writebackDevice; }; }) devices)); |