{ config, lib, ... }: let cfg = config.my.zram; in { options.my.zram = { enable = lib.mkEnableOption null // { default = !config.my.fs.swapPartition; }; writebackDevice = lib.mkOption { default = null; type = with lib.types; nullOr path; }; }; config = lib.mkIf cfg.enable { zramSwap = { enable = true; algorithm = "zstd"; memoryPercent = 90; inherit (cfg) writebackDevice; }; boot.kernel.sysctl = { "vm.swappiness" = 180; "vm.watermark_boost_factor" = 0; "vm.watermark_scale_factor" = 125; "vm.page-cluster" = 1; }; }; }