diff --git a/default.nix b/default.nix index f153abe..3665079 100644 --- a/default.nix +++ b/default.nix @@ -17,7 +17,8 @@ rec { inherit (dns) combinators evalZone - mkReverseRecord + mkIPv4ReverseRecord + mkIPv6ReverseRecord types ; diff --git a/dns/default.nix b/dns/default.nix index ef14c67..bcf406f 100644 --- a/dns/default.nix +++ b/dns/default.nix @@ -41,5 +41,5 @@ in inherit combinators; - inherit (dnslib.util) mkReverseRecord; + inherit (dnslib.util) mkIPv4ReverseRecord mkIPv6ReverseRecord; } diff --git a/dns/util/default.nix b/dns/util/default.nix index fea2dba..f0bc06b 100644 --- a/dns/util/default.nix +++ b/dns/util/default.nix @@ -35,18 +35,34 @@ let # : str -> [ str ] # Returns the record of the ipv6 as a list - mkRecordAux = v6: + mkIPv6RecordAux = v6: let - splitted = lib.splitString ":" v6; + v6' = if lib.hasPrefix "::" v6 then + "0${v6}" + else if lib.hasSuffix "::" v6 then + "${v6}0" + else + v6; + splitted = lib.splitString ":" v6'; n = 8 - builtins.length (lib.filter (x: x != "") splitted); in lib.stringToCharacters (lib.concatMapStrings (align4BytesOrExpand n) splitted); # : str -> str # Returns the reversed record of the ipv6 - mkReverseRecord = v6: - lib.concatStringsSep "." (lib.reverseList (mkRecordAux v6)) + ".ip6.arpa"; + mkIPv6ReverseRecord = v6: + lib.concatStringsSep "." (lib.reverseList (mkIPv6RecordAux v6)) + ".ip6.arpa"; + # : str -> str + # Returns the reversed record of the ipv4 + mkIPv4ReverseRecord = v4: + lib.concatStringsSep "." ( + lib.reverseList ( + lib.filter lib.isString ( + lib.splitString "." v4 + ) + ) + ) + ".in-addr.arpa"; in { - inherit writeCharacterString mkReverseRecord; + inherit writeCharacterString mkIPv4ReverseRecord mkIPv6ReverseRecord; } diff --git a/flake.nix b/flake.nix index 8ad2355..c6c8562 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,7 @@ inherit (dns) evalZone; inherit (dns) combinators; inherit (dns) types; - inherit (dns) mkReverseRecord; + inherit (dns) mkIPv4ReverseRecord mkIPv6ReverseRecord; toString = name: zone: builtins.toString (dns.evalZone name zone); } // dns.combinators;