mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 21:19:45 +01:00
kanshi: add support for output aliases
- Add `services.kanshi.profiles.<name>.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]:1ed86ce523
[2]:1605f7c813/item/doc/kanshi.5.scd (L78)
[3]:1605f7c813/item/doc/kanshi.5.scd (L80)
This commit is contained in:
parent
cb3ab5928c
commit
daaf0c2f8d
5 changed files with 45 additions and 8 deletions
|
@ -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 {
|
adaptiveSync = mkOption {
|
||||||
type = types.nullOr types.bool;
|
type = types.nullOr types.bool;
|
||||||
default = null;
|
default = null;
|
||||||
|
@ -135,15 +144,16 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputStr =
|
outputStr = { criteria, status, mode, position, scale, transform, adaptiveSync
|
||||||
{ criteria, status, mode, position, scale, transform, adaptiveSync, ... }:
|
, alias, ... }:
|
||||||
''output "${criteria}"'' + optionalString (status != null) " ${status}"
|
''output "${criteria}"'' + optionalString (status != null) " ${status}"
|
||||||
+ optionalString (mode != null) " mode ${mode}"
|
+ optionalString (mode != null) " mode ${mode}"
|
||||||
+ optionalString (position != null) " position ${position}"
|
+ optionalString (position != null) " position ${position}"
|
||||||
+ optionalString (scale != null) " scale ${toString scale}"
|
+ optionalString (scale != null) " scale ${toString scale}"
|
||||||
+ optionalString (transform != null) " transform ${transform}"
|
+ optionalString (transform != null) " transform ${transform}"
|
||||||
+ optionalString (adaptiveSync != null)
|
+ 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 {
|
profileModule = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
|
@ -296,6 +306,14 @@ in {
|
||||||
message =
|
message =
|
||||||
"Cannot mix kanshi.settings with kanshi.profiles or kanshi.extraConfig";
|
"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";
|
||||||
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
tests/modules/services/kanshi/alias-assertion.nix
Normal file
18
tests/modules/services/kanshi/alias-assertion.nix
Normal file
|
@ -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" ];
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
kanshi-basic-configuration = ./basic-configuration.nix;
|
kanshi-basic-configuration = ./basic-configuration.nix;
|
||||||
kanshi-new-configuration = ./new-configuration.nix;
|
kanshi-new-configuration = ./new-configuration.nix;
|
||||||
|
kanshi-alias-assertion = ./alias-assertion.nix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
include "path/to/included/file"
|
include "path/to/included/file"
|
||||||
output "*" enable
|
output "Iiyama North America PLE2483H-DP" alias $iiyama
|
||||||
profile nomad {
|
profile nomad {
|
||||||
output "eDP-1" enable
|
output "eDP-1" enable
|
||||||
}
|
}
|
||||||
|
|
||||||
profile desktop {
|
profile desktop {
|
||||||
output "eDP-1" disable
|
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
|
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 "1 two 3"
|
||||||
exec echo "4 five 6"
|
exec echo "4 five 6"
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
{ include = "path/to/included/file"; }
|
{ include = "path/to/included/file"; }
|
||||||
{
|
{
|
||||||
output = {
|
output = {
|
||||||
criteria = "*";
|
criteria = "Iiyama North America PLE2483H-DP";
|
||||||
status = "enable";
|
alias = "iiyama";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
status = "disable";
|
status = "disable";
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
criteria = "Iiyama North America PLE2483H-DP";
|
criteria = "$iiyama";
|
||||||
status = "enable";
|
status = "enable";
|
||||||
position = "0,0";
|
position = "0,0";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue