systemd: fix the timeout for the user service manager

This commit is contained in:
Colin 2024-02-22 00:24:05 +00:00
parent 473999c001
commit f27f994090

View File

@ -1,13 +1,13 @@
{ ... }:
{ pkgs, ... }:
{
systemd.extraConfig = ''
# DefaultTimeoutStopSec defaults to 90s, and frequently blocks overall system shutdown.
DefaultTimeoutStopSec=25
DefaultTimeoutStopSec=20
'';
systemd.user.extraConfig = ''
# DefaultTimeoutStopSec defaults to 90s, and frequently blocks overall system shutdown.
DefaultTimeoutStopSec=25
DefaultTimeoutStopSec=20
'';
services.journald.extraConfig = ''
@ -18,6 +18,41 @@
Compress=no
'';
# decreasing the timeout for the manager itself ("Stop job is running for User Manager for UID 1000").
# TimeoutStopSec gets stripped from .override file for `user@`, so can't do it that way:
# systemd.services."user@".serviceConfig.TimeoutStopSec = "20s";
# adding just TimeoutStopSec to `user@1000` causes it to lose all the other fields, including `ExecStart`:
# systemd.services."user@1000".serviceConfig.TimeoutStopSec = "20s";
# so, just recreate the whole damn service as it appears with `systemd cat 'user@1000'`
# and modify the parts i care about.
systemd.services."user@1000" = {
description = "User Manager for UID %i";
documentation = [ "man:user@service(5)" ];
after = [
"user-runtime-dir@%i.service"
"dbus.service"
"systemd-oomd.service"
];
requires = [ "user-runtime-dir@%i.service" ];
unitConfig.ignoreOnIsolate = true;
serviceConfig = {
User = "%i";
PAMName = "systemd-user";
Type = "notify-reload";
ExecStart = "${pkgs.systemd}/lib/systemd/systemd --user";
Slice = "user-%i.slice";
KillMode = "mixed";
Delegate = [ "pids" "memory" "cpu" ];
DelegateSubgroup = "init.scope";
TasksMax = "infinity";
TimeoutStopSec = "20s"; #< default: 120s
KeyringMode = "inherit";
OOMScoreAdjust = 100;
MemoryPressureWatch = "skip";
};
};
# allow ordinary users to `reboot` or `shutdown`.
# source: <https://nixos.wiki/wiki/Polkit>
security.polkit.extraConfig = ''