summaryrefslogtreecommitdiffstats
path: root/nixos/modules/programs/xss-lock.nix
blob: f5130f1a98e6dabde2161941d11d601adc03c2d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
  config,
  pkgs,
  lib,
  ...
}:

let
  cfg = config.programs.xss-lock;
in
{
  options.programs.xss-lock = {
    enable = lib.mkEnableOption "xss-lock";

    lockerCommand = lib.mkOption {
      default = "${pkgs.i3lock}/bin/i3lock";
      defaultText = lib.literalExpression ''"''${pkgs.i3lock}/bin/i3lock"'';
      example = lib.literalExpression ''"''${pkgs.i3lock-fancy}/bin/i3lock-fancy"'';
      type = lib.types.separatedString " ";
      description = "Locker to be used with xsslock";
    };

    extraOptions = lib.mkOption {
      default = [ ];
      example = [ "--ignore-sleep" ];
      type = lib.types.listOf lib.types.str;
      description = ''
        Additional command-line arguments to pass to
        {command}`xss-lock`.
      '';
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.user.services.xss-lock = {
      description = "XSS Lock Daemon";
      wantedBy = [ "graphical-session.target" ];
      partOf = [ "graphical-session.target" ];
      serviceConfig.ExecStart = builtins.concatStringsSep " " (
        [
          "${pkgs.xss-lock}/bin/xss-lock"
          "--session \${XDG_SESSION_ID}"
        ]
        ++ (map lib.escapeShellArg cfg.extraOptions)
        ++ [
          "--"
          cfg.lockerCommand
        ]
      );
      serviceConfig.Restart = "always";
    };
  };
}