ctucx.git: dns-nix

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

commit 914e2794d151e86495ba4b9e3ab64e48250b568d
parent 10d7307f26ee02620e86d153d8bfb6318250997a
Author: Kirill Elagin <kirelagin@gmail.com>
Date: Sun, 28 Mar 2021 23:44:39 -0400

Pass only `lib` to pure parts of the code

Previously, we were passing `pkgs` to all the parts of the code that
generate the records, but all of them were only using `pkgs.lib`.

Now we only pass `lib`, since it is “pure”, i.e. does not depend on the
stdenv and thus the `system` we are building on/for.

This will allow us to correctly expose `writeZone` through the flake
interface.
21 files changed, 47 insertions(+), 53 deletions(-)
diff --git a/default.nix b/default.nix
@@ -5,7 +5,7 @@
 { pkgs ? import <nixpkgs> {} }:
 
 let
-  dns = import ./dns { inherit pkgs; };
+  dns = import ./dns { inherit (pkgs) lib; };
   writeZone = import ./util/writeZone.nix {
     inherit (dns) evalZone;
     inherit (pkgs) writeTextFile;
diff --git a/dns/combinators.nix b/dns/combinators.nix
@@ -4,11 +4,10 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
   inherit (builtins) map;
-  inherit (pkgs) lib;
 
 in
 
diff --git a/dns/default.nix b/dns/default.nix
@@ -4,13 +4,11 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs) lib;
-
-  types = import ./types { inherit pkgs; };
-  combinators = import ./combinators.nix { inherit pkgs; };
+  types = import ./types { inherit lib; };
+  combinators = import ./combinators.nix { inherit lib; };
 
   evalZone = name: zone:
     (lib.evalModules {
diff --git a/dns/types/default.nix b/dns/types/default.nix
@@ -4,10 +4,10 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 {
-  inherit (import ./zone.nix { inherit pkgs; }) zone subzone;
-  record = import ./record.nix { inherit pkgs; };
-  records = import ./records { inherit pkgs; };
+  inherit (import ./zone.nix { inherit lib; }) zone subzone;
+  record = import ./record.nix { inherit lib; };
+  records = import ./records { inherit lib; };
 }
diff --git a/dns/types/record.nix b/dns/types/record.nix
@@ -4,10 +4,9 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs) lib;
   inherit (lib) const isString mkOption types;
 
   defaults = {
diff --git a/dns/types/records/A.nix b/dns/types/records/A.nix
@@ -4,10 +4,10 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) mkOption types;
 
 in
 
diff --git a/dns/types/records/AAAA.nix b/dns/types/records/AAAA.nix
@@ -4,10 +4,10 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) mkOption types;
 
 in
 
diff --git a/dns/types/records/CAA.nix b/dns/types/records/CAA.nix
@@ -4,10 +4,10 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) mkOption types;
 
 in
 
diff --git a/dns/types/records/CNAME.nix b/dns/types/records/CNAME.nix
@@ -4,10 +4,10 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) mkOption types;
 
 in
 
diff --git a/dns/types/records/DKIM.nix b/dns/types/records/DKIM.nix
@@ -7,10 +7,9 @@
 # This is a “fake” record type, not actually part of DNS.
 # It gets compiled down to a TXT record.
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs) lib;
   inherit (lib) mkOption types;
 
 in
diff --git a/dns/types/records/DMARC.nix b/dns/types/records/DMARC.nix
@@ -7,10 +7,9 @@
 # This is a “fake” record type, not actually part of DNS.
 # It gets compiled down to a TXT record.
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs) lib;
   inherit (lib) mkOption types;
 
 in
diff --git a/dns/types/records/DNSKEY.nix b/dns/types/records/DNSKEY.nix
@@ -2,12 +2,12 @@
 #
 # SPDX-License-Identifier: MIT
 
-{ pkgs }:
+{ lib }:
 let
   inherit (builtins) isInt split;
-  inherit (pkgs.lib) concatStrings flatten mkOption types;
+  inherit (lib) concatStrings flatten mkOption types;
 
-  dnssecOptions = import ./dnssec.nix { inherit pkgs; };
+  dnssecOptions = import ./dnssec.nix { inherit lib; };
   inherit (dnssecOptions) mkDNSSECAlgorithmOption;
 in
 {
diff --git a/dns/types/records/DS.nix b/dns/types/records/DS.nix
@@ -2,11 +2,11 @@
 #
 # SPDX-License-Identifier: MIT
 
-{ pkgs }:
+{ lib }:
 let
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) mkOption types;
 
-  dnssecOptions = import ./dnssec.nix { inherit pkgs; };
+  dnssecOptions = import ./dnssec.nix { inherit lib; };
   inherit (dnssecOptions) mkRegisteredNumberOption mkDNSSECAlgorithmOption;
 
   mkDSDigestTypeOption = { ... }@args: mkRegisteredNumberOption {
diff --git a/dns/types/records/MX.nix b/dns/types/records/MX.nix
@@ -4,10 +4,10 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) mkOption types;
 
 in
 
diff --git a/dns/types/records/NS.nix b/dns/types/records/NS.nix
@@ -4,10 +4,10 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) mkOption types;
 
 in
 
diff --git a/dns/types/records/SOA.nix b/dns/types/records/SOA.nix
@@ -4,11 +4,11 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs.lib) concatStringsSep removeSuffix replaceStrings;
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) concatStringsSep removeSuffix replaceStrings;
+  inherit (lib) mkOption types;
 
 in
 
diff --git a/dns/types/records/SRV.nix b/dns/types/records/SRV.nix
@@ -4,10 +4,10 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) mkOption types;
 
 in
 
diff --git a/dns/types/records/TXT.nix b/dns/types/records/TXT.nix
@@ -4,10 +4,10 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) mkOption types;
 
 in
 
diff --git a/dns/types/records/default.nix b/dns/types/records/default.nix
@@ -4,10 +4,10 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
-  inherit (pkgs.lib) genAttrs;
+  inherit (lib) genAttrs;
 
   types = [
     "A"

@@ -31,4 +31,4 @@ let
 
 in
 
-genAttrs types (t: import (./. + "/${t}.nix") { inherit pkgs; })
+genAttrs types (t: import (./. + "/${t}.nix") { inherit lib; })
diff --git a/dns/types/records/dnssec.nix b/dns/types/records/dnssec.nix
@@ -2,10 +2,10 @@
 #
 # SPDX-License-Identifier: MIT
 
-{ pkgs }:
+{ lib }:
 let
   inherit (builtins) attrNames isInt removeAttrs;
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) mkOption types;
 in
 rec {
   mkRegisteredNumberOption = { registryName, numberType, mnemonics }@args:
diff --git a/dns/types/zone.nix b/dns/types/zone.nix
@@ -4,17 +4,17 @@
 # SPDX-License-Identifier: MIT
 #
 
-{ pkgs }:
+{ lib }:
 
 let
   inherit (builtins) attrValues filter map removeAttrs;
-  inherit (pkgs.lib) concatMapStringsSep concatStringsSep mapAttrs
+  inherit (lib) concatMapStringsSep concatStringsSep mapAttrs
                      mapAttrsToList optionalString;
-  inherit (pkgs.lib) mkOption types;
+  inherit (lib) mkOption types;
 
-  inherit (import ./record.nix { inherit pkgs; }) recordType writeRecord;
+  inherit (import ./record.nix { inherit lib; }) recordType writeRecord;
 
-  rsubtypes = import ./records { inherit pkgs; };
+  rsubtypes = import ./records { inherit lib; };
   rsubtypes' = removeAttrs rsubtypes ["SOA"];
 
   subzoneOptions = {