aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/nixos/modules/config/zram.nix
diff options
context:
space:
mode:
Diffstat (limited to 'infra/libkookie/nixpkgs/nixos/modules/config/zram.nix')
-rw-r--r--infra/libkookie/nixpkgs/nixos/modules/config/zram.nix20
1 files changed, 17 insertions, 3 deletions
diff --git a/infra/libkookie/nixpkgs/nixos/modules/config/zram.nix b/infra/libkookie/nixpkgs/nixos/modules/config/zram.nix
index 5e9870bf6b1c..1f513b7e4dae 100644
--- a/infra/libkookie/nixpkgs/nixos/modules/config/zram.nix
+++ b/infra/libkookie/nixpkgs/nixos/modules/config/zram.nix
@@ -80,6 +80,15 @@ in
'';
};
+ memoryMax = mkOption {
+ default = null;
+ type = with types; nullOr int;
+ description = ''
+ Maximum total amount of memory (in bytes) that can be used by the zram
+ swap devices.
+ '';
+ };
+
priority = mkOption {
default = 5;
type = types.int;
@@ -146,11 +155,16 @@ in
# Calculate memory to use for zram
mem=$(${pkgs.gawk}/bin/awk '/MemTotal: / {
- print int($2*${toString cfg.memoryPercent}/100.0/${toString devicesCount}*1024)
+ value=int($2*${toString cfg.memoryPercent}/100.0/${toString devicesCount}*1024);
+ ${lib.optionalString (cfg.memoryMax != null) ''
+ memory_max=int(${toString cfg.memoryMax}/${toString devicesCount});
+ if (value > memory_max) { value = memory_max }
+ ''}
+ print value
}' /proc/meminfo)
- ${pkgs.utillinux}/sbin/zramctl --size $mem --algorithm ${cfg.algorithm} /dev/${dev}
- ${pkgs.utillinux}/sbin/mkswap /dev/${dev}
+ ${pkgs.util-linux}/sbin/zramctl --size $mem --algorithm ${cfg.algorithm} /dev/${dev}
+ ${pkgs.util-linux}/sbin/mkswap /dev/${dev}
'';
restartIfChanged = false;
};