{ config, lib, ... }: let cfg = config.sys.core.memory; in { options.sys.core.memory = { enable = lib.mkEnableOption "memory management"; zram = { enable = lib.mkEnableOption "enables zram compression"; percent = lib.mkOption { type = lib.types.int; default = 25; description = "Percentage of total RAM to use for zram"; }; }; swapfile = { enable = lib.mkEnableOption "enables a swapfile"; size = lib.mkOption { type = lib.types.int; default = 8192; description = "Size of the swapfile in gigabytes"; }; }; }; config = lib.mkIf cfg.enable (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; } ]; }) ]); }