about summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorJordan Williams <jordan@jwillikers.com>2024-03-02 12:40:16 -0600
committerJordan Williams <jordan@jwillikers.com>2024-03-03 12:00:25 -0600
commit8558d7b1ceb604b4e91b17281f2efbbad5ba47a1 (patch)
tree08f5b92b895c980b7b4b90af8aabefdc71479cbc /nixos/modules
parent9c8cdfde17d675c9bb3975d0a0bca26bdbbe6683 (diff)
downloadnixlib-8558d7b1ceb604b4e91b17281f2efbbad5ba47a1.tar
nixlib-8558d7b1ceb604b4e91b17281f2efbbad5ba47a1.tar.gz
nixlib-8558d7b1ceb604b4e91b17281f2efbbad5ba47a1.tar.bz2
nixlib-8558d7b1ceb604b4e91b17281f2efbbad5ba47a1.tar.lz
nixlib-8558d7b1ceb604b4e91b17281f2efbbad5ba47a1.tar.xz
nixlib-8558d7b1ceb604b4e91b17281f2efbbad5ba47a1.tar.zst
nixlib-8558d7b1ceb604b4e91b17281f2efbbad5ba47a1.zip
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.
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/config/users-groups.nix5
1 files changed, 5 insertions, 0 deletions
diff --git a/nixos/modules/config/users-groups.nix b/nixos/modules/config/users-groups.nix
index dd34771c0b42..02cd1a17f538 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