Skip to content

Commit

Permalink
imp: add "all" and "group" enum opts to hostsList
Browse files Browse the repository at this point in the history
  • Loading branch information
johnalotoski committed Mar 28, 2024
1 parent 89a5c1d commit bb6e3c2
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 86 deletions.
25 changes: 21 additions & 4 deletions flake/nixosModules/module-cardano-parts.nix
Expand Up @@ -41,11 +41,12 @@ flake @ {moduleWithSystem, ...}: {
config,
lib,
pkgs,
nodes,
...
}: let
inherit (builtins) attrNames deepSeq elem head stringLength;
inherit (lib) count filterAttrs foldl' mapAttrsToList mdDoc mapAttrs' mkIf mkOption nameValuePair pipe recursiveUpdate types;
inherit (types) anything attrsOf bool enum ints listOf package port nullOr str submodule;
inherit (lib) count filterAttrs foldl' isList mapAttrsToList mdDoc mapAttrs' mkIf mkOption nameValuePair pipe recursiveUpdate types;
inherit (types) anything attrsOf bool enum ints listOf oneOf package port nullOr str submodule;
inherit (cfg.group) groupFlake;
inherit (cfgPerNode.lib) topologyLib;

Expand Down Expand Up @@ -229,11 +230,17 @@ flake @ {moduleWithSystem, ...}: {
};

hostsList = mkOption {
type = listOf str;
type = oneOf [(enum ["all" "group"]) (listOf str)];
description = mdDoc ''
A list of Colmena machine names for which /etc/hosts will be configured for if
nixosModule.ip-module is available in the downstream repo and module-cardano-parts
nixosModule is imported.
If instead of a list, this option is configured with a string of "all", all
Colmena machine names in the cluster will be used for the /etc/hosts file.
If configured with a string of "group" then all Colmena machine names in the
same group will be used for the /etc/hosts file.
'';
default = cfg.group.meta.hostsList;
};
Expand Down Expand Up @@ -280,13 +287,23 @@ flake @ {moduleWithSystem, ...}: {
config = {
# The hosts file is case-insensitive, so switch from camelCase attr name to kebab-case
networking.hosts = mkIf (groupFlake.config.flake.nixosModules ? ips) (let
hostsList =
# See hostsList type and description above
# If hostsList is a list, use it directly
if isList cfgPerNode.meta.hostsList
then cfgPerNode.meta.hostsList
# If hostsList is a string of "all", use all machines, otherwise for "group" use group machines
else if cfgPerNode.meta.hostsList == "all"
then attrNames nodes
else topologyLib.groupMachines nodes;

genHostsType = type: suffix:
pipe (head groupFlake.config.flake.nixosModules.ips.imports) [
# Filter empty values
(filterAttrs (_: v: v.${type} != ""))

# Filter by hosts filter
(filterAttrs (n: _: elem n cfgPerNode.meta.hostsList))
(filterAttrs (n: _: elem n hostsList))

# Abort on any duplicated ips across multiple machines
(ipAttrs:
Expand Down
169 changes: 87 additions & 82 deletions flakeModules/cluster.nix
Expand Up @@ -62,7 +62,7 @@ flake @ {
...
}: let
inherit (lib) mdDoc mkDefault mkOption types;
inherit (types) addCheck anything attrsOf enum functionTo listOf nullOr package port raw str submodule;
inherit (types) addCheck anything attrsOf enum functionTo listOf nullOr oneOf package port raw str submodule;

cfg = config.flake.cardano-parts;
cfgAws = cfg.cluster.infra.aws;
Expand Down Expand Up @@ -222,7 +222,7 @@ flake @ {
groupSubmodule = submodule ({name, ...}: {
options = {
meta = mkOption {
type = metaSubmodule name;
type = metaSubmodule;
description = mdDoc "Cardano-parts cluster group meta submodule.";
default = {};
};
Expand Down Expand Up @@ -345,101 +345,106 @@ flake @ {
};
};

metaSubmodule = groupName:
submodule {
options = {
addressType = mkOption {
type = enum ["fqdn" "namePrivateIpv4" "namePublicIpv4" "privateIpv4" "publicIpv4"];
description = mdDoc "Cardano-parts cluster group default addressType for topologyLib mkProducer function.";
default =
if flake.config.flake.nixosModules ? ips
then "namePublicIpv4"
else "fqdn";
};
metaSubmodule = submodule {
options = {
addressType = mkOption {
type = enum ["fqdn" "namePrivateIpv4" "namePublicIpv4" "privateIpv4" "publicIpv4"];
description = mdDoc "Cardano-parts cluster group default addressType for topologyLib mkProducer function.";
default =
if flake.config.flake.nixosModules ? ips
then "namePublicIpv4"
else "fqdn";
};

cardanoDbSyncPrometheusExporterPort = mkOption {
type = port;
description = mdDoc "Cardano-parts cluster group cardanoDbSyncPrometheusExporterPort.";
default = 8080;
};
cardanoDbSyncPrometheusExporterPort = mkOption {
type = port;
description = mdDoc "Cardano-parts cluster group cardanoDbSyncPrometheusExporterPort.";
default = 8080;
};

cardanoNodePort = mkOption {
type = port;
description = mdDoc "Cardano-parts cluster group cardanoNodePort.";
default = 3001;
};
cardanoNodePort = mkOption {
type = port;
description = mdDoc "Cardano-parts cluster group cardanoNodePort.";
default = 3001;
};

cardanoNodePrometheusExporterPort = mkOption {
type = port;
description = mdDoc "Cardano-parts cluster group cardanoNodePrometheusExporterPort.";
default = 12798;
};
cardanoNodePrometheusExporterPort = mkOption {
type = port;
description = mdDoc "Cardano-parts cluster group cardanoNodePrometheusExporterPort.";
default = 12798;
};

cardanoSmashDelistedPools = mkOption {
type = listOf str;
description = mdDoc "Cardano-parts cluster group cardano-smash delisted pools.";
default = [];
};
cardanoSmashDelistedPools = mkOption {
type = listOf str;
description = mdDoc "Cardano-parts cluster group cardano-smash delisted pools.";
default = [];
};

cardano-db-sync-service = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-db-sync-service import path string.";
default = cfg.pkgs.special.cardano-db-sync-service;
};
cardano-db-sync-service = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-db-sync-service import path string.";
default = cfg.pkgs.special.cardano-db-sync-service;
};

cardano-faucet-service = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-faucet-service import path string.";
default = cfg.pkgs.special.cardano-faucet-service;
};
cardano-faucet-service = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-faucet-service import path string.";
default = cfg.pkgs.special.cardano-faucet-service;
};

cardano-metadata-service = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-metadata-service import path string.";
default = cfg.pkgs.special.cardano-metadata-service;
};
cardano-metadata-service = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-metadata-service import path string.";
default = cfg.pkgs.special.cardano-metadata-service;
};

cardano-node-service = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-node-service import path string.";
default = cfg.pkgs.special.cardano-node-service;
};
cardano-node-service = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-node-service import path string.";
default = cfg.pkgs.special.cardano-node-service;
};

cardano-node-service-ng = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-node-service-ng import path string.";
default = cfg.pkgs.special.cardano-node-service-ng;
};
cardano-node-service-ng = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-node-service-ng import path string.";
default = cfg.pkgs.special.cardano-node-service-ng;
};

cardano-smash-service = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-smash-service import path string.";
default = cfg.pkgs.special.cardano-smash-service;
};
cardano-smash-service = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group cardano-smash-service import path string.";
default = cfg.pkgs.special.cardano-smash-service;
};

