--- a/modules/hosts.nix +++ b/modules/hosts.nix @@ -1,12 +1,15 @@ { lib, fleetLib, + config, ... }: let inherit (fleetLib.modules) mkFleetGeneratorDefault; inherit (fleetLib.types) mkHostsType mkDataType; inherit (lib.options) mkOption; inherit (lib.types) str listOf attrsOf submodule; + inherit (lib.attrsets) mapAttrsToList mapAttrs; + inherit (lib.lists) flatten groupBy; in { options = { data = mkOption { @@ -35,6 +38,10 @@ Usually used to persist fleet data between runs. ''; }; + taggedWith = mkOption { + type = attrsOf (listOf str); + internal = true; + }; hosts = mkOption { type = mkHostsType ({config, ...}: { options = { @@ -75,5 +82,10 @@ description = "Configurations of individual hosts"; }; }; + config.taggedWith = let + hostTagList = flatten (mapAttrsToList (hostname: host: map (tag: {inherit hostname tag;}) host.tags) config.hosts); + grouped = mapAttrs (_: hosts: lib.map (pair: pair.hostname) hosts) (groupBy (elem: elem.tag) hostTagList); + in + grouped; _file = ./meta.nix; }