2023-01-17 13:30:45 -08:00
|
|
|
{ lib, entities, ... }:
|
|
|
|
|
2023-01-26 13:41:09 -08:00
|
|
|
with lib;
|
2023-01-17 13:30:45 -08:00
|
|
|
let
|
2023-01-17 13:42:50 -08:00
|
|
|
getHostSite = hostname:
|
|
|
|
let site-name = entities.hosts."${hostname}".site;
|
|
|
|
in entities.sites."${site-name}";
|
|
|
|
getHostDomain = hostname:
|
|
|
|
let domain-name = entities.hosts."${hostname}".domain;
|
|
|
|
in entities.domains."${domain-name}";
|
2023-01-17 13:30:45 -08:00
|
|
|
getHostRealm = hostname: (getHostDomain hostname).gssapi-realm;
|
2023-01-18 12:54:21 -08:00
|
|
|
getHostFqdn = hostname:
|
|
|
|
let hostDomain = entities.hosts."${hostname}".domain;
|
|
|
|
in "${hostname}.${hostDomain}";
|
2023-01-17 13:30:45 -08:00
|
|
|
|
2023-01-26 13:36:10 -08:00
|
|
|
getHostNetworkSettings = hostname:
|
|
|
|
let
|
|
|
|
hostDomain = entities.hosts."${hostname}".domain;
|
|
|
|
hostNetwork = entities.zones."${hostDomain}";
|
|
|
|
in hostNetwork.hosts."${hostname}";
|
|
|
|
|
2023-01-26 13:47:43 -08:00
|
|
|
getIfAttr = as: a: if hasAttr as a then getAttr as a else null;
|
|
|
|
|
|
|
|
getHostIpv4 = hostname:
|
2023-01-26 14:03:26 -08:00
|
|
|
getIfAttr "ipv4-address" (getHostNetworkSettings hostname);
|
2023-01-26 13:47:43 -08:00
|
|
|
getHostIpv6 = hostname:
|
2023-01-26 14:03:26 -08:00
|
|
|
getIfAttr "ipv6-address" (getHostNetworkSettings hostname);
|
2023-01-26 13:42:59 -08:00
|
|
|
getHostIps = hostname:
|
2023-01-26 13:36:10 -08:00
|
|
|
filter (o: o != null) [ (getHostIpv4 hostname) (getHostIpv6 hostname) ];
|
|
|
|
|
2023-03-03 16:06:48 -08:00
|
|
|
getDomainPostgresqlServer = domain:
|
|
|
|
getHostFqdn entities.domains."${domain}".postgresql-server;
|
2023-03-01 10:13:31 -08:00
|
|
|
|
2023-11-03 11:38:58 -07:00
|
|
|
getSiteHosts = site:
|
|
|
|
attrNames (filterAttrs (_: hostOpts: hostOpts.site == site) entities.hosts);
|
|
|
|
getDomainHosts = domain:
|
|
|
|
attrNames
|
2023-11-03 11:40:46 -07:00
|
|
|
(filterAttrs (_: hostOpts: hostOpts.domain == domain) entities.hosts);
|
2023-11-13 18:09:11 -08:00
|
|
|
|
2023-11-14 08:51:36 -08:00
|
|
|
getSiteGatewayV4 = siteName:
|
2023-11-14 08:57:18 -08:00
|
|
|
let site = entities.sites."${siteName}";
|
2023-11-14 09:00:57 -08:00
|
|
|
in if hasAttr "local-gateway" site then
|
|
|
|
getHostIpv4 site.local-gateway
|
|
|
|
else
|
|
|
|
site.gateway-v4;
|
2023-11-13 18:09:11 -08:00
|
|
|
|
2023-11-14 08:51:36 -08:00
|
|
|
getHostGatewayV4 = hostname:
|
2023-11-14 08:57:18 -08:00
|
|
|
getSiteGatewayV4 entities.hosts."${hostname}".site;
|
2023-11-14 08:51:36 -08:00
|
|
|
|
|
|
|
getSiteGatewayV6 = siteName:
|
2023-11-14 08:57:18 -08:00
|
|
|
let site = entities.sites."${siteName}";
|
2023-11-14 09:00:57 -08:00
|
|
|
in if hasAttr "local-gateway" site then
|
|
|
|
getHostIpv6 site.local-gateway
|
|
|
|
else
|
|
|
|
site.gateway-v6;
|
2023-11-14 08:51:36 -08:00
|
|
|
|
|
|
|
getHostGatewayV6 = hostname:
|
2023-11-14 08:57:18 -08:00
|
|
|
getSiteGatewayV6 entities.hosts."${hostname}".site;
|
2023-11-13 18:09:11 -08:00
|
|
|
|
2023-11-15 12:39:47 -08:00
|
|
|
getSiteNetwork = siteName: entities.sites."${siteName}".network;
|
|
|
|
|
|
|
|
getSiteV4PrefixLength = siteName:
|
2023-11-17 11:12:20 -08:00
|
|
|
toInt (elemAt (splitString "/" (getSiteNetwork siteName)) 1);
|
2023-11-15 12:39:47 -08:00
|
|
|
|
|
|
|
getSiteV6PrefixLength = siteName:
|
|
|
|
abort "not implemented: getSiteV6PrefixLength";
|
|
|
|
|
2023-01-26 13:36:10 -08:00
|
|
|
in {
|
|
|
|
inherit getHostSite getHostDomain getHostRealm getHostFqdn getHostIpv4
|
2023-11-13 18:09:11 -08:00
|
|
|
getHostIpv6 getHostIps getDomainPostgresqlServer getSiteHosts getDomainHosts
|
2023-11-15 12:39:47 -08:00
|
|
|
getSiteGatewayV4 getHostGatewayV4 getSiteGatewayV6 getHostGatewayV6
|
|
|
|
getSiteV4PrefixLength getSiteV6PrefixLength;
|
2023-11-16 10:02:42 -08:00
|
|
|
|
2023-11-17 11:05:58 -08:00
|
|
|
fudo-types = with lib.types; {
|
|
|
|
networkHost.options = {
|
2023-11-17 10:06:04 -08:00
|
|
|
hostname = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Hostname";
|
|
|
|
};
|
|
|
|
|
|
|
|
ipv4-address = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
description = "The V4 IP of a given host, if any.";
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
ipv6-address = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
description = "The V6 IP of a given host, if any.";
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
mac-address = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
description =
|
|
|
|
"The MAC address of a given host, if desired for IP reservation.";
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
description = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
description = "Description of the host.";
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
sshfp-records = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
description = "List of SSHFP records for this host.";
|
|
|
|
default = [ ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networkHosts = let
|
|
|
|
# This is necessary because of the default 'name'...sigh.
|
|
|
|
networkHostOpt = { name, ... }: {
|
2023-11-17 11:05:58 -08:00
|
|
|
options = {
|
|
|
|
hostname = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Hostname";
|
|
|
|
default = name;
|
|
|
|
};
|
|
|
|
|
|
|
|
ipv4-address = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
description = "The V4 IP of a given host, if any.";
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
ipv6-address = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
description = "The V6 IP of a given host, if any.";
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
mac-address = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
description =
|
|
|
|
"The MAC address of a given host, if desired for IP reservation.";
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
description = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
description = "Description of the host.";
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
sshfp-records = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
description = "List of SSHFP records for this host.";
|
|
|
|
default = [ ];
|
|
|
|
};
|
2023-11-16 16:33:14 -08:00
|
|
|
};
|
|
|
|
};
|
2023-11-17 10:06:04 -08:00
|
|
|
in attrsOf (submodule networkHostOpt);
|
2023-11-16 10:02:42 -08:00
|
|
|
};
|
2023-01-26 13:36:10 -08:00
|
|
|
}
|