1{2 lib,3 fleetLib,4 config,5 ...6}:7let8 inherit (fleetLib.modules) mkFleetGeneratorDefault;9 inherit (fleetLib.types) mkHostsType mkDataType;10 inherit (lib.options) mkOption;11 inherit (lib.types)12 str13 listOf14 attrsOf15 submodule16 ;17 inherit (lib.attrsets) mapAttrsToList mapAttrs;18 inherit (lib.lists) flatten groupBy;19in20{21 2223 options = {24 data = mkOption {25 type = mkDataType {26 options = {27 version = mkOption {28 type = str;29 internal = true;30 description = "Internal version identifier for saved fleet state";31 };3233 gcRootPrefix = mkOption {34 type = str;35 internal = true;36 description = "Prefix for fleet-generated gc garbage collection roots";37 };3839 hosts = mkOption {40 type = attrsOf (submodule {41 options.encryptionKey = mkOption {42 type = str;43 description = "Rage SSH encryption key for host-bound secrets";44 };45 });46 };47 };48 };49 description = ''50 Persistent configuration data for fleet management.51 Typically used to maintain state between fleet configuration runs.52 '';53 };5455 taggedWith = mkOption {56 type = attrsOf (listOf str);57 internal = true;58 description = "Mapping of hosts grouped by tags, used by fleet CLI";59 };6061 hosts = mkOption {62 type = mkHostsType (63 { config, ... }:64 {65 options = {66 system = mkOption {67 description = "System architecture and platform identifier";68 type = str;69 example = "x86_64-linux";70 };7172 tags = mkOption {73 description = ''74 Tags for host classification.75 Used for host selection via @tag syntax in CLI tools.76 '';77 type = listOf str;78 };7980 81 network = mkOption {82 type = submodule {83 options = {84 internalIps = mkOption {85 description = "List of internal IP addresses for the host";86 type = listOf str;87 default = [ ];88 };8990 externalIps = mkOption {91 description = "List of external IP addresses for the host";92 type = listOf str;93 default = [ ];94 };95 };96 };97 };98 };99 config = {100 101 nixos.networking.hostName = mkFleetGeneratorDefault config._module.args.name;102 103 tags = [ "all" ];104 };105 _file = ./meta.nix;106 }107 );108 default = { };109 };110 };111112 113 config.taggedWith =114 let115 116 hostTagList = flatten (117 mapAttrsToList (hostname: host: map (tag: { inherit hostname tag; }) host.tags) config.hosts118 );119 120 grouped = mapAttrs (_: hosts: lib.map (pair: pair.hostname) hosts) (121 groupBy (elem: elem.tag) hostTagList122 );123 in124 grouped;125126 127 _file = ./meta.nix;128}