Skip to content

Commit a47a6a7

Browse files
authored
Merge pull request #14 from Janik-Haag/develop
fix: txt records for too long values
2 parents 1cf30ea + 0bcdf6d commit a47a6a7

File tree

6 files changed

+123
-15
lines changed

6 files changed

+123
-15
lines changed

.github/workflows/ci.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ jobs:
2929
run: nix build .#docs
3030

3131
- name: "Try building example"
32-
run: nix build ./example#octodns
32+
run: nix build --override-input nixos-dns $(pwd)/ ./example#octodns
33+
34+
- name: "Check zonefile with bind"
35+
run: nix build --override-input nixos-dns $(pwd)/ ./example#zoneFiles && nix shell nixpkgs#bind --command named-checkzone example.com result/example.com

example/dns.nix

+18
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,32 @@
33
zones = {
44
"example.com" = {
55
"" = {
6+
soa = {
7+
data = {
8+
rname = "admin.example.invalid";
9+
mname = "ns.example.invalid";
10+
serial = 1970010100;
11+
refresh = 7200;
12+
retry = 3600;
13+
ttl = 60;
14+
expire = 1209600;
15+
};
16+
};
617
ns = {
718
data = [
819
"ns1.invalid"
920
"ns2.invalid"
1021
"ns3.invalid"
1122
];
1223
};
24+
txt = {
25+
data = [
26+
"meow"
27+
"v=spf1 a:mail.example.com -all"
28+
];
29+
};
1330
};
31+
"mail._domainkey".txt.data = "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2WJ46bl9UqBY9ZxqkVCBdSiysIJMUbWS3BK10Lupe4T5+jWAcdzJraznWeaVF/mR/9TyiB7lE79ZB6WxHxTwwJ5UZjURwImKAKqSGPXPACIj+LHyx5j2nHN4CawC6bkCmpGT99B7I/5bCelekoAHV9U/4pE2YEjgA0VxvlSKHB2Y7cPWL303DInYGaTrvMczuwLYoEwIiBirffYNqHyrOJE9A+ZQRdLjM8DFOxegAOV9mcHb3MwneJuu86Czz45UIrQ7AxkMUNKgHitqTSnXzLWd4BF6Kf3XUh/lED7WPdviBLJo/1H0Cgch8RRlinTeDVliHDQ6/zLWpk6+k3iKkQIDAQAB; s=*;";
1432
};
1533
"example.net" = {
1634
"" = {

example/flake.lock

+44-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/tests/zonefiles.nix

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
utils,
55
}:
66
{
7+
testFormatTxtRecordShorter255 = {
8+
expr = utils.zonefiles.formatTxtRecord "meow";
9+
expected = "\"meow\"";
10+
};
11+
testFormatTxtRecordLonger255 = {
12+
expr = utils.zonefiles.formatTxtRecord "v=DKIM1; k=rsa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc";
13+
expected = "\"v=DKIM1; k=rsa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" \"aaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\" \"bbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\" \"ccccccccccccccc\"";
14+
};
715
testWriteZoneFile = {
816
expr = builtins.readFile (
917
utils.zonefiles.write "example.com" {

utils/zonefiles.nix

+43-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
{ lib, utils }:
22
{
33
/*
4+
Converts a string into a valid txt record so it's compliant with RFC 4408
5+
This means it splits the string every 255 chars and surrounds it with quotation marks
6+
7+
Type:
8+
utils.zonefiles.formatTxtRecord :: String -> String
9+
*/
10+
formatTxtRecord =
11+
# The String of a txt resource record
12+
txtString:
13+
let
14+
format =
15+
{
16+
acc ? [ ],
17+
chars,
18+
}:
19+
let
20+
rest = [ (lib.concatStrings (lib.take 255 chars)) ];
21+
in
22+
if (lib.length chars) > 255 then
23+
format {
24+
acc = acc ++ rest;
25+
chars = lib.drop 255 chars;
26+
}
27+
else if acc != [ ] then
28+
acc ++ rest
29+
else
30+
rest;
31+
resolve = lib.concatStringsSep "\" \"" (format {
32+
chars = lib.stringToCharacters txtString;
33+
});
34+
in
35+
"\"${resolve}\"";
36+
37+
/*
38+
attributeset
439
Takes any record from the module and converts it to a fitting zonefile string
540
641
Type:
@@ -24,10 +59,17 @@
2459
else if record == "soa" then
2560
"SOA ${value.mname}. ${value.rname}. ( ${builtins.toString value.serial} ${builtins.toString value.refresh} ${builtins.toString value.retry} ${builtins.toString value.expire} ${builtins.toString value.ttl} )"
2661
else if record == "txt" then
27-
"TXT \"${value}\""
62+
"TXT ${utils.zonefiles.formatTxtRecord value}"
2863
else
2964
"${lib.toUpper record} ${value}";
65+
/*
66+
Converts a zone attributeset into a zonefile and returns a multiline string
67+
68+
Type:
69+
utils.zonefiles.mkZoneString :: Attr -> String
70+
*/
3071
mkZoneString =
72+
# Takes dnsConfig."your-domain.invalid"
3173
entries:
3274
''${lib.concatLines (
3375
lib.flatten (

0 commit comments

Comments
 (0)