From c01046b022329000c28e0b48b773e0d1b18d68fc Mon Sep 17 00:00:00 2001 From: Viktor Kronvall Date: Thu, 22 Apr 2021 21:23:52 +0900 Subject: [PATCH] services.buildkite-agents: support multi-tags The buildkite agent supports multiple tags with the same key. This functionality is used to have a [single agent listen on multiple queues](https://buildkite.com/docs/agent/v3/queues#setting-an-agents-queue). However, having the tags be of type `attrsOf str` means that we cannot suport this use case. This commit modifies the type of tags to be `attrsOf (either str (listOf str))` where the list is expanded into multiple tags with the same key. Example: ``` {tags = {queue = ["default", "testing"];};} ``` generates ``` tags="queue=default,queue=testing" ``` in the buildkite agent configuration. --- .../continuous-integration/buildkite-agents.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/continuous-integration/buildkite-agents.nix b/nixos/modules/services/continuous-integration/buildkite-agents.nix index b0045409ae6..3dd1c40aaa4 100644 --- a/nixos/modules/services/continuous-integration/buildkite-agents.nix +++ b/nixos/modules/services/continuous-integration/buildkite-agents.nix @@ -76,7 +76,7 @@ let }; tags = mkOption { - type = types.attrsOf types.str; + type = types.attrsOf (types.either types.str (types.listOf types.str)); default = {}; example = { queue = "default"; docker = "true"; ruby2 ="true"; }; description = '' @@ -230,7 +230,11 @@ in ## don't end up in the Nix store. preStart = let sshDir = "${cfg.dataDir}/.ssh"; - tagStr = lib.concatStringsSep "," (lib.mapAttrsToList (name: value: "${name}=${value}") cfg.tags); + tagStr = name: value: + if lib.isList value + then lib.concatStringsSep "," (builtins.map (v: "${name}=${v}") value) + else "${name}=${value}"; + tagsStr = lib.concatStringsSep "," (lib.mapAttrsToList tagStr cfg.tags); in optionalString (cfg.privateSshKeyPath != null) '' mkdir -m 0700 -p "${sshDir}" @@ -241,7 +245,7 @@ in token="$(cat ${toString cfg.tokenPath})" name="${cfg.name}" shell="${cfg.shell}" - tags="${tagStr}" + tags="${tagsStr}" build-path="${cfg.dataDir}/builds" hooks-path="${cfg.hooksPath}" ${cfg.extraConfig}