git.delta.rocks / jrsonnet / refs/commits / 16240ebb9bc9

difftreelog

source

modules/hosts.nix3.2 KiBsourcehistory
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  # Fleet Meta Configuration Module1516  options = {17    data = mkOption {18      type = mkDataType {19        options = {20          version = mkOption {21            type = str;22            internal = true;23            description = "Internal version identifier for saved fleet state";24          };2526          gcRootPrefix = mkOption {27            type = str;28            internal = true;29            description = "Prefix for fleet-generated gc garbage collection roots";30          };3132          hosts = mkOption {33            type = attrsOf (submodule {34              options.encryptionKey = mkOption {35                type = str;36                description = "Rage SSH encryption key for host-bound secrets";37              };38            });39          };40        };41      };42      description = ''43        Persistent configuration data for fleet management.44        Typically used to maintain state between fleet configuration runs.45      '';46    };4748    taggedWith = mkOption {49      type = attrsOf (listOf str);50      internal = true;51      description = "Mapping of hosts grouped by tags, used by fleet CLI";52    };5354    hosts = mkOption {55      type = mkHostsType ({config, ...}: {56        options = {57          system = mkOption {58            description = "System architecture and platform identifier";59            type = str;60            example = "x86_64-linux";61          };6263          tags = mkOption {64            description = ''65              Tags for host classification.66              Used for host selection via @tag syntax in CLI tools.67            '';68            type = listOf str;69          };7071          # Network configuration details72          network = mkOption {73            type = submodule {74              options = {75                internalIps = mkOption {76                  description = "List of internal IP addresses for the host";77                  type = listOf str;78                  default = [];79                };8081                externalIps = mkOption {82                  description = "List of external IP addresses for the host";83                  type = listOf str;84                  default = [];85                };86              };87            };88          };89        };90        config = {91          # Default hostname generation92          nixos.networking.hostName = mkFleetGeneratorDefault config._module.args.name;93          # Default 'all' tag for every host94          tags = ["all"];95        };96        _file = ./meta.nix;97      });98      default = {};99    };100  };101102  # Generate a mapping of hosts indexed by their tags103  config.taggedWith = let104    # Flatten host tags into a list of {hostname, tag} pairs105    hostTagList = flatten (mapAttrsToList (hostname: host: map (tag: {inherit hostname tag;}) host.tags) config.hosts);106    # Group hostnames by their tags107    grouped = mapAttrs (_: hosts: lib.map (pair: pair.hostname) hosts) (groupBy (elem: elem.tag) hostTagList);108  in109    grouped;110111  # Source file reference112  _file = ./meta.nix;113}