git.delta.rocks / jrsonnet / refs/commits / 3e7b063c34a7

difftreelog

source

modules/hosts.nix2.6 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  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}