linger-users: use systemd directory options

Using systemd properties avoids the need for manually running mkdir and
cd commands, and helps systemd clean up properly when appropriate.

Suggested-By: Grimmauld <grimmauld@grimmauld.de>
This commit is contained in:
Adam Dinwoodie
2025-11-08 17:49:47 +00:00
parent ac476b9cbc
commit e3cb0fe2ca

View File

@@ -899,7 +899,6 @@ in
script =
let
lingerDir = "/var/lib/systemd/linger";
userPartition = lib.lists.partition (u: u.linger) (builtins.attrValues cfg.users);
lingeringUserNames = map (u: u.name) userPartition.right;
nonLingeringUserNames = map (u: u.name) userPartition.wrong;
@@ -915,8 +914,6 @@ in
id "$1" >/dev/null
}
mkdir -vp ${lingerDir}
cd ${lingerDir}
shopt -s dotglob nullglob
for user in *; do
if ! user_configured "$user"; then
@@ -934,7 +931,11 @@ in
fi
'';
serviceConfig.Type = "oneshot";
serviceConfig = {
Type = "oneshot";
StateDirectory = "systemd/linger";
WorkingDirectory = "/var/lib/systemd/linger";
};
};
# Warn about user accounts with deprecated password hashing schemes