diff options
| author | Franck Cuny <franck@fcuny.net> | 2025-09-12 13:11:20 -0700 |
|---|---|---|
| committer | Franck Cuny <franck@fcuny.net> | 2025-09-12 13:55:09 -0700 |
| commit | 2fea36c19eb904125e2db5ba230b28d72dc881db (patch) | |
| tree | 4233e16f0d50aec1cd5e4d3e5f5ed1b8728e380c /modules/nixos/cgroups.nix | |
| parent | move common modules together and simplify imports (diff) | |
| download | infra-2fea36c19eb904125e2db5ba230b28d72dc881db.tar.gz | |
start to refactor nixos modules
Diffstat (limited to 'modules/nixos/cgroups.nix')
| -rw-r--r-- | modules/nixos/cgroups.nix | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/modules/nixos/cgroups.nix b/modules/nixos/cgroups.nix new file mode 100644 index 0000000..07dc964 --- /dev/null +++ b/modules/nixos/cgroups.nix @@ -0,0 +1,75 @@ +# Stolen from https://git.lix.systems/the-distro/infra/src/branch/main/common/cgroups.nix +# Relatively inspired by fbtax2: +# https://facebookmicrosites.github.io/cgroup2/docs/fbtax-results.html +{ ... }: +let + systemCriticalSliceConfig = { + ManagedOOMMemoryPressure = "kill"; + + # guarantee availability of memory + MemoryMin = "192M"; + # default 100 + IOWeight = 1000; + # default 100 + CPUWeight = 1000; + }; +in +{ + systemd.oomd = { + enable = true; + enableRootSlice = true; + enableSystemSlice = true; + enableUserSlices = true; + }; + + systemd.services.nix-daemon = { + serviceConfig = { + CPUWeight = 10; + IOWeight = 10; + }; + }; + + systemd.slices.hostcritical = { + description = "Ensures that services to keep the system alive remain alive"; + + unitConfig = { + # required to avoid a dependency cycle on systemd-oomd. systemd will + # actually guess this right but we should fix it anyway. + DefaultDependencies = false; + }; + + sliceConfig = systemCriticalSliceConfig; + }; + + # make root logins higher priority for resources + systemd.slices."user-0" = { + sliceConfig = systemCriticalSliceConfig; + }; + + systemd.slices.system = { + sliceConfig = { + ManagedOOMMemoryPressure = "kill"; + ManagedOOMMemoryPressureLimit = "50%"; + + IOWeight = 100; + }; + }; + + systemd.services.sshd = { + serviceConfig = { + Slice = "hostcritical.slice"; + }; + }; + + systemd.services.systemd-oomd = { + serviceConfig = { + Slice = "hostcritical.slice"; + }; + }; + + systemd.services.systemd-journald = { + serviceConfig = { + Slice = "hostcritical.slice"; + }; + }; +} |
