commit 6010977e38e694dd564f2cfa2523134ef1087ab8
parent 914e2794d151e86495ba4b9e3ab64e48250b568d
Author: Kirill Elagin <kirelagin@gmail.com>
Date: Mon, 29 Mar 2021 15:58:10 -0400
parent 914e2794d151e86495ba4b9e3ab64e48250b568d
Author: Kirill Elagin <kirelagin@gmail.com>
Date: Mon, 29 Mar 2021 15:58:10 -0400
Merge pull request #11 from kirelagin/flake-systems Fix `writeZone` in flake-mode
5 files changed, 73 insertions(+), 39 deletions(-)
diff --git a/README.md b/README.md @@ -21,7 +21,7 @@ Example of a zone ```nix # dns = import path/to/nix-dns; -with dns.combinators; { +with dns.lib.combinators; { SOA = { # Human readable names for fields nameServer = "ns.test.com."; adminEmail = "admin@test.com"; # Email address with a real `@`! @@ -102,14 +102,16 @@ Add it as an input to your flake: }; outputs = { self, nixpkgs, dns }: { - # All functions from `nix-dns` are available in `dns.lib`. + # Most functions from `nix-dns` are available in `dns.lib`. + # Functions that require `stdenv` (e.g. `writeZone`) are in + # `dns.util.<system>`. # ... }; } ``` -All examples below assume the old way of importing, but they should work with -just one change: replace `dns` with `dns.lib` everywhere. +All examples below assume the old way of importing, but they should work +without any changes. #### Importing directly (old way) @@ -153,7 +155,7 @@ services.nsd = { "example.com" = { # provideXFR = [ ... ]; # notify = [ ... ]; - data = dns.toString "example.com" (import ./dns/example.com { inherit dns; }); + data = dns.lib.toString "example.com" (import ./dns/example.com { inherit dns; }); }; }; }; @@ -166,7 +168,7 @@ services.nsd = { { dns }: -with dns.combinators; +with dns.lib.combinators; { SOA = { @@ -199,7 +201,7 @@ types to be used in the NixOS module system. Using them you can define an option in your module such as this one: ```nix -# dns = import path/to/nix-dns/dns { inherit pkgs; }; +# dns = import path/to/nix-dns/dns { inherit lib; }; {
diff --git a/default.nix b/default.nix @@ -1,21 +1,11 @@ -# SPDX-FileCopyrightText: 2019 Kirill Elagin <kirelagin@gmail.com> +# SPDX-FileCopyrightText: 2021 Kirill Elagin <https://kir.elagin.me/> # -# SPDX-License-Identifier: MIT - -{ pkgs ? import <nixpkgs> {} }: - -let - dns = import ./dns { inherit (pkgs) lib; }; - writeZone = import ./util/writeZone.nix { - inherit (dns) evalZone; - inherit (pkgs) writeTextFile; - }; -in - -{ - inherit (dns) evalZone; - inherit (dns) combinators; - inherit writeZone; - - toString = name: zone: toString (dns.evalZone name zone); -} // dns.combinators +# SPDX-License-Identifier: CC0-1.0 + +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).defaultNix
diff --git a/example.nix b/example.nix @@ -5,9 +5,10 @@ # let - dns = import ./. { }; + dns = import ./.; + util = dns.util.${builtins.currentSystem}; - testZone = with dns.combinators; { + testZone = with dns.lib.combinators; { SOA = { nameServer = "ns.test.com."; adminEmail = "admin@test.com"; @@ -61,4 +62,4 @@ let }; in -dns.writeZone "test.com" testZone +util.writeZone "test.com" testZone
diff --git a/flake.lock b/flake.lock @@ -1,21 +1,38 @@ { "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1614513358, + "narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5466c5bbece17adaab2d82fae80b46e807611bf3", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1587398327, - "narHash": "sha256-mEKkeLgUrzAsdEaJ/1wdvYn0YZBAKEG3AN21koD2AgU=", + "lastModified": 1616989418, + "narHash": "sha256-LcOn5wHR/1JwClfY/Ai/b+pSRY+d23QtIPQHwPAyHHI=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5272327b81ed355bbed5659b8d303cf2979b6953", + "rev": "9d8e05e088ad91b7c62886a2175f38bfa443db2c", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" } }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } }
diff --git a/flake.nix b/flake.nix @@ -1,12 +1,36 @@ -# SPDX-FileCopyrightText: 2020 Kirill Elagin <kirelagin@gmail.com> +# SPDX-FileCopyrightText: 2021 Kirill Elagin <https://kir.elagin.me/> # # SPDX-License-Identifier: MIT + { description = "Nix DSL for defining DNS zones"; - outputs = { self, nixpkgs }: { + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + let + inherit (nixpkgs) lib; + dns = import ./dns { inherit lib; }; + in { - lib = import ./default.nix { pkgs = nixpkgs; }; + lib = { + inherit (dns) evalZone; + inherit (dns) combinators; + toString = name: zone: builtins.toString (dns.evalZone name zone); + } // dns.combinators; - }; + } // flake-utils.lib.eachDefaultSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + util = { + writeZone = import ./util/writeZone.nix { + inherit (self.lib) evalZone; + inherit (pkgs) writeTextFile; + }; + }; + } + ); }