Putting the fun back in functional programming
This commit is contained in:
@@ -6,8 +6,8 @@ in
|
||||
|
||||
# Terminaler
|
||||
demiurgen = {
|
||||
ipv4 = pvvv4 200;
|
||||
ipv6 = pvvv6 200;
|
||||
ipv4 = pvvv4 201;
|
||||
ipv6 = pvvv6 201;
|
||||
# hinfo = ["Terminal" "Debian"];
|
||||
aliases = [ "rurgen" ];
|
||||
};
|
||||
|
||||
@@ -6,57 +6,33 @@ let
|
||||
hosts = import ./hosts.nix;
|
||||
|
||||
# Normal host forward records
|
||||
hostRecords = (
|
||||
lib.mapAttrs (
|
||||
name: host:
|
||||
lib.filterAttrs (_: value: !builtins.isNull value) {
|
||||
hostRecords = lib.mapAttrs (
|
||||
_: host:
|
||||
let
|
||||
ensureList = val: if builtins.isList val || builtins.isAttrs val then val else [ val ];
|
||||
in
|
||||
lib.optionalAttrs (host ? ipv4) {
|
||||
A = ensureList host.ipv4;
|
||||
}
|
||||
// lib.optionalAttrs (host ? ipv6) {
|
||||
AAAA = ensureList host.ipv6;
|
||||
}
|
||||
) hosts;
|
||||
|
||||
A =
|
||||
if !builtins.hasAttr "ipv4" host then
|
||||
null
|
||||
else if
|
||||
builtins.elem (builtins.typeOf host.ipv4) [
|
||||
"list"
|
||||
"set"
|
||||
]
|
||||
then
|
||||
host.ipv4
|
||||
else
|
||||
[ host.ipv4 ];
|
||||
|
||||
AAAA =
|
||||
if !builtins.hasAttr "ipv6" host then
|
||||
null
|
||||
else if
|
||||
builtins.elem (builtins.typeOf host.ipv6) [
|
||||
"list"
|
||||
"set"
|
||||
]
|
||||
then
|
||||
host.ipv6
|
||||
else
|
||||
[ host.ipv6 ];
|
||||
}
|
||||
) hosts
|
||||
);
|
||||
# TODO:
|
||||
# Above can be replaced using dns.nix helpers, without support for roundrobin, custom TTL, etc;
|
||||
# (lib.mapAttrs (name: host: dns.lib.host (host.ipv4 or null) (host.ipv6 or null)) hosts)
|
||||
|
||||
# CNAMEs
|
||||
aliasRecords = builtins.listToAttrs (
|
||||
lib.concatLists (
|
||||
lib.mapAttrsToList (
|
||||
target: host:
|
||||
if (!builtins.hasAttr "aliases" host) then
|
||||
[ ]
|
||||
else
|
||||
lib.map (source: {
|
||||
name = source;
|
||||
value.CNAME = [ target ];
|
||||
}) host.aliases
|
||||
) hosts
|
||||
aliasRecords = lib.concatMapAttrs (
|
||||
target: host:
|
||||
builtins.listToAttrs (
|
||||
builtins.map (alias: {
|
||||
name = alias;
|
||||
value.CNAME = [ target ];
|
||||
}) host.aliases or [ ]
|
||||
)
|
||||
);
|
||||
) hosts;
|
||||
in
|
||||
# TODO: Merge such that an error is raised if a label exists in more than one of these sets:
|
||||
(hostRecords // aliasRecords)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
with dns.lib.combinators;
|
||||
{
|
||||
useOrigin = true; # Don't fully qualified names
|
||||
useOrigin = true; # Don't output fully qualified names
|
||||
|
||||
SOA = {
|
||||
nameServer = "dvask.pvv.ntnu.no";
|
||||
|
||||
@@ -12,16 +12,10 @@ let
|
||||
lib.concatLists (
|
||||
lib.mapAttrsToList (
|
||||
target: host:
|
||||
lib.map (
|
||||
aRecordKey:
|
||||
let
|
||||
hostOctet = builtins.elemAt (lib.splitString "." aRecordKey) 3;
|
||||
in
|
||||
{
|
||||
name = hostOctet;
|
||||
value.PTR = [ (target + domainSuffix) ];
|
||||
}
|
||||
) (lib.filter (e: lib.hasPrefix pvvv4Prefix e) (host.A or [ ]))
|
||||
lib.map (aRecordKey: {
|
||||
name = lib.removePrefix pvvv4Prefix aRecordKey;
|
||||
value.PTR = [ (target + domainSuffix) ];
|
||||
}) (lib.filter (e: lib.hasPrefix pvvv4Prefix e) (host.A or [ ]))
|
||||
) pvvHostRecords
|
||||
)
|
||||
);
|
||||
@@ -31,7 +25,7 @@ let
|
||||
};
|
||||
in
|
||||
{
|
||||
useOrigin = true; # Don't use fully qualified names
|
||||
useOrigin = true; # Don't output fully qualified names
|
||||
|
||||
SOA = {
|
||||
nameServer = "dvask.pvv.ntnu.no";
|
||||
|
||||
Reference in New Issue
Block a user