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"; }