Files
nix-stuff/common/nice-config.nix
Shelvacu 61a442dd42 wip nice
2025-01-31 15:45:47 -08:00

173 lines
6.6 KiB
Nix

{
lib,
config,
vacuModuleType,
...
}:
let
nice = config.vacu.nice;
serviceNice = name: { serviceConfig = {
Nice = nice.${name};
X-VacuExplicitNice = true;
}; };
noNice = { serviceConfig.X-VacuExplicitNice = true; };
in
{ imports = [
{
config.vacu.nice = {
oomd = -15;
input = -14;
tty = -13;
sshServer = -12;
adminShell = -11;
adminShellCommand = -10;
udev = -10;
importantServices = -9;
graphicsDM = -8;
graphicsKonsole = -7;
audio = -6;
graphicsLight = -5;
network = -4;
zfs = -3; # the userland stuff, so not super important
peripherals = -2; # interacting with all the incidental/misc parts of the hardware. Battery status, lights, rfkill, thunderbolt ...
database = -1;
default = 0;
shellCommand = 1;
frontproxy = 2;
normalContainer = 3;
graphicsAppHeavy = 4;
bulkContainer = 5;
bulk = 6;
nixbuild = 7;
};
}
(lib.optionalAttrs vacuModuleType == "nixos" {
systemd.services = {
bluetooth = serviceNice "peripherals";
bolt = serviceNice "peripherals";
"console-getty" = serviceNice "tty";
"container@" = serviceNice "normalContainer";
dbus-broker = serviceNice "importantServices";
dbus = serviceNice "importantServices";
display-manager = serviceNice "graphicsDM";
debug-shell = serviceNice "tty";
emergency = serviceNice "tty";
firewall = serviceNice "network";
fwupd = serviceNice "bulk";
"getty@" = serviceNice "tty";
iio-sensor-proxy = serviceNice "peripherals";
interception-tools = serviceNice "input";
kmod-static-nodes = serviceNice "importantServices";
logrotate-checkconf = serviceNice "importantServices";
ModemManager = serviceNice "network";
mount-pstore = serviceNice "importantServices";
network-local-commands = serviceNice "network";
network-setup = serviceNice "network";
NetworkManager-wait-online = serviceNice "network";
NetworkManager = serviceNice "network";
nix-daemon = serviceNice "nixbuild";
nix-gc = serviceNice "nixbuild";
nix-optimise = serviceNice "nixbuild";
nscd = serviceNice "importantService";
openvpn-restart = serviceNice "network";
polkit = serviceNice "importantServices";
postgresql = serviceNice "database";
post-resume = serviceNice "importantServices";
power-profiles-daemon = serviceNice "peripherals";
pre-sleep = serviceNice "importantServices";
prepare-kexec = serviceNice "importantServices";
reload-systemd-vconsole-setup = serviceNice "importantServices";
rescue = serviceNice "importantServices";
resolvconf = serviceNice "network";
rtkit-daemon = serviceNice "importantServices";
save-hwclock = serviceNice "importantServices";
"serial-getty@" = serviceNice "tty";
sshd = serviceNice "sshServer";
suid-sgid-wrappers = serviceNice "importantServices";
systemd-ask-password-console = serviceNice "importantServices";
systemd-ask-password-wall = serviceNice "importantServices";
"systemd-backlight@" = serviceNice "graphicsLight";
systemd-binfmt = serviceNice "importantServices";
systemd-boot-random-seed = serviceNice "importantServices";
"systemd-fsck@" = serviceNice "importantServices";
systemd-hibernate = serviceNice "importantServices";
systemd-hostnamed = serviceNice "importantServices";
systemd-hybrid-sleep = serviceNice "importantServices";
systemd-importd = serviceNice "bulk";
systemd-journal-catalog-update = serviceNice "importantServices";
systemd-journal-flush = serviceNice "importantServices";
systemd-journald = serviceNice "importantServices";
"systemd-journald@" = serviceNice "importantServices";
systemd-kexec = serviceNice "importantServices";
systemd-localed = serviceNice "importantServices";
systemd-logind = serviceNice "tty";
systemd-machined = serviceNice "importantServices";
systemd-modules-load = serviceNice "importantServices";
systemd-oomd = serviceNice "oomd";
systemd-random-seed = serviceNice "importantServices";
systemd-remount-fs = serviceNice "importantServices";
systemd-sysctl = serviceNice "importantServices";
systemd-timesyncd = serviceNice "network";
systemd-tmpfiles-setup-dev-early = serviceNice "importantServices";
systemd-tmpfiles-setup-dev = serviceNice "importantServices";
systemd-tmpfiles-setup = serviceNice "importantServices";
systemd-udev-trigger = serviceNice "udev";
systemd-udevd = serviceNice "udev";
systemd-update-utmp = serviceNice "importantService";
systemd-user-sessions = serviceNice "importantService";
systemd-vconsole-setup = serviceNice "tty";
udisks2 = serviceNice "peripherals";
upower = serviceNice "peripherals";
"user@" = noNice;
"user-runtime-dir@" = serviceNice "importantServices";
waydroid-container = serviceNice "bulk";
wpa_supplicant = serviceNice "network";
zfs-share = serviceNice "zfs";
zfs-zes = serviceNice "zfs";
};
systemd.user.services = {
"app-blueman@" = serviceNice "peripherals";
"app-brave@" = serviceNice "graphicsAppHeavy";
"app-Nextcloud@" = serviceNice "bulk";
"app-nheko@" = serviceNice "graphicsAppHeavy";
"app-obsidian@" = serviceNice "graphicsAppHeavy";
"app-org.kde.dolphin@" = serviceNice "graphicsLight";
"app-org.kde.gwenview@" = serviceNice "graphicsLight";
"app-org.kde.kalendarac@" = serviceNice "graphicsLight";
"app-org.kde.konsole@" = serviceNice "graphicsKonsole";
"app-org.kde.kunifiedpush\\x2ddistributor@" = serviceNice "graphicsLight";
"app-org.kde.xwaylandvideobridge@" = serviceNice "graphicsLight";
"app-signal\\x2ddesktop@" = serviceNice "graphicsAppHeavy";
"app-systemsettings@" = serviceNice "graphicsLight";
"app-thunderbird@" = serviceNice "graphicsAppHeavy";
"at-spi-dbus-bus" = serviceNice "graphicsDM";
"dbus" = serviceNice "graphicsDM";
"dconf" = serviceNice "graphicsDM";
"kde-baloo" = serviceNice "bulk";
"obex" = serviceNice "graphicsLight";
"pipewire-pulse" = serviceNice "audio";
"pipewire" = serviceNice "audio";
"plasma-baloorunner" = serviceNice "graphicsDM";
"plasma-gmenudbusmenuproxy" = serviceNice
};
vacu.shell.initLines = lib.mkBefore ''
if [[ -z "$VACU_DO_RENICE" ]]; then
new_nice="''${VACU_DO_RENICE:-${toString nice.default}}"
renice --priority $new_nice --pid $$ || true
fi
'';
security.pam.loginLimits = [
{
domain = "@${users.groups.wheel.name}";
item = "priority";
value = toString nice.adminShell;
}
{
domain = "root";
item = "priority";
value = toString nice.adminShell;
}
];
})
]