2017-09-20 16:50:49 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.screen-locker;
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
options.services.screen-locker = {
|
|
|
|
enable = mkEnableOption "screen locker for X session";
|
|
|
|
|
|
|
|
lockCmd = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Locker command to run.";
|
|
|
|
example = "\${pkgs.i3lock}/bin/i3lock -n -c 000000";
|
|
|
|
};
|
|
|
|
|
2020-04-06 19:41:13 +02:00
|
|
|
enableDetectSleep = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to reset timers when awaking from sleep.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-09-20 16:50:49 +02:00
|
|
|
inactiveInterval = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 10;
|
|
|
|
description = ''
|
|
|
|
Inactive time interval in minutes after which session will be locked.
|
|
|
|
The minimum is 1 minute, and the maximum is 1 hour.
|
|
|
|
See <link xlink:href="https://linux.die.net/man/1/xautolock"/>.
|
|
|
|
'';
|
|
|
|
};
|
2018-04-29 15:58:42 +02:00
|
|
|
|
|
|
|
xautolockExtraOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2018-04-29 15:58:42 +02:00
|
|
|
description = ''
|
|
|
|
Extra command-line arguments to pass to <command>xautolock</command>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
xssLockExtraOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2018-04-29 15:58:42 +02:00
|
|
|
description = ''
|
|
|
|
Extra command-line arguments to pass to <command>xss-lock</command>.
|
|
|
|
'';
|
|
|
|
};
|
2017-09-20 16:50:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-07-07 23:24:27 +02:00
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "services.screen-locker" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
|
|
|
|
2017-09-20 16:50:49 +02:00
|
|
|
systemd.user.services.xautolock-session = {
|
|
|
|
Unit = {
|
|
|
|
Description = "xautolock, session locker service";
|
|
|
|
After = [ "graphical-session-pre.target" ];
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
2017-09-20 16:50:49 +02:00
|
|
|
|
|
|
|
Service = {
|
2019-06-02 23:12:01 +02:00
|
|
|
ExecStart = concatStringsSep " " ([
|
|
|
|
"${pkgs.xautolock}/bin/xautolock"
|
|
|
|
"-time ${toString cfg.inactiveInterval}"
|
|
|
|
"-locker '${pkgs.systemd}/bin/loginctl lock-session $XDG_SESSION_ID'"
|
2020-04-06 19:41:13 +02:00
|
|
|
] ++ optional cfg.enableDetectSleep "-detectsleep"
|
|
|
|
++ cfg.xautolockExtraOptions);
|
2017-09-20 16:50:49 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-02-01 19:17:58 +01:00
|
|
|
systemd.user.services.xss-lock = {
|
|
|
|
Unit = {
|
|
|
|
Description = "xss-lock, session locker service";
|
|
|
|
After = [ "graphical-session-pre.target" ];
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
ExecStart = concatStringsSep " "
|
|
|
|
([ "${pkgs.xss-lock}/bin/xss-lock" "-s \${XDG_SESSION_ID}" ]
|
|
|
|
++ cfg.xssLockExtraOptions ++ [ "-- ${cfg.lockCmd}" ]);
|
|
|
|
};
|
|
|
|
};
|
2017-09-20 16:50:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|