ctucx.git: dns.nix

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

commit b9e26974dc4b1d1451f528d4453e604ade612b15
parent d622906683a75fd7293bc479fe8956f2a63093ca
Author: Kirill Elagin <kirelagin@gmail.com>
Date: Sun, 10 Mar 2019 04:29:18 +0100

fix: Fix and cleanup subzone name handling
3 files changed, 8 insertions(+), 17 deletions(-)
M
README.md
|
5
++---
M
dns/types/zone.nix
|
19
+++++--------------
M
example.nix
|
1
+
diff --git a/README.md b/README.md
@@ -46,9 +46,8 @@ with dns.combinators; {
   ];
 
   subdomains = {
-    www = {
-      A = [ (a "203.0.114.1") ];
-    };
+    www.A = [ (a "203.0.114.1") ];
+
     staging = delegateTo [  # Another shortcut combinator
       "ns1.another.com."
       "ns2.another.com."
diff --git a/dns/types/zone.nix b/dns/types/zone.nix
@@ -19,7 +19,7 @@ let
 
   subzoneOptions = name: {
     subdomains = mkOption {
-      type = types.attrsOf subzone;
+      type = types.attrsOf (subzone name);
       default = {};
       example = {
         www = {

@@ -30,16 +30,6 @@ let
         };
       };
       description = "Records for subdomains of the domain";
-      apply =  # Fixup names of subrecords. Don’t ask!
-        let
-          fixupSubzones =
-            mapAttrs (_dn: if _dn != "_module"  then fixupSubzone else id);
-          fixupSubzone =
-            mapAttrs (_rt: if hasAttr _rt recordTypes' then fixupRecords else id);
-          fixupRecords =
-            map (r: r // { name = "${r.name}.${name}"; });
-        in
-          fixupSubzones;
     };
   } //
     mapAttrs (n: t: mkOption rec {

@@ -49,9 +39,10 @@ let
       description = "List of ${t} records for this zone/subzone";
     }) recordTypes';
 
-  subzone = types.submodule ({name, ...}: {
-    options = subzoneOptions name;
-  });
+  subzone = pname:
+    types.submodule ({name, ...}: {
+      options = subzoneOptions "${name}.${pname}";
+    });
 
   writeSubzone = zone:
     let
diff --git a/example.nix b/example.nix
@@ -53,6 +53,7 @@ let
         "ns1.another.com."
         "ns2.another.com."
       ];
+      foo.subdomains.www.CNAME = map cname [ "foo.test.com" ];
     };
   };
 in