diff options
author | maxine <35892750+amaxine@users.noreply.github.com> | 2023-10-10 20:08:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-10 20:08:27 +0200 |
commit | f3d84b91e9f33651532ad792083da5206d78732a (patch) | |
tree | 1acf3ad74f102c9520b762870fd3658c19b9ec03 /nixos/modules | |
parent | 5323fbf70331f8a7c47f1b4f49841cf74507f77f (diff) | |
parent | e648d4646589c380ff3a9fb57824eacef1cee412 (diff) | |
download | nixlib-f3d84b91e9f33651532ad792083da5206d78732a.tar nixlib-f3d84b91e9f33651532ad792083da5206d78732a.tar.gz nixlib-f3d84b91e9f33651532ad792083da5206d78732a.tar.bz2 nixlib-f3d84b91e9f33651532ad792083da5206d78732a.tar.lz nixlib-f3d84b91e9f33651532ad792083da5206d78732a.tar.xz nixlib-f3d84b91e9f33651532ad792083da5206d78732a.tar.zst nixlib-f3d84b91e9f33651532ad792083da5206d78732a.zip |
Merge pull request #260248 from ToxicFrog/linger
nixos/users-groups: add user option to enable lingering
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/config/users-groups.nix | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/nixos/modules/config/users-groups.nix b/nixos/modules/config/users-groups.nix index f11a1f82fc2c..f6e063ccdbad 100644 --- a/nixos/modules/config/users-groups.nix +++ b/nixos/modules/config/users-groups.nix @@ -330,6 +330,20 @@ let administrator before being able to use the system again. ''; }; + + linger = mkOption { + type = types.bool; + default = false; + description = lib.mdDoc '' + Whether to enable lingering for this user. If true, systemd user + units will start at boot, rather than starting at login and stopping + at logout. This is the declarative equivalent of running + `loginctl enable-linger` for this user. + + If false, user units will not be started until the user logs in, and + may be stopped on logout depending on the settings in `logind.conf`. + ''; + }; }; config = mkMerge @@ -663,6 +677,20 @@ in { ''; }; + system.activationScripts.update-lingering = let + lingerDir = "/var/lib/systemd/linger"; + lingeringUsers = map (u: u.name) (attrValues (flip filterAttrs cfg.users (n: u: u.linger))); + lingeringUsersFile = builtins.toFile "lingering-users" + (concatStrings (map (s: "${s}\n") + (sort (a: b: a < b) lingeringUsers))); # this sorting is important for `comm` to work correctly + in stringAfter [ "users" ] '' + if [ -e ${lingerDir} ] ; then + cd ${lingerDir} + 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 + ''; + # Warn about user accounts with deprecated password hashing schemes system.activationScripts.hashes = { deps = [ "users" ]; |