From bb2f0dcd295616b1536aa27c2da2e4db561b2f00 Mon Sep 17 00:00:00 2001 From: hektor Date: Sat, 24 Oct 2026 12:38:41 +0200 Subject: [PATCH] feat(memory): declare 'memory' module --- hosts/andromache/default.nix | 3 +-- hosts/astyanax/default.nix | 7 ++++--- modules/common/embedded.nix | 6 ++---- modules/memory/default.nix | 19 +++++++++++++++++++ modules/memory/oom.nix | 7 +++++++ modules/memory/zram.nix | 11 +++++++++++ 6 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 modules/memory/default.nix create mode 100644 modules/memory/oom.nix create mode 100644 modules/memory/zram.nix diff --git a/hosts/andromache/default.nix b/hosts/andromache/default.nix index 1cc7d18..2a628c1 100644 --- a/hosts/andromache/default.nix +++ b/hosts/andromache/default.nix @@ -44,6 +44,7 @@ in }; keyboard.enable = true; localization.enable = true; + memory.zram.enable = true; my = { fonts.enable = true; stylix.enable = true; @@ -121,6 +122,4 @@ in enable = true; package = pkgs.plocate; }; - - zramSwap.enable = true; } diff --git a/hosts/astyanax/default.nix b/hosts/astyanax/default.nix index 8867fe4..c558822 100644 --- a/hosts/astyanax/default.nix +++ b/hosts/astyanax/default.nix @@ -42,6 +42,10 @@ in }; keyboard.enable = true; localization.enable = true; + memory = { + oom.enable = true; + zram.enable = true; + }; my = { fonts.enable = true; stylix.enable = true; @@ -126,7 +130,4 @@ in }; }; }; - - zramSwap.enable = true; - systemd.oomd.enableUserSlices = true; } diff --git a/modules/common/embedded.nix b/modules/common/embedded.nix index 3f66f7a..520738d 100644 --- a/modules/common/embedded.nix +++ b/modules/common/embedded.nix @@ -5,10 +5,8 @@ system.autoUpgrade.enable = false; nix.settings.max-jobs = 0; - zramSwap = { - enable = true; - memoryPercent = 100; - }; + memory.zram.enable = true; + zramSwap.memoryPercent = 100; services.journald.settings.Journal.SystemMaxUse = "100M"; }; diff --git a/modules/memory/default.nix b/modules/memory/default.nix new file mode 100644 index 0000000..32334f0 --- /dev/null +++ b/modules/memory/default.nix @@ -0,0 +1,19 @@ +{ lib, ... }: + +{ + imports = [ + ./oom.nix + ./zram.nix + ]; + + options.memory = { + oom.enable = lib.mkOption { + default = false; + type = lib.types.bool; + }; + zram.enable = lib.mkOption { + default = false; + type = lib.types.bool; + }; + }; +} diff --git a/modules/memory/oom.nix b/modules/memory/oom.nix new file mode 100644 index 0000000..e4871f5 --- /dev/null +++ b/modules/memory/oom.nix @@ -0,0 +1,7 @@ +{ config, lib, ... }: + +{ + config = lib.mkIf config.memory.oom.enable { + systemd.oomd.enableUserSlices = lib.mkDefault true; + }; +} diff --git a/modules/memory/zram.nix b/modules/memory/zram.nix new file mode 100644 index 0000000..9ab8305 --- /dev/null +++ b/modules/memory/zram.nix @@ -0,0 +1,11 @@ +{ config, lib, ... }: + +{ + config = lib.mkIf config.memory.zram.enable { + zramSwap.enable = true; + boot.kernel.sysctl = { + "vm.swappiness" = lib.mkDefault 180; + "vm.page-cluster" = lib.mkDefault 0; + }; + }; +}