2022-01-03 19:03:20 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.swayidle;
|
|
|
|
|
|
|
|
mkTimeout = t:
|
|
|
|
[ "timeout" (toString t.timeout) (escapeShellArg t.command) ]
|
|
|
|
++ optionals (t.resumeCommand != null) [
|
|
|
|
"resume"
|
|
|
|
(escapeShellArg t.resumeCommand)
|
|
|
|
];
|
|
|
|
|
|
|
|
mkEvent = e: [ e.event (escapeShellArg e.command) ];
|
|
|
|
|
2022-05-03 17:20:46 +00:00
|
|
|
args = cfg.extraArgs ++ (concatMap mkTimeout cfg.timeouts)
|
|
|
|
++ (concatMap mkEvent cfg.events);
|
2022-01-03 19:03:20 +00:00
|
|
|
|
|
|
|
in {
|
|
|
|
meta.maintainers = [ maintainers.c0deaddict ];
|
|
|
|
|
|
|
|
options.services.swayidle = let
|
|
|
|
|
|
|
|
timeoutModule = { ... }: {
|
|
|
|
options = {
|
|
|
|
timeout = mkOption {
|
|
|
|
type = types.ints.positive;
|
|
|
|
example = 60;
|
2022-01-06 08:22:42 +00:00
|
|
|
description = "Timeout in seconds.";
|
2022-01-03 19:03:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
command = mkOption {
|
|
|
|
type = types.str;
|
2022-01-06 08:22:42 +00:00
|
|
|
description = "Command to run after timeout seconds of inactivity.";
|
2022-01-03 19:03:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
resumeCommand = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
2022-01-06 08:22:42 +00:00
|
|
|
description = "Command to run when there is activity again.";
|
2022-01-03 19:03:20 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
eventModule = { ... }: {
|
|
|
|
options = {
|
|
|
|
event = mkOption {
|
|
|
|
type = types.enum [ "before-sleep" "after-resume" "lock" "unlock" ];
|
2022-01-06 08:22:42 +00:00
|
|
|
description = "Event name.";
|
2022-01-03 19:03:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
command = mkOption {
|
|
|
|
type = types.str;
|
2022-01-06 08:22:42 +00:00
|
|
|
description = "Command to run when event occurs.";
|
2022-01-03 19:03:20 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
2022-01-06 08:22:42 +00:00
|
|
|
enable = mkEnableOption "idle manager for Wayland";
|
2022-01-03 19:03:20 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.swayidle;
|
|
|
|
defaultText = literalExpression "pkgs.swayidle";
|
|
|
|
description = "Swayidle package to install.";
|
|
|
|
};
|
|
|
|
|
|
|
|
timeouts = mkOption {
|
|
|
|
type = with types; listOf (submodule timeoutModule);
|
|
|
|
default = [ ];
|
2022-01-06 08:22:42 +00:00
|
|
|
example = literalExpression ''
|
2022-01-03 19:03:20 +00:00
|
|
|
[
|
2022-10-04 16:50:55 +00:00
|
|
|
{ timeout = 60; command = "${pkgs.swaylock}/bin/swaylock -fF"; }
|
2022-01-03 19:03:20 +00:00
|
|
|
]
|
|
|
|
'';
|
2022-01-06 08:22:42 +00:00
|
|
|
description = "List of commands to run after idle timeout.";
|
2022-01-03 19:03:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
events = mkOption {
|
|
|
|
type = with types; listOf (submodule eventModule);
|
|
|
|
default = [ ];
|
2022-01-06 08:22:42 +00:00
|
|
|
example = literalExpression ''
|
2022-01-03 19:03:20 +00:00
|
|
|
[
|
2022-10-04 16:50:55 +00:00
|
|
|
{ event = "before-sleep"; command = "${pkgs.swaylock}/bin/swaylock"; }
|
2022-01-03 19:03:20 +00:00
|
|
|
{ event = "lock"; command = "lock"; }
|
|
|
|
]
|
|
|
|
'';
|
2022-12-03 04:20:00 +00:00
|
|
|
description = "Run command on occurrence of a event.";
|
2022-01-03 19:03:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [ ];
|
2022-01-06 08:22:42 +00:00
|
|
|
description = "Extra arguments to pass to swayidle.";
|
2022-01-03 19:03:20 +00:00
|
|
|
};
|
2022-09-05 16:56:10 +00:00
|
|
|
|
|
|
|
systemdTarget = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "sway-session.target";
|
|
|
|
description = ''
|
|
|
|
Systemd target to bind to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-01-03 19:03:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2022-04-24 14:25:54 +00:00
|
|
|
assertions = [
|
|
|
|
(hm.assertions.assertPlatform "services.swayidle" pkgs platforms.linux)
|
|
|
|
];
|
|
|
|
|
2022-01-03 19:03:20 +00:00
|
|
|
systemd.user.services.swayidle = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Idle manager for Wayland";
|
|
|
|
Documentation = "man:swayidle(1)";
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
Type = "simple";
|
2022-07-03 16:28:29 +00:00
|
|
|
# swayidle executes commands using "sh -c", so the PATH needs to contain a shell.
|
|
|
|
Environment = [ "PATH=${makeBinPath [ pkgs.bash ]}" ];
|
2022-01-03 19:03:20 +00:00
|
|
|
ExecStart =
|
|
|
|
"${cfg.package}/bin/swayidle -w ${concatStringsSep " " args}";
|
|
|
|
};
|
|
|
|
|
2022-09-05 16:56:10 +00:00
|
|
|
Install = { WantedBy = [ cfg.systemdTarget ]; };
|
2022-01-03 19:03:20 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|