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
|
|
|
|
(filterAttrs (_: hostOpts: hostOpts.domain == domain) entities.domain);
|
2023-01-26 13:36:10 -08:00
|
|
|
in {
|
|
|
|
inherit getHostSite getHostDomain getHostRealm getHostFqdn getHostIpv4
|
2023-11-03 11:38:58 -07:00
|
|
|
getHostIpv6 getHostIps getDomainPostgresqlServer getSiteHosts
|
|
|
|
getDomainHosts;
|
2023-01-26 13:36:10 -08:00
|
|
|
}
|