1 { config, lib, pkgs, ... }:
6 cfg = config.services.xserver.xautolock;
10 services.xserver.xautolock = {
11 enable = mkEnableOption "xautolock";
12 enableNotifier = mkEnableOption "xautolock.notify" // {
14 Whether to enable the notifier feature of xautolock.
15 This publishes a notification before the autolock.
24 Idle time (in minutes) to wait until xautolock locks the computer.
29 default = "${pkgs.xlockmore}/bin/xlock"; # default according to `man xautolock`
30 defaultText = literalExpression ''"''${pkgs.xlockmore}/bin/xlock"'';
31 example = literalExpression ''"''${pkgs.i3lock}/bin/i3lock -i /path/to/img"'';
35 The script to use when automatically locking the computer.
39 nowlocker = mkOption {
41 example = literalExpression ''"''${pkgs.i3lock}/bin/i3lock -i /path/to/img"'';
42 type = types.nullOr types.str;
45 The script to use when manually locking the computer with {command}`xautolock -locknow`.
54 Time (in seconds) before the actual lock when the notification about the pending lock should be published.
60 example = literalExpression ''"''${pkgs.libnotify}/bin/notify-send 'Locking in 10 seconds'"'';
61 type = types.nullOr types.str;
64 Notification script to be used to warn about the pending autolock.
69 default = null; # default according to `man xautolock` is none
70 example = "/run/current-system/systemd/bin/systemctl suspend";
71 type = types.nullOr types.str;
74 The script to use when nothing has happened for as long as {option}`killtime`
79 default = 20; # default according to `man xautolock`
83 Minutes xautolock waits until it executes the script specified in {option}`killer`
84 (Has to be at least 10 minutes)
88 extraOptions = mkOption {
89 type = types.listOf types.str;
91 example = [ "-detectsleep" ];
93 Additional command-line arguments to pass to
100 config = mkIf cfg.enable {
101 environment.systemPackages = with pkgs; [ xautolock ];
102 systemd.user.services.xautolock = {
103 description = "xautolock service";
104 wantedBy = [ "graphical-session.target" ];
105 partOf = [ "graphical-session.target" ];
106 serviceConfig = with lib; {
107 ExecStart = strings.concatStringsSep " " ([
108 "${pkgs.xautolock}/bin/xautolock"
110 "-time ${toString cfg.time}"
111 "-locker '${cfg.locker}'"
112 ] ++ optionals cfg.enableNotifier [
113 "-notify ${toString cfg.notify}"
114 "-notifier '${cfg.notifier}'"
115 ] ++ optionals (cfg.nowlocker != null) [
116 "-nowlocker '${cfg.nowlocker}'"
117 ] ++ optionals (cfg.killer != null) [
118 "-killer '${cfg.killer}'"
119 "-killtime ${toString cfg.killtime}"
120 ] ++ cfg.extraOptions);
126 assertion = cfg.enableNotifier -> cfg.notifier != null;
127 message = "When enabling the notifier for xautolock, you also need to specify the notify script";
130 assertion = cfg.killer != null -> cfg.killtime >= 10;
131 message = "killtime has to be at least 10 minutes according to `man xautolock`";
133 ] ++ (lib.forEach [ "locker" "notifier" "nowlocker" "killer" ]
136 assertion = cfg.${option} != null -> builtins.substring 0 1 cfg.${option} == "/";
137 message = "Please specify a canonical path for `services.xserver.xautolock.${option}`";