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:
|
|
|
|
let site = config.fudo.sites."${siteName}";
|
|
|
|
in if hasAttr "local-gateway" site then getHostIpv4 else site.gateway-v4;
|
2023-11-13 18:09:11 -08:00
|
|
|
|
2023-11-14 08:51:36 -08:00
|
|
|
getHostGatewayV4 = hostname:
|
|
|
|
getSiteGatewayV4 config.fudo.hosts."${hostname}".site;
|
|
|
|
|
|
|
|
getSiteGatewayV6 = siteName:
|
|
|
|
let site = config.fudo.sites."${siteName}";
|
|
|
|
in if hasAttr "local-gateway" site then getHostIpv6 else site.gateway-v6;
|
|
|
|
|
|
|
|
getHostGatewayV6 = hostname:
|
|
|
|
getSiteGatewayV6 config.fudo.hosts."${hostname}".site;
|
2023-11-13 18:09:11 -08:00
|
|
|
|
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
|
|
|
|
getSiteGateway getHostGateway;
|
2023-01-26 13:36:10 -08:00
|
|
|
}
|