nixos/users-groups: Fix the update-lingering activation script failing

The update-lingering activation script currently fails during rebuilds.
This happens when removing a user with linger enabled.
The call to loginctl disable-linger runs for the non-existent user.
This returns an error code which causes the failure.

To mitigate this, this PR removes any residual linger files.
These are files named for the user in /var/lib/systemd/linger.
A simple check for user existence determines whether to delete the file.
This happens before the call to disable-linger to avoid any errors.

Fixes #283769.
This commit is contained in:
Jordan Williams 2024-03-02 12:40:16 -06:00
parent 9c8cdfde17
commit 8558d7b1ce
No known key found for this signature in database
GPG Key ID: 9FB42B0E7F657D8C

View File

@ -704,6 +704,11 @@ in {
in stringAfter [ "users" ] ''
if [ -e ${lingerDir} ] ; then
cd ${lingerDir}
for user in ${lingerDir}/*; do
if ! id "$user" >/dev/null 2>&1; then
rm --force -- "$user"
fi
done
ls ${lingerDir} | sort | comm -3 -1 ${lingeringUsersFile} - | xargs -r ${pkgs.systemd}/bin/loginctl disable-linger
ls ${lingerDir} | sort | comm -3 -2 ${lingeringUsersFile} - | xargs -r ${pkgs.systemd}/bin/loginctl enable-linger
fi