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