ctucx.git: dns.nix

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

commit 4713eecb3735823ce5dfaf823a0715d0f1c17cd7
parent 065c731a43b319822bce3bd02f79d75569f7b9c1
Author: Kirill Elagin <kirelagin@gmail.com>
Date: Sun, 10 Mar 2019 03:13:15 +0100

records: SRV
4 files changed, 67 insertions(+), 2 deletions(-)
M
dns/types/record.nix
|
6
++++--
A
dns/types/records/SRV.nix
|
54
++++++++++++++++++++++++++++++++++++++++++++++++++++++
M
dns/types/records/default.nix
|
1
+
M
example.nix
|
8
++++++++
diff --git a/dns/types/record.nix b/dns/types/record.nix
@@ -8,7 +8,7 @@
 
 let
   inherit (pkgs) lib;
-  inherit (lib) mkOption types;
+  inherit (lib) const mkOption types;
 
   recordTypes = import ./records { inherit pkgs; };
 in

@@ -52,6 +52,8 @@ recordType: name: types.submodule {
     rtype  = recordType.rtype;
     _rtype = recordType;
     __toString = data@{name, rtype, class, ttl, _rtype, ...}:
-      "${name}. ${toString ttl} ${class} ${rtype} ${_rtype.dataToString data}";
+      let
+        name' = _rtype.nameFixup or (const name) data;
+      in "${name'}. ${toString ttl} ${class} ${rtype} ${_rtype.dataToString data}";
   };
 }
diff --git a/dns/types/records/SRV.nix b/dns/types/records/SRV.nix
@@ -0,0 +1,54 @@
+#
+# © 2019 Kirill Elagin <kirelagin@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+{ pkgs }:
+
+let
+  inherit (pkgs.lib) mkOption types;
+
+in
+
+{
+  rtype = "SRV";
+  options = {
+    service = mkOption {
+      type = types.str;
+      example = "foobar";
+      description = "The symbolic name of the desired service. Do not add the underscore!";
+    };
+    proto = mkOption {
+      type = types.str;
+      example = "tcp";
+      description = "The symbolic name of the desired protocol. Do not add the underscore!";
+    };
+    priority = mkOption {
+      type = types.ints.u16;
+      default = 0;
+      example = 0;
+      description = "The priority of this target host";
+    };
+    weight = mkOption {
+      type = types.ints.u16;
+      default = 100;
+      example = 20;
+      description = "The weight field specifies a relative weight for entries with the same priority. Larger weights SHOULD be given a proportionately higher probability of being selected";
+    };
+    port = mkOption {
+      type = types.ints.u16;
+      example = 9;
+      description = "The port on this target host of this service";
+    };
+    target = mkOption {
+      type = types.str;
+      example = "";
+      description = "The domain name of the target host";
+    };
+  };
+  dataToString = data: with data;
+    "${toString priority} ${toString weight} ${toString port} ${target}";
+  nameFixup = self:
+    "_${self.service}._${self.proto}.${self.name}";
+}
diff --git a/dns/types/records/default.nix b/dns/types/records/default.nix
@@ -17,6 +17,7 @@ let
     "MX"
     "NS"
     "SOA"
+    "SRV"
     "TXT"
   ];
 
diff --git a/example.nix b/example.nix
@@ -37,6 +37,14 @@ let
 
     CAA = letsEncrypt "admin@example.com";
 
+    SRV = [
+      { service = "sip";
+        proto = "tcp";
+        port = 5060;
+        target = "sip.example.com";
+      }
+    ];
+
     subdomains = {
       www = {
         A = map a [ "203.0.113.4" ];