From daaf0c2f8da6c7b5dc04dd62a3d98422f259551b Mon Sep 17 00:00:00 2001 From: "O. C. Taskin" <42993892+octvs@users.noreply.github.com> Date: Fri, 13 Sep 2024 10:51:33 +0200 Subject: [PATCH] kanshi: add support for output aliases - Add `services.kanshi.profiles..outputs.*.alias` to support new alias directive from kanshi [1]. - Add an assertion to reject aliases not on global scope, which are not allowed on kanshi [2]. - Add a new test to check alias rejection, `alias-assertion`. - Add relevant coverage by modifying the existing "new-configuration" test. - Kanshi also doesn't allow wildcards on global scope [3], correct the faulty test case. [1]: https://git.sr.ht/~emersion/kanshi/commit/1ed86ce523553240ceb81e9d466b88d3554a66bb [2]: https://git.sr.ht/~emersion/kanshi/tree/1605f7c81314d004104b7a1b149656947369c999/item/doc/kanshi.5.scd#L78 [3]: https://git.sr.ht/~emersion/kanshi/tree/1605f7c81314d004104b7a1b149656947369c999/item/doc/kanshi.5.scd#L80 --- modules/services/kanshi.nix | 24 ++++++++++++++++--- .../services/kanshi/alias-assertion.nix | 18 ++++++++++++++ tests/modules/services/kanshi/default.nix | 1 + .../services/kanshi/new-configuration.conf | 4 ++-- .../services/kanshi/new-configuration.nix | 6 ++--- 5 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 tests/modules/services/kanshi/alias-assertion.nix diff --git a/modules/services/kanshi.nix b/modules/services/kanshi.nix index b503ffc7f..3b1bdf2cf 100644 --- a/modules/services/kanshi.nix +++ b/modules/services/kanshi.nix @@ -123,6 +123,15 @@ let ''; }; + alias = mkOption { + type = types.nullOr types.str; + default = null; + example = "laptopMonitor"; + description = '' + Defines an alias for the output + ''; + }; + adaptiveSync = mkOption { type = types.nullOr types.bool; default = null; @@ -135,15 +144,16 @@ let }; }; - outputStr = - { criteria, status, mode, position, scale, transform, adaptiveSync, ... }: + outputStr = { criteria, status, mode, position, scale, transform, adaptiveSync + , alias, ... }: ''output "${criteria}"'' + optionalString (status != null) " ${status}" + optionalString (mode != null) " mode ${mode}" + optionalString (position != null) " position ${position}" + optionalString (scale != null) " scale ${toString scale}" + optionalString (transform != null) " transform ${transform}" + optionalString (adaptiveSync != null) - " adaptive_sync ${if adaptiveSync then "on" else "off"}"; + " adaptive_sync ${if adaptiveSync then "on" else "off"}" + + optionalString (alias != null) " alias \$${alias}"; profileModule = types.submodule { options = { @@ -296,6 +306,14 @@ in { message = "Cannot mix kanshi.settings with kanshi.profiles or kanshi.extraConfig"; } + { + assertion = let profiles = filter (x: x ? profile) cfg.settings; + in length + (filter (x: any (a: a ? alias && a.alias != null) x.profile.outputs) + profiles) == 0; + message = + "Output kanshi.*.output.alias can only be defined on global scope"; + } ]; } diff --git a/tests/modules/services/kanshi/alias-assertion.nix b/tests/modules/services/kanshi/alias-assertion.nix new file mode 100644 index 000000000..0dc6d7e64 --- /dev/null +++ b/tests/modules/services/kanshi/alias-assertion.nix @@ -0,0 +1,18 @@ +{ config, pkgs, ... }: { + config = { + services.kanshi = { + enable = true; + package = config.lib.test.mkStubPackage { }; + settings = [{ + profile.name = "nomad"; + profile.outputs = [{ + criteria = "eDP-1"; + alias = "test"; + }]; + }]; + }; + + test.asserts.assertions.expected = + [ "Output kanshi.*.output.alias can only be defined on global scope" ]; + }; +} diff --git a/tests/modules/services/kanshi/default.nix b/tests/modules/services/kanshi/default.nix index b7704b112..05e224aaa 100644 --- a/tests/modules/services/kanshi/default.nix +++ b/tests/modules/services/kanshi/default.nix @@ -1,4 +1,5 @@ { kanshi-basic-configuration = ./basic-configuration.nix; kanshi-new-configuration = ./new-configuration.nix; + kanshi-alias-assertion = ./alias-assertion.nix; } diff --git a/tests/modules/services/kanshi/new-configuration.conf b/tests/modules/services/kanshi/new-configuration.conf index c0858a048..817f66329 100644 --- a/tests/modules/services/kanshi/new-configuration.conf +++ b/tests/modules/services/kanshi/new-configuration.conf @@ -1,12 +1,12 @@ include "path/to/included/file" -output "*" enable +output "Iiyama North America PLE2483H-DP" alias $iiyama profile nomad { output "eDP-1" enable } profile desktop { output "eDP-1" disable - output "Iiyama North America PLE2483H-DP" enable position 0,0 + output "$iiyama" enable position 0,0 output "Iiyama North America PLE2483H-DP 1158765348486" enable mode 1920x1080 position 1920,0 scale 2.100000 transform flipped-270 exec echo "1 two 3" exec echo "4 five 6" diff --git a/tests/modules/services/kanshi/new-configuration.nix b/tests/modules/services/kanshi/new-configuration.nix index 9b3a36478..2c92c730d 100644 --- a/tests/modules/services/kanshi/new-configuration.nix +++ b/tests/modules/services/kanshi/new-configuration.nix @@ -7,8 +7,8 @@ { include = "path/to/included/file"; } { output = { - criteria = "*"; - status = "enable"; + criteria = "Iiyama North America PLE2483H-DP"; + alias = "iiyama"; }; } { @@ -27,7 +27,7 @@ status = "disable"; } { - criteria = "Iiyama North America PLE2483H-DP"; + criteria = "$iiyama"; status = "enable"; position = "0,0"; }