ctucx.git: dns.nix

fork of https://github.com/kirelagin/dns.nix

commit 065c731a43b319822bce3bd02f79d75569f7b9c1
parent cefdf0989d9fe3e5697a3c45287e0c5fb8008fa8
Author: Kirill Elagin <kirelagin@gmail.com>
Date: Sun, 10 Mar 2019 02:49:46 +0100

Do not add dots at the end of FQDNs
5 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/README.md b/README.md
@@ -15,15 +15,15 @@ Example
 ```nix
 with dns.combinators; {
   SOA = {  # Human readable names for fields
-    nameServer = "ns.test.com";
-    adminEmail = "admin@test.com";  # Email address with real `@`!
+    nameServer = "ns.test.com.";
+    adminEmail = "admin@test.com";  # Email address with a real `@`!
     serial = 2019030800;
     # Sane defaults for the remaining ones
   };
 
   NS = map ns [  # Why not `map` over your records?
-    "ns.test.com"
-    "ns2.test.com"
+    "ns.test.com."
+    "ns2.test.com."
   ];
 
   A = [

@@ -50,8 +50,8 @@ with dns.combinators; {
       A = [ (a "203.0.114.1") ];
     };
     staging = delegateTo [  # Another shortcut combinator
-      "ns1.another.com"
-      "ns2.another.com"
+      "ns1.another.com."
+      "ns2.another.com."
     ];
   };
 }
diff --git a/dns/types/records/CNAME.nix b/dns/types/records/CNAME.nix
@@ -20,5 +20,5 @@ in
       description = "A <domain-name> which specifies the canonical or primary name for the owner. The owner name is an alias";
     };
   };
-  dataToString = {cname, ...}: "${cname}.";
+  dataToString = {cname, ...}: "${cname}";
 }
diff --git a/dns/types/records/NS.nix b/dns/types/records/NS.nix
@@ -20,5 +20,5 @@ in
       description = "A <domain-name> which specifies a host which should be authoritative for the specified class and domain";
     };
   };
-  dataToString = {nsdname, ...}: "${nsdname}.";
+  dataToString = {nsdname, ...}: "${nsdname}";
 }
diff --git a/dns/types/records/SOA.nix b/dns/types/records/SOA.nix
@@ -7,7 +7,7 @@
 { pkgs }:
 
 let
-  inherit (pkgs.lib) concatStringsSep replaceStrings;
+  inherit (pkgs.lib) concatStringsSep removeSuffix replaceStrings;
   inherit (pkgs.lib) mkOption types;
 
 in

@@ -18,13 +18,13 @@ in
     nameServer = mkOption {
       type = types.str;
       example = "ns1.example.com";
-      description = "The <domain-name> of the name server that was the original or primary source of data for this zone";
+      description = "The <domain-name> of the name server that was the original or primary source of data for this zone. Don't forget the dot at the end!";
     };
     adminEmail = mkOption {
       type = types.str;
       example = "admin@example.com";
-      description = "An email address of the person responsible for this zone. (Note: in traditional zone files you are supposed to put a dot instead of `@` in your address; you can use `@` with this module and it is recommended to do so.)";
-      apply = replaceStrings ["@"] ["."];
+      description = "An email address of the person responsible for this zone. (Note: in traditional zone files you are supposed to put a dot instead of `@` in your address; you can use `@` with this module and it is recommended to do so. Also don't put the dot at the end!)";
+      apply = s: replaceStrings ["@"] ["."] (removeSuffix "." s);
     };
     serial = mkOption {
       type = types.ints.unsigned;  # TODO: u32

@@ -59,5 +59,5 @@ in
   dataToString = data@{nameServer, adminEmail, ...}:
     let
       numbers = map toString (with data; [serial refresh retry expire minimum]);
-    in "${nameServer}. ${adminEmail}. (${concatStringsSep " " numbers})";
+    in "${nameServer} ${adminEmail}. (${concatStringsSep " " numbers})";
 }
diff --git a/example.nix b/example.nix
@@ -9,14 +9,14 @@ let
 
   testZone = with dns.combinators; {
     SOA = {
-      nameServer = "ns.test.com";
+      nameServer = "ns.test.com.";
       adminEmail = "admin@test.com";
       serial = 2019030800;
     };
 
     NS = map ns [
-      "ns.test.com"
-      "ns2.test.com"
+      "ns.test.com."
+      "ns2.test.com."
     ];
 
     A = [

@@ -42,8 +42,8 @@ let
         A = map a [ "203.0.113.4" ];
       };
       staging = delegateTo [
-        "ns1.another.com"
-        "ns2.another.com"
+        "ns1.another.com."
+        "ns2.another.com."
       ];
     };
   };