1.4 KiB
1.4 KiB
systemd-lock-handler
The systemd-lock-handler
module provides a service that bridges
D-Bus events from logind
to user-level systemd targets:
lock.target
started byloginctl lock-session
,unlock.target
started byloginctl unlock-session
andsleep.target
started bysystemctl suspend
.
You can create a user service that starts with any of these targets.
For example, to create a service for swaylock
:
{
services.systemd-lock-handler.enable = true;
systemd.user.services.swaylock = {
description = "Screen locker for Wayland";
documentation = [ "man:swaylock(1)" ];
# If swaylock exits cleanly, unlock the session:
onSuccess = [ "unlock.target" ];
# When lock.target is stopped, stops this too:
partOf = [ "lock.target" ];
# Delay lock.target until this service is ready:
before = [ "lock.target" ];
wantedBy = [ "lock.target" ];
serviceConfig = {
# systemd will consider this service started when swaylock forks...
Type = "forking";
# ... and swaylock will fork only after it has locked the screen.
ExecStart = "${lib.getExe pkgs.swaylock} -f";
# If swaylock crashes, always restart it immediately:
Restart = "on-failure";
RestartSec = 0;
};
};
}
See upstream documentation for more information.