swayidle: assert events migration warning

This commit is contained in:
Austin Horstman
2026-06-01 12:39:55 -05:00
parent ff53fe10e0
commit 9a638c1442
2 changed files with 37 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
{
config,
lib,
options,
pkgs,
...
}:
@@ -99,22 +100,14 @@ in
events = mkOption {
type =
with types;
(coercedTo (listOf attrs)) (
coercedTo (listOf attrs) (
events:
lib.warn
''
The syntax of services.swayidle.events has changed. While it
previously accepted a list of events, it now accepts an attrset
keyed by the event name.
''
(
lib.listToAttrs (
map (e: {
name = e.event;
value = e.command;
}) events
)
)
lib.listToAttrs (
map (e: {
name = e.event;
value = e.command;
}) events
)
) (submodule eventsModule);
default = { };
example = literalExpression ''
@@ -145,6 +138,21 @@ in
};
config = lib.mkIf cfg.enable {
warnings = lib.optional (lib.any builtins.isList options.services.swayidle.events.definitions) (
lib.hm.deprecations.mkDeprecatedOptionValueWarning {
option = [
"services"
"swayidle"
"events"
];
old = "a list";
replacement = "an attribute set keyed by event name";
details = ''
Use event names as attribute keys and commands as values.
'';
}
);
assertions = [
(lib.hm.assertions.assertPlatform "services.swayidle" pkgs lib.platforms.linux)
];

View File

@@ -1,5 +1,12 @@
{ config, ... }:
{
# Exercise merging legacy list definitions with new attrset definitions.
imports = [
{
services.swayidle.events.after-resume = "notify-send resumed";
}
];
services.swayidle = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@swayidle@"; };
@@ -15,11 +22,13 @@
];
};
test.asserts.evalWarnings.expected = [
test.asserts.warnings.expected = [
''
The syntax of services.swayidle.events has changed. While it
previously accepted a list of events, it now accepts an attrset
keyed by the event name.
Using `services.swayidle.events` as a list is deprecated and will be
removed in a future release. Please use an attribute set keyed by event name instead.
Use event names as attribute keys and commands as values.
''
];
@@ -36,7 +45,7 @@
[Service]
Environment=PATH=@bash-interactive@/bin
ExecStart=@swayidle@/bin/dummy -w before-sleep 'swaylock -fF' lock 'swaylock -fF'
ExecStart=@swayidle@/bin/dummy -w after-resume 'notify-send resumed' before-sleep 'swaylock -fF' lock 'swaylock -fF'
Restart=always
Type=simple