summary refs log tree commit diff
path: root/nixos/modules/services/x11/xautolock.nix
blob: 60ce9e6ed5c0986f03a2ec35aabfc8e6363d3058 (plain) (blame)
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
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.xserver.xautolock;
in
  {
    options = {
      services.xserver.xautolock = {
        enable = mkEnableOption "xautolock";
        enableNotifier = mkEnableOption "xautolock.notify" // {
          description = ''
            Whether to enable the notifier feature of xautolock.
            This publishes a notification before the autolock.
          '';
        };

        time = mkOption {
          default = 15;
          type = types.int;

          description = ''
            Idle time to wait until xautolock locks the computer.
          '';
        };

        locker = mkOption {
          default = "xlock"; # default according to `man xautolock`
          example = "i3lock -i /path/to/img";
          type = types.string;

          description = ''
            The script to use when locking the computer.
          '';
        };

        notify = mkOption {
          default = 10;
          type = types.int;

          description = ''
            Time (in seconds) before the actual lock when the notification about the pending lock should be published.
          '';
        };

        notifier = mkOption {
          default = "notify-send 'Locking in 10 seconds'";
          type = types.string;

          description = ''
            Notification script to be used to warn about the pending autolock.
          '';
        };
      };
    };

    config = mkIf cfg.enable {
      environment.systemPackages = with pkgs; [ xautolock ];

      services.xserver.displayManager.sessionCommands = with builtins; with pkgs; ''
        ${xautolock}/bin/xautolock \
          ${concatStringsSep " \\\n" ([
            "-time ${toString(cfg.time)}"
            "-locker ${cfg.locker}"
          ] ++ optional cfg.enableNotifier (concatStringsSep " " [ 
            "-notify ${toString(cfg.notify)}"
            "-notifier \"${cfg.notifier}\""
          ]))} &
      '';
    };
  }