entities/lib.nix

35 lines
1.1 KiB
Nix

{ lib, entities, ... }:
with lib;
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}";
getHostRealm = hostname: (getHostDomain hostname).gssapi-realm;
getHostFqdn = hostname:
let hostDomain = entities.hosts."${hostname}".domain;
in "${hostname}.${hostDomain}";
getHostNetworkSettings = hostname:
let
hostDomain = entities.hosts."${hostname}".domain;
hostNetwork = entities.zones."${hostDomain}";
in hostNetwork.hosts."${hostname}";
getIfAttr = as: a: if hasAttr as a then getAttr as a else null;
getHostIpv4 = hostname:
getIfAttr "ipv4-address" (getHostNetworkSettings hostname);
getHostIpv6 = hostname:
getIfAttr "ipv6-address" (getHostNetworkSettings hostname);
getHostIps = hostname:
filter (o: o != null) [ (getHostIpv4 hostname) (getHostIpv6 hostname) ];
in {
inherit getHostSite getHostDomain getHostRealm getHostFqdn getHostIpv4
getHostIpv6 getHostIps;
}