summaryrefslogtreecommitdiff
path: root/os/core/memory.nix
blob: b20ec8ac08757a2079224ec6d3f0320508576576 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{ config, lib, ... }:
let
  cfg = config.os.core.memory;
in
{
  options.os.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;
      } ];
    })
  ];
}