domain = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group domain.";
default = cfgAws.domain;
};
domain = mkOption {
type = str;
description = mdDoc "Cardano-parts cluster group domain.";
default = cfgAws.domain;
};

environmentName = mkOption {
type = nullOr str;
description = mdDoc "Cardano-parts cluster group environmentName.";
default = "custom";
};
environmentName = mkOption {
type = nullOr str;
description = mdDoc "Cardano-parts cluster group environmentName.";
default = "custom";
};

hostsList = mkOption {
type = listOf str;
description = mdDoc ''
A list of Colmena machine names for which /etc/hosts will be configured for if
nixosModule.ip-module is available in the downstream repo and module-cardano-parts
nixosModule is imported.
'';
default = (cfg.lib.topologyLib cfg.cluster.groups.${groupName}).groupMachines (flake.self.nixosConfigurations or {});
};
hostsList = mkOption {
type = oneOf [(enum ["all" "group"]) (listOf str)];
description = mdDoc ''
A list of Colmena machine names for which /etc/hosts will be configured for if
nixosModule.ip-module is available in the downstream repo and module-cardano-parts
nixosModule is imported.
If instead of a list, this option is configured with a string of "all", all
Colmena machine names in the cluster will be used for the /etc/hosts file.
If configured with a string of "group" then all Colmena machine names in the
same group will be used for the /etc/hosts file.
'';
default = "group";
};
};
};

pkgsSubmodule = submodule {
options = {
Expand Down

0 comments on commit bb6e3c2

Please sign in to comment.