entities/lib.nix

38 lines
1.2 KiB
Nix
Raw Normal View History

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
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;
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) ];
getDomainPostgresqlServer = domain:
getHostFqdn entities.domains."${domain}".postgresql-server;
2023-03-01 10:13:31 -08:00
2023-01-26 13:36:10 -08:00
in {
inherit getHostSite getHostDomain getHostRealm getHostFqdn getHostIpv4
2023-03-01 10:13:31 -08:00
getHostIpv6 getHostIps getDomainPostgresqlServer;
2023-01-26 13:36:10 -08:00
}