aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/services/screen-locker.nix
blob: 30591a7d1a546572cb4cfb5a78b4632643fa6d74 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.services.screen-locker;

in {

  options.services.screen-locker = {
    enable = mkEnableOption "screen locker for X session";

    lockCmd = mkOption {
      type = types.str;
      description = "Locker command to run.";
      example = "\${pkgs.i3lock}/bin/i3lock -n -c 000000";
    };

    inactiveInterval = mkOption {
      type = types.int;
      default = 10;
      description = ''
        Inactive time interval in minutes after which session will be locked.
        The minimum is 1 minute, and the maximum is 1 hour.
        See <link xlink:href="https://linux.die.net/man/1/xautolock"/>.
      '';
    };

    xautolockExtraOptions = mkOption {
      type = types.listOf types.str;
      default = [ ];
      description = ''
        Extra command-line arguments to pass to <command>xautolock</command>.
      '';
    };

    xssLockExtraOptions = mkOption {
      type = types.listOf types.str;
      default = [ ];
      description = ''
        Extra command-line arguments to pass to <command>xss-lock</command>.
      '';
    };

  };

  config = mkIf cfg.enable {
    systemd.user.services.xautolock-session = {
      Unit = {
        Description = "xautolock, session locker service";
        After = [ "graphical-session-pre.target" ];
        PartOf = [ "graphical-session.target" ];
      };

      Install = { WantedBy = [ "graphical-session.target" ]; };

      Service = {
        ExecStart = concatStringsSep " " ([
          "${pkgs.xautolock}/bin/xautolock"
          "-detectsleep"
          "-time ${toString cfg.inactiveInterval}"
          "-locker '${pkgs.systemd}/bin/loginctl lock-session $XDG_SESSION_ID'"
        ] ++ cfg.xautolockExtraOptions);
      };
    };

    systemd.user.services.xss-lock = {
      Unit = {
        Description = "xss-lock, session locker service";
        After = [ "graphical-session-pre.target" ];
        PartOf = [ "graphical-session.target" ];
      };

      Install = { WantedBy = [ "graphical-session.target" ]; };

      Service = {
        ExecStart = concatStringsSep " "
          ([ "${pkgs.xss-lock}/bin/xss-lock" "-s \${XDG_SESSION_ID}" ]
            ++ cfg.xssLockExtraOptions ++ [ "-- ${cfg.lockCmd}" ]);
      };
    };
  };

}