nix-files/hosts/common/programs/swayidle.nix

69 lines
1.8 KiB
Nix
Raw Normal View History

2024-03-06 20:55:01 +00:00
{ 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 = {};
};
};
};
2024-03-06 21:33:11 +00:00
sandbox.method = "bwrap";
sandbox.whitelistDbus = [ "user" ]; #< might need system too, for inhibitors
sandbox.whitelistWayland = true;
2024-03-06 20:55:01 +00:00
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";
};
};
};
}