commit 7fa2370ddf90e14a507486487359f522efb514e2
parent 67a9c8c71126edde5601533ba7ce37c73d5664ba
Author: Katja (ctucx) <git@ctu.cx>
Date: Mon, 19 May 2025 13:26:40 +0200
parent 67a9c8c71126edde5601533ba7ce37c73d5664ba
Author: Katja (ctucx) <git@ctu.cx>
Date: Mon, 19 May 2025 13:26:40 +0200
config/nixos/modules/services: add earlyoom
2 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/config/nixos/modules/presets/base.nix b/config/nixos/modules/presets/base.nix @@ -61,6 +61,13 @@ in networking = lib.mkDefault true; }; + services = { + earlyoom = { + avoid = [ "init" ]; + prefer = [ "nix" ]; + }; + }; + programs = { shellUtilities.enable = lib.mkDefault true; systemUtilities.enable = lib.mkDefault true;
diff --git a/config/nixos/modules/services/earlyoom.nix b/config/nixos/modules/services/earlyoom.nix @@ -0,0 +1,41 @@ +{ + povSelf, + config, + lib, + ... +}: +let + inherit (lib) types; + cfg = lib.getAttrFromPath povSelf config; + +in +{ + + options = { + enable = { + type = types.bool; + default = false; + }; + avoid = { + type = types.listOf types.str; + default = [ ]; + }; + prefer = { + type = types.listOf types.str; + default = [ ]; + }; + }; + + config = lib.mkIf cfg.enable { + services.earlyoom = { + enable = true; + enableNotifications = true; + extraArgs = [ + "--ignore-root-user" + (lib.mkIf (cfg.avoid != [ ]) "--avoid '(^|/)(${lib.concatStringsSep "|" cfg.avoid})$'") + (lib.mkIf (cfg.prefer != [ ]) "--avoid '(^|/)(${lib.concatStringsSep "|" cfg.prefer})$'") + ]; + }; + }; + +}