1 # systemd-lock-handler {#module-services-systemd-lock-handler}
3 The `systemd-lock-handler` module provides a service that bridges
4 D-Bus events from `logind` to user-level systemd targets:
6 - `lock.target` started by `loginctl lock-session`,
7 - `unlock.target` started by `loginctl unlock-session` and
8 - `sleep.target` started by `systemctl suspend`.
10 You can create a user service that starts with any of these targets.
12 For example, to create a service for `swaylock`:
16 services.systemd-lock-handler.enable = true;
18 systemd.user.services.swaylock = {
19 description = "Screen locker for Wayland";
20 documentation = ["man:swaylock(1)"];
22 # If swaylock exits cleanly, unlock the session:
23 onSuccess = ["unlock.target"];
25 # When lock.target is stopped, stops this too:
26 partOf = ["lock.target"];
28 # Delay lock.target until this service is ready:
29 before = ["lock.target"];
30 wantedBy = ["lock.target"];
33 # systemd will consider this service started when swaylock forks...
36 # ... and swaylock will fork only after it has locked the screen.
37 ExecStart = "${lib.getExe pkgs.swaylock} -f";
39 # If swaylock crashes, always restart it immediately:
40 Restart = "on-failure";
47 See [upstream documentation](https://sr.ht/~whynothugo/systemd-lock-handler) for more information.