ctucx.git: dns.nix

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

commit 6d8fc64452948048710ca70f57369580259ae96f
parent 262c366c0f277d447731ffb5d5d6b2531bd49f36
Author: Kirill Elagin <kirelagin@gmail.com>
Date: Fri, 8 Mar 2019 20:14:25 +0100

Clean up evaluation and derivation logic
2 files changed, 51 insertions(+), 51 deletions(-)
M
default.nix
|
75
++++++++++++++++++++++++++++-----------------------------------------------
M
dns/default.nix
|
27
+++++++++++++++++++++++----
diff --git a/default.nix b/default.nix
@@ -7,59 +7,40 @@
 { pkgs ? import <nixpkgs> {} }:
 
 let
-  inherit (pkgs) lib;
   dns = import ./dns { inherit pkgs; };
 
-  module = {
-    options = {
-      zones = lib.mkOption {
-        type = lib.types.attrsOf dns.types.zone;
-        default = {};
-        description = "DNS zones";
-      };
+  testZone = {
+    SOA = {
+      nameServer = "ns.test.com";
+      adminEmail = "admin@test.com";
+      serial = 2019030800;
     };
-  };
-
-  testZones = {
-    "test.com" = {
-      SOA = {
-        nameServer = "ns.test.com";
-        adminEmail = "admin@test.com";
-        serial = 2019030800;
-      };
 
-      NS = [
-        { nsdname = "ns.test.com"; }
-        { nsdname = "ns2.test.com"; }
-      ];
-
-      A = [
-        { address = "1.1.1.1"; ttl = 60 * 60; }
-        { address = "1.0.0.1"; ttl = 60 * 60; }
-      ];
+    NS = [
+      { nsdname = "ns.test.com"; }
+      { nsdname = "ns2.test.com"; }
+    ];
 
-      CAA = [
-        { issuerCritical = false;
-          tag = "issue";
-          value = "letsencrypt.org";
-        }
-        { issuerCritical = false;
-          tag = "issuewild";
-          value = ";";
-        }
-        { issuerCritical = false;
-          tag = "iodef";
-          value = "mailto:admin@example.com";
-        }
-      ];
-    };
-  };
+    A = [
+      { address = "1.1.1.1"; ttl = 60 * 60; }
+      { address = "1.0.0.1"; ttl = 60 * 60; }
+    ];
 
-  testConfig = (lib.evalModules {
-    modules = [
-      (module // { config = { zones = testZones; }; })
+    CAA = [
+      { issuerCritical = false;
+        tag = "issue";
+        value = "letsencrypt.org";
+      }
+      { issuerCritical = false;
+        tag = "issuewild";
+        value = ";";
+      }
+      { issuerCritical = false;
+        tag = "iodef";
+        value = "mailto:admin@example.com";
+      }
     ];
-  }).config;
+  };
 in
 
-dns.mkZone "test.com" (testConfig.zones."test.com")
+dns.writeZone "test.com" testZone
diff --git a/dns/default.nix b/dns/default.nix
@@ -7,15 +7,34 @@
 { pkgs }:
 
 let
-  mkZone = name: zone:
+  inherit (pkgs) lib;
+  types = import ./types { inherit pkgs; };
+
+  evalZone = name: zone:
+    (lib.evalModules {
+      modules = [
+        { options = {
+            zones = lib.mkOption {
+              type = lib.types.attrsOf types.zone;
+              description = "DNS zones";
+            };
+          };
+          config = {
+            zones = { "${name}" = zone; };
+          };
+        }
+      ];
+    }).config.zones."${name}";
+
+  writeZone = name: zone:
     pkgs.writeTextFile {
       name = "${name}.zone";
-      text = toString zone + "\n";
+      text = toString (evalZone name zone) + "\n";
     };
 in
 
 {
-  inherit mkZone;
+  inherit evalZone writeZone;
 
-  types = import ./types { inherit pkgs; };
+  inherit types;
 }