ctucx.git: dns.nix

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

commit 6ef7aec0150acbaaff9b69c85c2d214eec9ae39f
parent b8d53c7a47bb0af55d06760f4a67c78d1d51d8f1
Author: Kirill Elagin <kirelagin@gmail.com>
Date: Fri, 8 Mar 2019 19:47:38 +0100

Add more record types
7 files changed, 205 insertions(+), 53 deletions(-)
A
dns/types/records/A.nix
|
24
++++++++++++++++++++++++
A
dns/types/records/CAA.nix
|
35
+++++++++++++++++++++++++++++++++++
A
dns/types/records/CNAME.nix
|
24
++++++++++++++++++++++++
A
dns/types/records/NS.nix
|
24
++++++++++++++++++++++++
A
dns/types/records/SOA.nix
|
63
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A
dns/types/records/TXT.nix
|
24
++++++++++++++++++++++++
M
dns/types/records/default.nix
|
64
+++++++++++-----------------------------------------------------
diff --git a/dns/types/records/A.nix b/dns/types/records/A.nix
@@ -0,0 +1,24 @@
+#
+# © 2019 Kirill Elagin <kirelagin@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+{ pkgs }:
+
+let
+  inherit (pkgs.lib) mkOption types;
+
+in
+
+{
+  rtype = "A";
+  options = {
+    address = mkOption {
+      type = types.str;
+      example = "26.3.0.103";
+      description = "IP address of the host";
+    };
+  };
+  dataToString = {address, ...}: address;
+}
diff --git a/dns/types/records/CAA.nix b/dns/types/records/CAA.nix
@@ -0,0 +1,35 @@
+#
+# © 2019 Kirill Elagin <kirelagin@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+{ pkgs }:
+
+let
+  inherit (pkgs.lib) mkOption types;
+
+in
+
+{
+  rtype = "CAA";
+  options = {
+    issuerCritical = mkOption {
+      type = types.bool;
+      example = true;
+      description = "If set to '1', indicates that the corresponding property tag MUST be understood if the semantics of the CAA record are to be correctly interpreted by an issuer";
+    };
+    tag = mkOption {
+      type = types.enum ["issue" "issuewild" "iodef"];
+      example = "issue";
+      description = "One of the defined property tags";
+    };
+    value = mkOption {
+      type = types.str;
+      example = "ca.example.net";
+      description = "Value of the property";
+    };
+  };
+  dataToString = {issuerCritical, tag, value, ...}:
+    ''${if issuerCritical then "1" else "0"} ${tag} "${value}"'';
+}
diff --git a/dns/types/records/CNAME.nix b/dns/types/records/CNAME.nix
@@ -0,0 +1,24 @@
+#
+# © 2019 Kirill Elagin <kirelagin@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+{ pkgs }:
+
+let
+  inherit (pkgs.lib) mkOption types;
+
+in
+
+{
+  rtype = "CNAME";
+  options = {
+    cname = mkOption {
+      type = types.str;
+      example = "www.test.com";
+      description = "A <domain-name> which specifies the canonical or primary name for the owner. The owner name is an alias";
+    };
+  };
+  dataToString = {cname, ...}: cname;
+}
diff --git a/dns/types/records/NS.nix b/dns/types/records/NS.nix
@@ -0,0 +1,24 @@
+#
+# © 2019 Kirill Elagin <kirelagin@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+{ pkgs }:
+
+let
+  inherit (pkgs.lib) mkOption types;
+
+in
+
+{
+  rtype = "NS";
+  options = {
+    nsdname = mkOption {
+      type = types.str;
+      example = "ns2.example.com";
+      description = "A <domain-name> which specifies a host which should be authoritative for the specified class and domain";
+    };
+  };
+  dataToString = {nsdname, ...}: nsdname;
+}
diff --git a/dns/types/records/SOA.nix b/dns/types/records/SOA.nix
@@ -0,0 +1,63 @@
+#
+# © 2019 Kirill Elagin <kirelagin@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+{ pkgs }:
+
+let
+  inherit (pkgs.lib) concatStringsSep replaceStrings;
+  inherit (pkgs.lib) mkOption types;
+
+in
+
+{
+  rtype = "SOA";
+  options = {
+    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";
+    };
+    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 ["@"] ["."];
+    };
+    serial = mkOption {
+      type = types.ints.unsigned;  # TODO: u32
+      example = 20;
+      description = "Version number of the original copy of the zone";
+    };
+    refresh = mkOption {
+      type = types.ints.unsigned;  # TODO: u32
+      default = 24 * 60 * 60;
+      example = 7200;
+      description = "Time interval before the zone should be refreshed";
+    };
+    retry = mkOption {
+      type = types.ints.unsigned;  # TODO: u32
+      default = 10 * 60;
+      example = 600;
+      description = "Time interval that should elapse before a failed refresh should be retried";
+    };
+    expire = mkOption {
+      type = types.ints.unsigned;  # TODO: u32
+      default = 10 * 24 * 60 * 60;
+      example = 3600000;
+      description = "Time value that specifies the upper limit on the time interval that can elapse before the zone is no longer authoritative";
+    };
+    minimum = mkOption {
+      type = types.ints.unsigned;  # TODO: u32
+      default = 60;
+      example = 60;
+      description = "Minimum TTL field that should be exported with any RR from this zone";
+    };
+  };
+  dataToString = data@{nameServer, adminEmail, ...}:
+    let
+      numbers = map toString (with data; [serial refresh retry expire minimum]);
+    in "${nameServer} ${adminEmail} (${concatStringsSep " " numbers})";
+}
diff --git a/dns/types/records/TXT.nix b/dns/types/records/TXT.nix
@@ -0,0 +1,24 @@
+#
+# © 2019 Kirill Elagin <kirelagin@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+{ pkgs }:
+
+let
+  inherit (pkgs.lib) mkOption types;
+
+in
+
+{
+  rtype = "TXT";
+  options = {
+    data = mkOption {
+      type = types.str;
+      example = "favorite drink=orange juice";
+      description = "Arbitrary information";
+    };
+  };
+  dataToString = {data, ...}: ''"${data}"'';
+}
diff --git a/dns/types/records/default.nix b/dns/types/records/default.nix
@@ -7,59 +7,17 @@
 { pkgs }:
 
 let
