4 cfg = config.systemd.oomd;
9 (lib.mkRenamedOptionModule
10 [ "systemd" "oomd" "enableUserServices" ]
11 [ "systemd" "oomd" "enableUserSlices" ]
15 options.systemd.oomd = {
16 enable = lib.mkEnableOption "the `systemd-oomd` OOM killer" // {
20 # Fedora enables the first and third option by default. See the 10-oomd-* files here:
21 # https://src.fedoraproject.org/rpms/systemd/tree/806c95e1c70af18f81d499b24cd7acfa4c36ffd6
22 enableRootSlice = lib.mkEnableOption "oomd on the root slice (`-.slice`)";
23 enableSystemSlice = lib.mkEnableOption "oomd on the system slice (`system.slice`)";
24 enableUserSlices = lib.mkEnableOption "oomd on all user slices (`user@.slice`) and all user owned slices";
26 extraConfig = lib.mkOption {
35 example = lib.literalExpression ''{ DefaultMemoryPressureDurationSec = "20s"; }'';
37 Extra config options for `systemd-oomd`. See {command}`man oomd.conf`
38 for available options.
43 config = lib.mkIf cfg.enable {
44 systemd.additionalUpstreamSystemUnits = [
45 "systemd-oomd.service"
48 systemd.services.systemd-oomd.wantedBy = [ "multi-user.target" ];
50 environment.etc."systemd/oomd.conf".text = lib.generators.toINI { } {
51 OOM = cfg.extraConfig;
54 systemd.oomd.extraConfig.DefaultMemoryPressureDurationSec = lib.mkDefault "20s"; # Fedora default
56 users.users.systemd-oom = {
57 description = "systemd-oomd service user";
58 group = "systemd-oom";
61 users.groups.systemd-oom = { };
63 systemd.slices."-".sliceConfig = lib.mkIf cfg.enableRootSlice {
64 ManagedOOMMemoryPressure = "kill";
65 ManagedOOMMemoryPressureLimit = lib.mkDefault "80%";
67 systemd.slices."system".sliceConfig = lib.mkIf cfg.enableSystemSlice {
68 ManagedOOMMemoryPressure = "kill";
69 ManagedOOMMemoryPressureLimit = lib.mkDefault "80%";
71 systemd.slices."user-".sliceConfig = lib.mkIf cfg.enableUserSlices {
72 ManagedOOMMemoryPressure = "kill";
73 ManagedOOMMemoryPressureLimit = lib.mkDefault "80%";
75 systemd.user.units."slice" = lib.mkIf cfg.enableUserSlices {
78 ManagedOOMMemoryPressure=kill
79 ManagedOOMMemoryPressureLimit=80%
81 overrideStrategy = "asDropin";