mirror of
https://github.com/nix-community/home-manager
synced 2024-11-16 08:09:45 +01:00
5f433eb164
Before, loading a module would be guarded by an optional platform condition. This made it possible to avoid loading and evaluating a module if it did not support the host platform. Unfortunately, this made it impossible to share a single configuration between GNU/Linux and Darwin hosts, which some wish to do. This removes the conditional load and instead inserts host platform assertions in the modules that are platform specific. Fixes #1906
97 lines
2.5 KiB
Nix
97 lines
2.5 KiB
Nix
{ 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";
|
|
};
|
|
|
|
enableDetectSleep = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
description = ''
|
|
Whether to reset timers when awaking from sleep.
|
|
'';
|
|
};
|
|
|
|
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"/>.
|
|
'';
|
|
};
|
|
|
|
xautolockExtraOptions = mkOption {
|
|
type = types.listOf types.str;
|
|
default = [ ];
|
|
description = ''
|
|
Extra command-line arguments to pass to <command>xautolock</command>.
|
|
'';
|
|
};
|
|
|
|
xssLockExtraOptions = mkOption {
|
|
type = types.listOf types.str;
|
|
default = [ ];
|
|
description = ''
|
|
Extra command-line arguments to pass to <command>xss-lock</command>.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
assertions = [
|
|
(lib.hm.assertions.assertPlatform "services.screen-locker" pkgs
|
|
lib.platforms.linux)
|
|
];
|
|
|
|
systemd.user.services.xautolock-session = {
|
|
Unit = {
|
|
Description = "xautolock, session locker service";
|
|
After = [ "graphical-session-pre.target" ];
|
|
PartOf = [ "graphical-session.target" ];
|
|
};
|
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
|
|
|
Service = {
|
|
ExecStart = concatStringsSep " " ([
|
|
"${pkgs.xautolock}/bin/xautolock"
|
|
"-time ${toString cfg.inactiveInterval}"
|
|
"-locker '${pkgs.systemd}/bin/loginctl lock-session $XDG_SESSION_ID'"
|
|
] ++ optional cfg.enableDetectSleep "-detectsleep"
|
|
++ cfg.xautolockExtraOptions);
|
|
};
|
|
};
|
|
|
|
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}" ]);
|
|
};
|
|
};
|
|
};
|
|
|
|
}
|