git.delta.rocks / jrsonnet / refs/commits / 6d807f634fbf

difftreelog

feat retrieve tagged hosts

Yaroslav Bolyukin2024-11-30parent: #fcad02a.patch.diff
in: trunk

1 file changed

modifiedmodules/hosts.nixdiffbeforeafterboth
before · modules/hosts.nix
1{2  lib,3  fleetLib,4  ...5}: let6  inherit (fleetLib.modules) mkFleetGeneratorDefault;7  inherit (fleetLib.types) mkHostsType mkDataType;8  inherit (lib.options) mkOption;9  inherit (lib.types) str listOf attrsOf submodule;10in {11  options = {12    data = mkOption {13      type = mkDataType {14        options = {15          version = mkOption {16            type = str;17            internal = true;18          };19          gcRootPrefix = mkOption {20            type = str;21            internal = true;22          };23          hosts = mkOption {24            type = attrsOf (submodule {25              options.encryptionKey = mkOption {26                type = str;27                description = "Rage SSH encryption key for secrets.";28              };29            });30          };31        };32      };33      description = ''34        Configuration provided from outside.35        Usually used to persist fleet data between runs.36      '';37    };38    hosts = mkOption {39      type = mkHostsType ({config, ...}: {40        options = {41          system = mkOption {42            description = "Type of the system.";43            type = str;44            example = "x86_64-linux";45          };46          tags = mkOption {47            description = "Host tag. In CLI, you can refer to all hosts having this tag using @tag syntax.";48            type = listOf str;49          };50          network = mkOption {51            type = submodule {52              options = {53                internalIps = mkOption {54                  description = "Internal ips";55                  type = listOf str;56                  default = [];57                };58                externalIps = mkOption {59                  description = "External ips";60                  type = listOf str;61                  default = [];62                };63              };64            };65            description = "Network definition of host";66          };67        };68        config = {69          nixos.networking.hostName = mkFleetGeneratorDefault config._module.args.name;70          tags = ["all"];71        };72        _file = ./meta.nix;73      });74      default = {};75      description = "Configurations of individual hosts";76    };77  };78  _file = ./meta.nix;79}
after · modules/hosts.nix
1{2  lib,3  fleetLib,4  config,5  ...6}: let7  inherit (fleetLib.modules) mkFleetGeneratorDefault;8  inherit (fleetLib.types) mkHostsType mkDataType;9  inherit (lib.options) mkOption;10  inherit (lib.types) str listOf attrsOf submodule;11  inherit (lib.attrsets) mapAttrsToList mapAttrs;12  inherit (lib.lists) flatten groupBy;13in {14  options = {15    data = mkOption {16      type = mkDataType {17        options = {18          version = mkOption {19            type = str;20            internal = true;21          };22          gcRootPrefix = mkOption {23            type = str;24            internal = true;25          };26          hosts = mkOption {27            type = attrsOf (submodule {28              options.encryptionKey = mkOption {29                type = str;30                description = "Rage SSH encryption key for secrets.";31              };32            });33          };34        };35      };36      description = ''37        Configuration provided from outside.38        Usually used to persist fleet data between runs.39      '';40    };41    taggedWith = mkOption {42      type = attrsOf (listOf str);43      internal = true;44    };45    hosts = mkOption {46      type = mkHostsType ({config, ...}: {47        options = {48          system = mkOption {49            description = "Type of the system.";50            type = str;51            example = "x86_64-linux";52          };53          tags = mkOption {54            description = "Host tag. In CLI, you can refer to all hosts having this tag using @tag syntax.";55            type = listOf str;56          };57          network = mkOption {58            type = submodule {59              options = {60                internalIps = mkOption {61                  description = "Internal ips";62                  type = listOf str;63                  default = [];64                };65                externalIps = mkOption {66                  description = "External ips";67                  type = listOf str;68                  default = [];69                };70              };71            };72            description = "Network definition of host";73          };74        };75        config = {76          nixos.networking.hostName = mkFleetGeneratorDefault config._module.args.name;77          tags = ["all"];78        };79        _file = ./meta.nix;80      });81      default = {};82      description = "Configurations of individual hosts";83    };84  };85  config.taggedWith = let86    hostTagList = flatten (mapAttrsToList (hostname: host: map (tag: {inherit hostname tag;}) host.tags) config.hosts);87    grouped = mapAttrs (_: hosts: lib.map (pair: pair.hostname) hosts) (groupBy (elem: elem.tag) hostTagList);88  in89    grouped;90  _file = ./meta.nix;91}