65 lines
1.6 KiB
Nix
65 lines
1.6 KiB
Nix
|
{ config, lib, ... }:
|
||
|
let
|
||
|
cfg = config.sane.programs.swayidle;
|
||
|
idleAction = with lib; types.submodule ({ config, name, ... }: {
|
||
|
options.enable = mkOption {
|
||
|
type = types.bool;
|
||
|
default = true;
|
||
|
};
|
||
|
options.command = mkOption {
|
||
|
type = types.str;
|
||
|
default = name;
|
||
|
};
|
||
|
options.desktop = mkOption {
|
||
|
type = types.nullOr types.str;
|
||
|
default = null;
|
||
|
};
|
||
|
options.delay = mkOption {
|
||
|
type = types.int;
|
||
|
description = ''
|
||
|
how many seconds of idle time before triggering the command.
|
||
|
'';
|
||
|
};
|
||
|
config.command = lib.mkIf (config.desktop != null) "sane-open-desktop ${config.desktop}";
|
||
|
});
|
||
|
in
|
||
|
{
|
||
|
sane.programs.swayidle = {
|
||
|
configOption = with lib; mkOption {
|
||
|
default = {};
|
||
|
type = types.submodule {
|
||
|
options.actions = mkOption {
|
||
|
type = types.attrsOf idleAction;
|
||
|
default = {};
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
# sandboxing: TODO
|
||
|
services.swayidle = {
|
||
|
description = "swayidle: perform actions when sway session is idle";
|
||
|
after = [ "graphical-session.target" ];
|
||
|
wantedBy = [ "graphical-session.target" ];
|
||
|
|
||
|
serviceConfig = {
|
||
|
ExecStart = lib.escapeShellArgs (
|
||
|
[
|
||
|
"${cfg.package}/bin/swayidle"
|
||
|
"-w"
|
||
|
] ++ lib.flatten (
|
||
|
lib.mapAttrsToList
|
||
|
(_: { command, delay, enable, ... }: lib.optionals enable [
|
||
|
"timeout"
|
||
|
(builtins.toString delay)
|
||
|
command
|
||
|
])
|
||
|
cfg.config.actions
|
||
|
)
|
||
|
);
|
||
|
Type = "simple";
|
||
|
Restart = "always";
|
||
|
RestartSec = "20s";
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
}
|