I have started using the systemd “user lingering” feature on one of my NixOS systems, and I would like to add a NixOS option for controlling this functionality. From the
loginctl(1) man page:
enable-linger [USER...], disable-linger [USER...]
Enable/disable user lingering for one or more users. If enabled for a specific user, a user manager is spawned for the user at boot and kept around after logouts. This allows users who are not logged in to run long-running services. Takes one or more user names or numeric UIDs as argument. If no argument is specified, enables/disables lingering for the user of the session of the caller.
Enabling this this simply creates an empty file at
I think the option belongs either in
users.users.<name> as a boolean attribute, or in
systemd.users as a list of usernames. As far as I can tell, there are no systemd-related options under
systemd.users seems the more appropriate place. I would like to get some feedback before opening a pull request to implement the option.
Out of curiosity, what is the use-case here?
The system is a headless server, and this allows users to have Syncthing (installed via home-manager) running when not logged in.
If it’s a headless server without any interactive users, can’t you run syncthing using the nixos module instead?
There are interactive users, and Syncthing is designed to be run as a normal user if you want multi-user support.
If you don’t have enough feedback, consider pinging the people listed as maintainers of the package you intend to contribute to. The maintainers are in the package files somewhere.
It’s not super elegant, but you can simply do
# Enable linger for some user
systemd.tmpfiles.rules = [
Linger is important for running Docker services in rootless mode. Otherwise you need a logged-in user session for the containers to stay up, which is not ideal for network services that are supposed to be persistent.
zigbee2mqtt in a container, but no lingering is needed for that.
podman runs in a regular systemd system unit with
DynamicUser = yes set.
Possibly, I haven’t figured out the incantations needed to get docker compose into a NixOS systemd unit. But linger worked for my purposes.
I haven’t had a need for docker/podman-compose, so I can’t really say anything about that, but you can configure containers through
virtualisation.oci-containers which is what I do for
zigbee2mqtt. Very straight-forward.