Skip to content

Commit 78b1b62

Browse files
Add mkReverseRecord
Signed-off-by: Tom Hubrecht <[email protected]>
1 parent 2ad41c7 commit 78b1b62

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

dns/util/default.nix

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@ let
2323
then ''"${s}"''
2424
else concatMapStringsSep " " (x: ''"${x}"'') (splitInGroupsOf 255 s);
2525

26+
# : str -> str, with length 4 (zeros are padded to the left)
27+
align4Bytes = lib.fixedWidthString 4 "0";
28+
29+
# : int -> str -> str
30+
# Expands "" to 4n zeros and aligns the rest on 4 bytes
31+
align4BytesOrExpand = n: v:
32+
if v == ""
33+
then (lib.fixedWidthString (4*n) "0" "")
34+
else align4Bytes v;
35+
36+
# : str -> [ str ]
37+
# Returns the record of the ipv6 as a list
38+
mkRecordAux = v6:
39+
let
40+
splitted = lib.splitString ":" v6;
41+
n = 8 - builtins.length (lib.filter (x: x != "") splitted);
42+
in
43+
lib.stringToCharacters (lib.concatMapStrings (align4BytesOrExpand n) splitted);
44+
45+
# : str -> str
46+
# Returns the reversed record of the ipv6
47+
mkReverseRecord = v6:
48+
lib.concatStringsSep "." (lib.reverseList (mkRecordAux v6)) + ".ip6.arpa";
49+
2650
in {
27-
inherit writeCharacterString;
51+
inherit writeCharacterString mkReverseRecord;
2852
}

0 commit comments

Comments
 (0)