Skip to content

nixos/users-groups: add user option to enable lingering#260248

Merged
amaxine merged 1 commit intoNixOS:masterfrom
ToxicFrog:linger
Oct 10, 2023
Merged

nixos/users-groups: add user option to enable lingering#260248
amaxine merged 1 commit intoNixOS:masterfrom
ToxicFrog:linger

Conversation

@ToxicFrog
Copy link
Contributor

Description of changes

Adds a new boolean user option, linger, which can be used to enable systemd lingering for individual users.

This is not the same as DontKillUserProcesses=true; (a) it allows configuration per-user rather than per-system and (b) lingering users will have their slice and services start on boot (or on nixos-rebuild) rather than on first login.

Adapted from
https://gist.github.com/graham33/fdbdcc18317a621d9dd54beb36be6683

Fixes #3702

Lingering users can still be managed mutably by root with loginctl, but the settings here will take precedence when nixos-rebuild is run.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Adapted from
https://gist.github.com/graham33/fdbdcc18317a621d9dd54beb36be6683

Fixes NixOS#3702

Lingering users can still be managed mutably by root with `loginctl`,
but the settings here will take precedence when `nixos-rebuild` is run.
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Oct 10, 2023
@ToxicFrog ToxicFrog requested a review from colemickens October 10, 2023 15:44
@delroth delroth added the 12.approvals: 1 This PR was reviewed and approved by one person. label Oct 10, 2023
@ofborg ofborg bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Oct 10, 2023
@amaxine
Copy link
Contributor

amaxine commented Oct 10, 2023

Oh, this is great, thank you!

@amaxine amaxine merged commit f3d84b9 into NixOS:master Oct 10, 2023
@Ralith
Copy link
Contributor

Ralith commented Oct 10, 2023

Should this be enabled by default when isNormalUser is set?

in stringAfter [ "users" ] ''
if [ -e ${lingerDir} ] ; then
cd ${lingerDir}
ls ${lingerDir} | sort | comm -3 -1 ${lingeringUsersFile} - | xargs -r ${pkgs.systemd}/bin/loginctl disable-linger
Copy link
Member

@SuperSandro2000 SuperSandro2000 Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't deactivate lingering for a user after it is was enabled and disabled again, right? It would just flip lingering for all users that have it enabled.

Edit: I didn't immediately catch the comm usage here which reveals another problem: Now we deactivate any lingering for any user that has it manually configured and there is no way to deactivate this. This breaks at least one of my systems which I would need to switch to this setting. Since there is no release not for this change, normally it would went unnoticed.

I think we can only enforce this when users cannot be manually changed, so we would need to rely on users.mutableUsers

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm just a random person that followed the issue where this commit was first introduced, and I may be missing a bunch of things here, but wouldn't relying on mutableUsers in turn break the ability of setting this through configuration.nix for users that aren't mutable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this "break" (i'm using this term very lightly) my system if i remove a user? i'm thinking yes because the update-lingering activation script keeps failing on me - consider

$ sudo loginctl disable-linger someone-who-no-longer-exists                         nix-shell-env
Failed to look up user someone-who-no-longer-exists: No such process

my system works fine if i simply rm the offending file out of /var/lib/systemd/linger

cc @ToxicFrog @SuperSandro2000 @ambroisie

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned in #283769 (comment) i'm considering reverting this PR - would anyone care to comment before i do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enabling persistent user instance systemd

8 participants