ctucx.git: dns-nix

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

commit 10d7307f26ee02620e86d153d8bfb6318250997a
parent 985797066ffaf8fb05693169c7c2c3222c704365
Author: Kirill Elagin <kirelagin@gmail.com>
Date: Sun, 28 Mar 2021 23:35:46 -0400

Move writeZone to a separate util dir

The problem with `writeZone` is that it produces a derivation by using
`writeTextFile` from nixpkgs, which, in turn, is tricky to access from
within a flake, since it depends on the `system` attribute.

Moving it to a separate module will allows us to clearly separate “pure”
and “impure” functions and expose them form the flake accordingly.
3 files changed, 18 insertions(+), 7 deletions(-)
M
default.nix
|
7
++++++-
M
dns/default.nix
|
7
+------
A
util/writeZone.nix
|
11
+++++++++++
diff --git a/default.nix b/default.nix
@@ -6,11 +6,16 @@
 
 let
   dns = import ./dns { inherit pkgs; };
+  writeZone = import ./util/writeZone.nix {
+    inherit (dns) evalZone;
+    inherit (pkgs) writeTextFile;
+  };
 in
 
 {
-  inherit (dns) evalZone writeZone;
+  inherit (dns) evalZone;
   inherit (dns) combinators;
+  inherit writeZone;
 
   toString = name: zone: toString (dns.evalZone name zone);
 } // dns.combinators
diff --git a/dns/default.nix b/dns/default.nix
@@ -28,15 +28,10 @@ let
       ];
     }).config.zones."${name}";
 
-  writeZone = name: zone:
-    pkgs.writeTextFile {
-      name = "${name}.zone";
-      text = toString (evalZone name zone);
-    };
 in
 
 {
-  inherit evalZone writeZone;
+  inherit evalZone;
 
   inherit types;
 
diff --git a/util/writeZone.nix b/util/writeZone.nix
@@ -0,0 +1,11 @@
+# SPDX-FileCopyrightText: 2021 Kirill Elagin <kirelagin@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+
+{ evalZone, writeTextFile }:
+
+name: zone:
+  writeTextFile {
+    name = "${name}.zone";
+    text = toString (evalZone name zone);
+  }