{ config, lib, ... }: let cfg = config.sys.core.memory; in { options.sys.core.memory = { zram = { enable = lib.mkEnableOption "enables zram compression"; percent = lib.mkOption { type = lib.types.int; default = 25; }; }; swapfile = { enable = lib.mkEnableOption "enables a swapfile"; size = lib.mkOption { type = lib.types.int; default = 8; }; }; }; config = lib.mkMerge [ (lib.mkIf cfg.zram.enable { zramSwap = { enable = true; algorithm = "zstd"; memoryPercent = cfg.zram.percent; priority = 100; }; }) (lib.mkIf cfg.swapfile.enable { swapDevices = [ { device = "/.swapvol/swapfile"; size = cfg.swapfile.size * 1024; priority = 0; } ]; }) ]; }