1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.xserver.xautolock;
7in
8 {
9 options = {
10 services.xserver.xautolock = {
11 enable = mkEnableOption "xautolock";
12 enableNotifier = mkEnableOption "xautolock.notify" // {
13 description = ''
14 Whether to enable the notifier feature of xautolock.
15 This publishes a notification before the autolock.
16 '';
17 };
18
19 time = mkOption {
20 default = 15;
21 type = types.int;
22
23 description = ''
24 Idle time to wait until xautolock locks the computer.
25 '';
26 };
27
28 locker = mkOption {
29 default = "xlock"; # default according to `man xautolock`
30 example = "i3lock -i /path/to/img";
31 type = types.string;
32
33 description = ''
34 The script to use when locking the computer.
35 '';
36 };
37
38 notify = mkOption {
39 default = 10;
40 type = types.int;
41
42 description = ''
43 Time (in seconds) before the actual lock when the notification about the pending lock should be published.
44 '';
45 };
46
47 notifier = mkOption {
48 default = "notify-send 'Locking in 10 seconds'";
49 type = types.string;
50
51 description = ''
52 Notification script to be used to warn about the pending autolock.
53 '';
54 };
55 };
56 };
57
58 config = mkIf cfg.enable {
59 environment.systemPackages = with pkgs; [ xautolock ];
60
61 services.xserver.displayManager.sessionCommands = with builtins; with pkgs; ''
62 ${xautolock}/bin/xautolock \
63 ${concatStringsSep " \\\n" ([
64 "-time ${toString(cfg.time)}"
65 "-locker ${cfg.locker}"
66 ] ++ optional cfg.enableNotifier (concatStringsSep " " [
67 "-notify ${toString(cfg.notify)}"
68 "-notifier \"${cfg.notifier}\""
69 ]))} &
70 '';
71 };
72 }