2021-04-06 19:54:26 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2021-04-06 19:20:39 +02:00
|
|
|
let
|
|
|
|
cfg = config.my.home.wm.screen-lock;
|
2021-04-19 18:44:28 +02:00
|
|
|
|
2024-09-27 15:48:26 +02:00
|
|
|
notificationCmd =
|
2021-04-19 18:44:28 +02:00
|
|
|
let
|
|
|
|
duration = toString (cfg.notify.delay * 1000);
|
2023-07-23 19:58:40 +02:00
|
|
|
notifyCmd = "${lib.getExe pkgs.libnotify} -u critical -t ${duration}";
|
2021-04-19 18:44:28 +02:00
|
|
|
in
|
|
|
|
# Needs to be surrounded by quotes for systemd to launch it correctly
|
|
|
|
''"${notifyCmd} -- 'Locking in ${toString cfg.notify.delay} seconds'"'';
|
2021-04-06 19:20:39 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
config = lib.mkIf cfg.enable {
|
2021-06-15 17:45:17 +02:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion =
|
|
|
|
let
|
|
|
|
inherit (cfg) cornerLock notify;
|
|
|
|
bothEnabled = cornerLock.enable && notify.enable;
|
|
|
|
cornerLockHigherThanNotify = cornerLock.delay >= notify.delay;
|
|
|
|
in
|
|
|
|
bothEnabled -> cornerLockHigherThanNotify;
|
|
|
|
message = ''
|
|
|
|
`config.my.home.wm.notify.delay` cannot have a value higher than
|
|
|
|
`config.my.home.wm.cornerLock.delay`.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2021-04-06 19:20:39 +02:00
|
|
|
services.screen-locker = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
inactiveInterval = cfg.timeout;
|
|
|
|
|
|
|
|
lockCmd = cfg.command;
|
2021-04-06 19:54:26 +02:00
|
|
|
|
2021-10-22 13:15:16 +02:00
|
|
|
xautolock = {
|
|
|
|
extraOptions = lib.optionals cfg.cornerLock.enable [
|
|
|
|
# Mouse corners: instant lock on upper-left, never lock on lower-right
|
|
|
|
"-cornerdelay"
|
|
|
|
"${toString cfg.cornerLock.delay}"
|
|
|
|
"-cornerredelay"
|
|
|
|
"${toString cfg.cornerLock.delay}"
|
|
|
|
"-corners"
|
|
|
|
"+00-"
|
|
|
|
] ++ lib.optionals cfg.notify.enable [
|
|
|
|
"-notify"
|
|
|
|
"${toString cfg.notify.delay}"
|
|
|
|
"-notifier"
|
2024-09-27 15:48:26 +02:00
|
|
|
notificationCmd
|
2021-10-22 13:15:16 +02:00
|
|
|
];
|
|
|
|
};
|
2021-04-06 19:20:39 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|