From 8558d7b1ceb604b4e91b17281f2efbbad5ba47a1 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Sat, 2 Mar 2024 12:40:16 -0600 Subject: 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. --- nixos/modules/config/users-groups.nix | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'nixos') diff --git a/nixos/modules/config/users-groups.nix b/nixos/modules/config/users-groups.nix index dd34771c0b42b..02cd1a17f538a 100644 --- a/nixos/modules/config/users-groups.nix +++ b/nixos/modules/config/users-groups.nix @@ -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 -- cgit 1.4.1