From 095f3e32ae8de2e0828e548d88e553069025cec1 Mon Sep 17 00:00:00 2001 From: Faye Duxovni Date: Sat, 2 Oct 2021 17:22:36 -0400 Subject: [PATCH] kanshi: allow multiple exec statements per profile kanshi configurations can have more than one exec statement in a profile. This change allows services.kanshi.profiles..exec to be a list of strings rather than a single string. --- modules/services/kanshi.nix | 19 +++++++++++-------- .../services/kanshi/basic-configuration.conf | 6 ++++++ .../services/kanshi/basic-configuration.nix | 9 ++++++++- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/modules/services/kanshi.nix b/modules/services/kanshi.nix index ce6e25221..55788ae0e 100644 --- a/modules/services/kanshi.nix +++ b/modules/services/kanshi.nix @@ -104,23 +104,26 @@ let }; exec = mkOption { - type = types.nullOr types.str; - default = null; + type = with types; coercedTo str singleton (listOf str); + default = [ ]; example = - "\${pkg.sway}/bin/swaymsg workspace 1, move workspace to eDP-1"; + "[ \${pkg.sway}/bin/swaymsg workspace 1, move workspace to eDP-1 ]"; description = '' - Command executed after the profile is succesfully applied. + Commands executed after the profile is succesfully applied. + Note that if you provide multiple commands, they will be + executed asynchronously with no guaranteed ordering. ''; }; }; }; profileStr = name: - { outputs, exec, ... }: - '' + { outputs, exec, ... }: '' profile ${name} { - ${concatStringsSep "\n " (map outputStr outputs)} - '' + optionalString (exec != null) " exec ${exec}\n" + '' + ${ + concatStringsSep "\n " + (map outputStr outputs ++ map (cmd: "exec ${cmd}") exec) + } } ''; in { diff --git a/tests/modules/services/kanshi/basic-configuration.conf b/tests/modules/services/kanshi/basic-configuration.conf index 9d6442b98..a305f28f2 100644 --- a/tests/modules/services/kanshi/basic-configuration.conf +++ b/tests/modules/services/kanshi/basic-configuration.conf @@ -1,8 +1,14 @@ +profile backwardsCompat { + output "LVDS-1" enable + exec echo "7 eight 9" +} + profile desktop { output "eDP-1" disable output "Iiyama North America PLE2483H-DP" 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" } profile nomad { diff --git a/tests/modules/services/kanshi/basic-configuration.nix b/tests/modules/services/kanshi/basic-configuration.nix index b8cd5d214..c5706e635 100644 --- a/tests/modules/services/kanshi/basic-configuration.nix +++ b/tests/modules/services/kanshi/basic-configuration.nix @@ -11,7 +11,7 @@ }]; }; desktop = { - exec = ''echo "1 two 3"''; + exec = [ ''echo "1 two 3"'' ''echo "4 five 6"'' ]; outputs = [ { criteria = "eDP-1"; @@ -32,6 +32,13 @@ } ]; }; + backwardsCompat = { + outputs = [{ + criteria = "LVDS-1"; + status = "enable"; + }]; + exec = ''echo "7 eight 9"''; + }; }; extraConfig = '' profile test {