-  inherit (pkgs.lib) concatStringsSep replaceStrings;
-  inherit (pkgs.lib) mkOption types;
+  inherit (pkgs.lib) genAttrs;
+
+  types = [
+    "A"
+    "CAA"
+    "CNAME"
+    "NS"
+    "SOA"
+    "TXT"
+  ];
 
 in
 
-{
-  SOA = {
-    rtype = "SOA";
-    options = {
-      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";
-      };
-      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 ["@"] ["."];
-      };
-      serial = mkOption {
-        type = types.ints.unsigned;  # TODO: u32
-        example = 20;
-        description = "Version number of the original copy of the zone";
-      };
-      refresh = mkOption {
-        type = types.ints.unsigned;  # TODO: u32
-        default = 24 * 60 * 60;
-        example = 7200;
-        description = "Time interval before the zone should be refreshed";
-      };
-      retry = mkOption {
-        type = types.ints.unsigned;  # TODO: u32
-        default = 10 * 60;
-        example = 600;
-        description = "Time interval that should elapse before a failed refresh should be retried";
-      };
-      expire = mkOption {
-        type = types.ints.unsigned;  # TODO: u32
-        default = 10 * 24 * 60 * 60;
-        example = 3600000;
-        description = "Time value that specifies the upper limit on the time interval that can elapse before the zone is no longer authoritative";
-      };
-      minimum = mkOption {
-        type = types.ints.unsigned;  # TODO: u32
-        default = 60;
-        example = 60;
-        description = "Minimum TTL field that should be exported with any RR from this zone";
-      };
-    };
-    dataToString = data@{nameServer, adminEmail, ...}:
-      let
-        numbers = map toString (with data; [serial refresh retry expire minimum]);
-      in "${nameServer} ${adminEmail} (${concatStringsSep " " numbers})";
-  };
-}
+genAttrs types (t: import (./. + "/${t}.nix") { inherit pkgs; })