diff --git a/modules/services/swayidle.nix b/modules/services/swayidle.nix index 79da15c80..66e22966c 100644 --- a/modules/services/swayidle.nix +++ b/modules/services/swayidle.nix @@ -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) ]; diff --git a/tests/modules/services/swayidle/legacy-configuration.nix b/tests/modules/services/swayidle/legacy-configuration.nix index e07834fa7..3081cfc12 100644 --- a/tests/modules/services/swayidle/legacy-configuration.nix +++ b/tests/modules/services/swayidle/legacy-configuration.nix @@ -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