diff --git a/hosts.nix b/hosts.nix index 42df339..64664da 100644 --- a/hosts.nix +++ b/hosts.nix @@ -1,7 +1,8 @@ let pvvv4 = hostPart: "129.241.210.${toString hostPart}"; pvvv6 = hostPart: "2001:700:300:1900::${toString hostPart}"; -in { +in +{ # Terminaler demiurgen = { @@ -29,7 +30,13 @@ in { }; roundrobin = { - ipv4 = [ (pvvv4 201) (pvvv4 202) ]; - ipv6 = [ (pvvv6 201) (pvvv6 202) ]; + ipv4 = [ + (pvvv4 201) + (pvvv4 202) + ]; + ipv6 = [ + (pvvv6 201) + (pvvv6 202) + ]; }; } diff --git a/pvv-subdomains.nix b/pvv-subdomains.nix index 887ea01..4626689 100644 --- a/pvv-subdomains.nix +++ b/pvv-subdomains.nix @@ -6,37 +6,57 @@ let hosts = import ./hosts.nix; # Normal host forward records - hostRecords = - (lib.mapAttrs ( + hostRecords = ( + lib.mapAttrs ( name: host: lib.filterAttrs (_: value: !builtins.isNull value) { - 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); - # 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 [ ] + A = + if !builtins.hasAttr "ipv4" host then + null + else if + builtins.elem (builtins.typeOf host.ipv4) [ + "list" + "set" + ] + then + host.ipv4 else - lib.map (source: { - name = source; - value.CNAME = [ target ]; - }) host.aliases - ) hosts - ) ); + [ 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 + ); + # 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 + ) + ); in - # TODO: Merge such that an error is raised if a label exists in more than one of these sets: - ( hostRecords // aliasRecords ) +# TODO: Merge such that an error is raised if a label exists in more than one of these sets: +(hostRecords // aliasRecords) diff --git a/zoneConfig.nix b/zoneConfig.nix index 8d1b3b5..4b547c6 100644 --- a/zoneConfig.nix +++ b/zoneConfig.nix @@ -22,12 +22,11 @@ stdenvNoCC.mkDerivation { name = "zoneConfig"; dontUnpack = true; - installPhase = - '' - mkdir -p $out/zones + installPhase = '' + mkdir -p $out/zones - '' - + (lib.concatMapAttrsStringSep "\n" (name: path: "cp ${path} $out/zones/${name}.zone") zoneConfigs); + '' + + (lib.concatMapAttrsStringSep "\n" (name: path: "cp ${path} $out/zones/${name}.zone") zoneConfigs); # TODO: Write named.conf to include the zones, set allow-transfer, etc. } diff --git a/zones/pvv.ntnu.no.nix b/zones/pvv.ntnu.no.nix index 0a19646..c8f1319 100644 --- a/zones/pvv.ntnu.no.nix +++ b/zones/pvv.ntnu.no.nix @@ -19,9 +19,8 @@ in CNAME = [ "www.pvv.ntnu.no" ]; - subdomains = - pvvHostRecords - // { # Override with custom / additional subdomains - "_dmarc".TXT = [ "v=DMARC1; p=quarantine; fo=1;" ]; # TODO: Better example, as dns.nix has the DMARC type - }; + subdomains = pvvHostRecords // { + # Override with custom / additional subdomains + "_dmarc".TXT = [ "v=DMARC1; p=quarantine; fo=1;" ]; # TODO: Better example, as dns.nix has the DMARC type + }; } diff --git a/zones/pvv.org.nix b/zones/pvv.org.nix index 6c98f5d..51ad83e 100644 --- a/zones/pvv.org.nix +++ b/zones/pvv.org.nix @@ -19,9 +19,8 @@ in CNAME = [ "www.pvv.org" ]; - subdomains = - pvvHostRecords - // { # Override with custom / additional subdomains + subdomains = pvvHostRecords // { + # Override with custom / additional subdomains - }; + }; } diff --git a/zones/reverse-ipv4-parent.nix b/zones/reverse-ipv4-parent.nix index 227beb7..a9122d6 100644 --- a/zones/reverse-ipv4-parent.nix +++ b/zones/reverse-ipv4-parent.nix @@ -15,31 +15,37 @@ with dns.lib.combinators; "nn.unintett.no" ]; - subdomains = let - # $GENERATE 0-127 $ CNAME $.0-127 - nvgRedirects = builtins.listToAttrs ( builtins.genList (n: - { name = toString n; value.CNAME = [ "${toString n}.0-127" ]; } - ) 127); + subdomains = + let + # $GENERATE 0-127 $ CNAME $.0-127 + nvgRedirects = builtins.listToAttrs ( + builtins.genList (n: { + name = toString n; + value.CNAME = [ "${toString n}.0-127" ]; + }) 127 + ); - # $GENERATE 128-255 $ CNAME $.128-255 - pvvRedirects = builtins.listToAttrs ( builtins.genList (n: - { name = toString (n+128); value.CNAME = [ "${toString (n+128)}.128-255" ]; } - ) 127); - in { - # 129.241.210.0/25 delegated to NVGs NS - "0-127" = { - NS = [ + # $GENERATE 128-255 $ CNAME $.128-255 + pvvRedirects = builtins.listToAttrs ( + builtins.genList (n: { + name = toString (n + 128); + value.CNAME = [ "${toString (n + 128)}.128-255" ]; + }) 127 + ); + in + { + # 129.241.210.0/25 delegated to NVGs NS + "0-127".NS = [ "swix.nvg.ntnu.no" "nn.uninett.no" ]; - }; - # 129.241.210.128/25 delegated to PVVs NS - "128-255" = { - NS = [ + # 129.241.210.128/25 delegated to PVVs NS + "128-255".NS = [ "dvask.pvv.ntnu.no" "nn.uninett.no" ]; - }; - } // nvgRedirects // pvvRedirects; + } + // nvgRedirects + // pvvRedirects; } diff --git a/zones/reverse-ipv4.nix b/zones/reverse-ipv4.nix index c056509..60818fb 100644 --- a/zones/reverse-ipv4.nix +++ b/zones/reverse-ipv4.nix @@ -9,16 +9,22 @@ let # Find all the A-records pointing into the PVV-network, and generate the opposing PTR records # TODO: Handle duplicates? Avoid NVG-IPs? pvvHostReverseRecords = builtins.listToAttrs ( - lib.concatLists ( - lib.mapAttrsToList ( target: host: - lib.map - (aRecordKey: 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 [])) - ) pvvHostRecords - ) - ); + in + { + name = hostOctet; + value.PTR = [ (target + domainSuffix) ]; + } + ) (lib.filter (e: lib.hasPrefix pvvv4Prefix e) (host.A or [ ])) + ) pvvHostRecords + ) + ); additionalReverseRecords = { "129".PTR = [ "el-swd.nettel.ntnu.no." ]; # Gateway router/switch