nixos/xautolock: rewrite and add some options
This commit is contained in:
parent
e64f4d8118
commit
5e8d1757ef
@ -31,7 +31,17 @@ in
|
|||||||
type = types.string;
|
type = types.string;
|
||||||
|
|
||||||
description = ''
|
description = ''
|
||||||
The script to use when locking the computer.
|
The script to use when automatically locking the computer.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
nowlocker = mkOption {
|
||||||
|
default = null;
|
||||||
|
example = "i3lock -i /path/to/img";
|
||||||
|
type = types.nullOr types.string;
|
||||||
|
|
||||||
|
description = ''
|
||||||
|
The script to use when manually locking the computer with <command>xautolock -locknow</command>.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -45,28 +55,82 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
notifier = mkOption {
|
notifier = mkOption {
|
||||||
default = "notify-send 'Locking in 10 seconds'";
|
default = null;
|
||||||
type = types.string;
|
example = literalExample ''
|
||||||
|
"${pkgs.libnotify}/bin/notify-send \"Locking in 10 seconds\""
|
||||||
|
'';
|
||||||
|
type = types.nullOr types.string;
|
||||||
|
|
||||||
description = ''
|
description = ''
|
||||||
Notification script to be used to warn about the pending autolock.
|
Notification script to be used to warn about the pending autolock.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
killer = mkOption {
|
||||||
|
default = null; # default according to `man xautolock` is none
|
||||||
|
example = "systemctl suspend";
|
||||||
|
type = types.nullOr types.string;
|
||||||
|
|
||||||
|
description = ''
|
||||||
|
The script to use when nothing has happend for as long as <option>killtime</option>
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
killtime = mkOption {
|
||||||
|
default = 20; # default according to `man xautolock`
|
||||||
|
type = types.int;
|
||||||
|
|
||||||
|
description = ''
|
||||||
|
Minutes xautolock waits until it executes the script specified in <option>killer</option>
|
||||||
|
(Has to be at least 10 minutes)
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
extraOptions = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [ ];
|
||||||
|
example = [ "-detectsleep" ];
|
||||||
|
description = ''
|
||||||
|
Additional command-line arguments to pass to
|
||||||
|
<command>xautolock</command>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
environment.systemPackages = with pkgs; [ xautolock ];
|
environment.systemPackages = with pkgs; [ xautolock ];
|
||||||
|
systemd.user.services.xautolock = {
|
||||||
services.xserver.displayManager.sessionCommands = with builtins; with pkgs; ''
|
description = "xautolock service";
|
||||||
${xautolock}/bin/xautolock \
|
wantedBy = [ "graphical-session.target" ];
|
||||||
${concatStringsSep " \\\n" ([
|
partOf = [ "graphical-session.target" ];
|
||||||
"-time ${toString(cfg.time)}"
|
serviceConfig = with lib; {
|
||||||
"-locker ${cfg.locker}"
|
ExecStart = strings.concatStringsSep " " ([
|
||||||
] ++ optional cfg.enableNotifier (concatStringsSep " " [
|
"${pkgs.xautolock}/bin/xautolock"
|
||||||
"-notify ${toString(cfg.notify)}"
|
"-noclose"
|
||||||
"-notifier \"${cfg.notifier}\""
|
"-time ${toString cfg.time}"
|
||||||
]))} &
|
"-locker '${cfg.locker}'"
|
||||||
'';
|
] ++ optionals cfg.enableNotifier [
|
||||||
|
"-notify ${toString cfg.notify}"
|
||||||
|
"-notifier '${cfg.notifier}'"
|
||||||
|
] ++ optionals (cfg.nowlocker != null) [
|
||||||
|
"-nowlocker '${cfg.nowlocker}'"
|
||||||
|
] ++ optionals (cfg.killer != null) [
|
||||||
|
"-killer '${cfg.killer}'"
|
||||||
|
"-killtime ${toString cfg.killtime}"
|
||||||
|
] ++ cfg.extraOptions);
|
||||||
|
Restart = "always";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = cfg.enableNotifier -> cfg.notifier != null;
|
||||||
|
message = "When enabling the notifier for xautolock, you also need to specify the notify script";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
assertion = cfg.killer != null -> cfg.killtime >= 10;
|
||||||
|
message = "killtime has to be at least 10 minutes according to `man xautolock`";
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user