Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions modules/services/swayidle.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,32 @@ in
};
};

eventModule =
eventsModule =
{ ... }:
{
options = {
event = mkOption {
type = types.enum [
"before-sleep"
"after-resume"
"lock"
"unlock"
];
description = "Event name.";
before-sleep = mkOption {
type = types.nullOr types.str;
default = null;
description = "Command to run before suspending.";
};

command = mkOption {
type = types.str;
description = "Command to run when event occurs.";
after-resume = mkOption {
type = types.nullOr types.str;
default = null;
description = "Command to run after resuming.";
};

lock = mkOption {
type = types.nullOr types.str;
default = null;
description = "Command to run when the logind session is locked.";
};

unlock = mkOption {
type = types.nullOr types.str;
default = null;
description = "Command to run when the logind session is unlocked.";
};
};
};
Expand All @@ -84,13 +93,13 @@ in
};

events = mkOption {
type = with types; listOf (submodule eventModule);
type = with types; submodule eventsModule;
default = [ ];
example = literalExpression ''
[
{ event = "before-sleep"; command = "${pkgs.swaylock}/bin/swaylock -fF"; }
{ event = "lock"; command = "lock"; }
]
{
"before-sleep" = "${pkgs.swaylock}/bin/swaylock -fF";
"lock" = "lock";
}
'';
description = "Run command on occurrence of a event.";
};
Expand Down Expand Up @@ -146,13 +155,17 @@ in
t.resumeCommand
];

mkEvent = e: [
e.event
e.command
mkEvent = event: command: [
event
command
];

nonemptyEvents = lib.filterAttrs (event: command: command != null) cfg.events;

args =
cfg.extraArgs ++ (lib.concatMap mkTimeout cfg.timeouts) ++ (lib.concatMap mkEvent cfg.events);
cfg.extraArgs
++ (lib.concatMap mkTimeout cfg.timeouts)
++ (lib.flatten (lib.mapAttrsToList mkEvent nonemptyEvents));
in
"${lib.getExe cfg.package} ${lib.escapeShellArgs args}";
};
Expand Down
14 changes: 4 additions & 10 deletions tests/modules/services/swayidle/basic-configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@
resumeCommand = ''swaymsg "output * dpms on"'';
}
];
events = [
{
event = "before-sleep";
command = "swaylock -fF";
}
{
event = "lock";
command = "swaylock -fF";
}
];
events = {
before-sleep = "swaylock -fF";
lock = "swaylock -fF";
};
};

nmt.script = ''
Expand Down
Loading