Unverified Commit 2af1ee5b authored by Will Fancher's avatar Will Fancher Committed by GitHub
Browse files

Merge pull request #259196 from liff/mod/systemd-lock-handler

nixos/systemd-lock-handler: init with corresponding package at 2.4.2
parents 0e03f6a2 e103c5cf
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -67,6 +67,8 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m

- [RustDesk](https://rustdesk.com), a full-featured open source remote control alternative for self-hosting and security with minimal configuration. Alternative to TeamViewer.

- [systemd-lock-handler](https://git.sr.ht/~whynothugo/systemd-lock-handler/), a bridge between logind D-Bus events and systemd targets. Available as [services.systemd-lock-handler.enable](#opt-services.systemd-lock-handler.enable).

## Backward Incompatibilities {#sec-release-24.05-incompatibilities}

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
+1 −0
Original line number Diff line number Diff line
@@ -1236,6 +1236,7 @@
  ./services/system/saslauthd.nix
  ./services/system/self-deploy.nix
  ./services/system/systembus-notify.nix
  ./services/system/systemd-lock-handler.nix
  ./services/system/uptimed.nix
  ./services/system/zram-generator.nix
  ./services/torrent/deluge.nix
+47 −0
Original line number Diff line number Diff line
# systemd-lock-handler {#module-services-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 by `loginctl lock-session`,
  - `unlock.target` started by `loginctl unlock-session` and
  - `sleep.target` started by `systemctl suspend`.

You can create a user service that starts with any of these targets.

For example, to create a service for `swaylock`:

```nix
{
  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](https://sr.ht/~whynothugo/systemd-lock-handler) for more information.
+27 −0
Original line number Diff line number Diff line
{ config
, pkgs
, lib
, ...
}:
let
  cfg = config.services.systemd-lock-handler;
  inherit (lib) mkIf mkEnableOption mkPackageOption;
in
{
  options.services.systemd-lock-handler = {
    enable = mkEnableOption (lib.mdDoc "systemd-lock-handler");
    package = mkPackageOption pkgs "systemd-lock-handler" { };
  };

  config = mkIf cfg.enable {
    systemd.packages = [ cfg.package ];

    # https://github.com/NixOS/nixpkgs/issues/81138
    systemd.user.services.systemd-lock-handler.wantedBy = [ "default.target" ];
  };

  meta = {
    maintainers = with lib.maintainers; [ liff ];
    doc = ./systemd-lock-handler.md;
  };
}
+1 −0
Original line number Diff line number Diff line
@@ -856,6 +856,7 @@ in {
  systemd-journal = handleTest ./systemd-journal.nix {};
  systemd-journal-gateway = handleTest ./systemd-journal-gateway.nix {};
  systemd-journal-upload = handleTest ./systemd-journal-upload.nix {};
  systemd-lock-handler = runTestOn ["aarch64-linux" "x86_64-linux"] ./systemd-lock-handler.nix;
  systemd-machinectl = handleTest ./systemd-machinectl.nix {};
  systemd-networkd = handleTest ./systemd-networkd.nix {};
  systemd-networkd-dhcpserver = handleTest ./systemd-networkd-dhcpserver.nix {};
Loading