ctucx.git: dns-nix

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

commit 774ddfcd95a16132d7911d7c6d24de85b106ea56
parent c7b9645da9c0ddce4f9de4ef27ec01bb8108039a
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 13 Sep 2022 10:03:30 +0200

remove __toString
4 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/dns/types/default.nix b/dns/types/default.nix
@@ -8,7 +8,7 @@
 
 {
   inherit (import ./simple.nix { inherit lib; }) domain-name;
-  inherit (import ./zone.nix { inherit lib; }) zone subzone;
+  inherit (import ./zone.nix { inherit lib; }) zone subzone zoneToString;
   record = import ./record.nix { inherit lib; };
   records = import ./records { inherit lib; };
 }
diff --git a/dns/types/zone.nix b/dns/types/zone.nix
@@ -57,6 +57,11 @@ let
       concatStringsSep "\n\n" groups'
       + optionalString (sub != "") ("\n\n" + sub);
 
+  zoneToString = name: zone@{SOA, ...}:
+    ''
+      ${writeRecord name rsubtypes.SOA SOA}
+    '' + writeSubzone name zone + "\n";
+
   zone = types.submodule ({ name, ... }: {
     options = {
       TTL = mkOption {

@@ -72,22 +77,8 @@ let
         } // type.example;
         description = "SOA record";
       };
-      __toString = mkOption {
-        readOnly = true;
-        visible = false;
-      };
     } // subzoneOptions;
 
-    config = {
-      __toString = zone@{ TTL, SOA, ... }:
-        ''
-          $TTL ${toString TTL}
-
-          ${writeRecord name rsubtypes.SOA SOA}
-
-          ${writeSubzone name zone}
-        '';
-    };
   });
 
 in

@@ -95,4 +86,5 @@ in
 {
   inherit zone;
   inherit subzone;
+  inherit zoneToString;
 }
diff --git a/flake.nix b/flake.nix
@@ -29,6 +29,7 @@
         util = {
           writeZone = import ./util/writeZone.nix {
             inherit (self.lib) evalZone;
+            inherit (self.lib.types) zoneToString;
             inherit (pkgs) writeTextFile;
           };
         };
diff --git a/util/writeZone.nix b/util/writeZone.nix
@@ -2,10 +2,10 @@
 #
 # SPDX-License-Identifier: MPL-2.0 or MIT
 
-{ evalZone, writeTextFile }:
+{ evalZone, zoneToString, writeTextFile }:
 
 name: zone:
   writeTextFile {
     name = "${name}.zone";
-    text = toString (evalZone name zone);
+    text = zoneToString name (evalZone name zone);
   }