git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commitc01046b022329000c28e0b48b773e0d1b18d68fc authorViktor Kronvall <viktor.kronvall@gmail.com> dateThu 22 Apr 2021, 21:23 (6 years ago) parentf29292d
1 file changed+7−3
nixos/modules/services/continuous-integration/buildkite-agents.nix+7−3
nixos/modules/services/continuous-integration/buildkite-agents.nix+7−3
@@ -76,7 +76,7 @@ let
7676 };
7777
7878 tags = mkOption {
79− type = types.attrsOf types.str;
79+ type = types.attrsOf (types.either types.str (types.listOf types.str));
8080 default = {};
8181 example = { queue = "default"; docker = "true"; ruby2 ="true"; };
8282 description = ''
@@ -230,7 +230,11 @@ in
230230 ## don't end up in the Nix store.
231231 preStart = let
232232 sshDir = "${cfg.dataDir}/.ssh";
233− tagStr = lib.concatStringsSep "," (lib.mapAttrsToList (name: value: "${name}=${value}") cfg.tags);
233+ tagStr = name: value:
234+ if lib.isList value
235+ then lib.concatStringsSep "," (builtins.map (v: "${name}=${v}") value)
236+ else "${name}=${value}";
237+ tagsStr = lib.concatStringsSep "," (lib.mapAttrsToList tagStr cfg.tags);
234238 in
235239 optionalString (cfg.privateSshKeyPath != null) ''
236240 mkdir -m 0700 -p "${sshDir}"
@@ -241,7 +245,7 @@ in
241245 token="$(cat ${toString cfg.tokenPath})"
242246 name="${cfg.name}"
243247 shell="${cfg.shell}"
244− tags="${tagStr}"
248+ tags="${tagsStr}"
245249 build-path="${cfg.dataDir}/builds"
246250 hooks-path="${cfg.hooksPath}"
247251 ${cfg.extraConfig}