# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie # SPDX-License-Identifier: MIT { description = "BIND zone files for Zig: read one, edit it, write it back"; inputs = { nixpkgs = { url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"; }; # The toolchain is the official 0.17.0 release binary, packaged by the # overlay, rather than nixpkgs' Zig, which is still 0.16. zig = { url = "git+https://git.jcollie.dev/jeff/zig-overlay.git"; inputs = { nixpkgs.follows = "nixpkgs"; zon2nix.follows = "zon2nix"; }; }; zon2nix = { url = "github:jcollie/zon2nix"; inputs = { nixpkgs.follows = "nixpkgs"; }; }; }; outputs = { nixpkgs, zig, zon2nix, ... }: let inherit (nixpkgs) lib; makePackages = system: import nixpkgs { inherit system; }; zigFor = system: zig.packages.${system}."0.17.0"; # Only the systems the overlay has a 0.17.0 release binary for, since # there is no other Zig 0.17 to fall back on. forAllSystems = lib.genAttrs ( lib.filter ( system: zig.packages ? ${system} && zig.packages.${system} ? "0.17.0" ) lib.systems.flakeExposed ); in { # The comparison against BIND as a build rather than a devshell command, # so that `nix flake check` covers it too. It needs no network: the Zig # dependencies come from build.zig.zon.nix, which zon2nix generates from # the manifest, and `--system` makes a missing one an error naming the # package rather than a silent attempt to fetch it. checks = forAllSystems ( system: let pkgs = makePackages system; # Generated from build.zig.zon; regenerate with # nix develop -c zon2nix --17 --nix=build.zig.zon.nix build.zig.zon zigDeps = pkgs.callPackage ./build.zig.zon.nix { zig_0_17 = zigFor system; }; # Only the files the check actually reads, so that editing the README # does not rebuild it. source = lib.fileset.toSource { root = ./.; fileset = lib.fileset.unions [ ./build.zig ./build.zig.zon ./src ./tests ./tools ]; }; in { differential = pkgs.runCommand "zig-dns-zone-differential" { nativeBuildInputs = [ (zigFor system) pkgs.bind # The comparison is driven by tests/differential.py, and the # sandbox has no interpreter it was not given. pkgs.python3 ]; } '' cp -r ${source} source chmod -R u+w source cd source export ZIG_GLOBAL_CACHE_DIR="$TMPDIR/zig-cache" zig build differential --system ${zigDeps} touch $out ''; } ); devShells = forAllSystems ( system: let pkgs = makePackages system; in { default = pkgs.mkShell { name = "zig-dns-zone"; nativeBuildInputs = [ (zigFor system) pkgs.git-pages-cli pkgs.pinact pkgs.reuse # The other opinion about what a zone file means. # `named-compilezone` reads one and writes it back in a canonical # form, which is exactly what `zig build differential` compares # against; `dig` and `drill` are here for reading a record off # the wire when a zone file and a server disagree. pkgs.bind pkgs.ldns # Regenerates build.zig.zon.nix, which is how the flake check # gets the Zig dependencies without a network: # # zon2nix --17 --nix=build.zig.zon.nix build.zig.zon # # Wrapped so that the `zig env` it shells out to is this # project's Zig rather than whatever the caller happens to have. (pkgs.symlinkJoin { name = "zon2nix"; paths = [ zon2nix.packages.${pkgs.stdenv.hostPlatform.system}.zon2nix ]; nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' wrapProgram $out/bin/zon2nix \ --prefix PATH : ${lib.makeBinPath [ (zigFor system) ]} ''; }) ] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.kcov pkgs.perf ]; }; } ); }; }