# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie # SPDX-License-Identifier: MIT { description = "Avahi for Zig: publish and browse mDNS services through the system's Avahi daemon"; inputs = { nixpkgs = { url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; }; zon2nix = { url = "github:jcollie/zon2nix"; inputs.nixpkgs.follows = "nixpkgs"; }; # The NixOS release the virtual machine test runs on, for its Avahi. nixos-unstable = { url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"; }; }; outputs = { self, nixpkgs, zon2nix, nixos-unstable, ... }: let inherit (nixpkgs) lib; makePackages = system: import nixpkgs { inherit system; }; forAllSystems = lib.genAttrs lib.systems.flakeExposed; # zon2nix shells out to `zig env`, and without a Zig on PATH it prints # "unable to execute zig, is it in your PATH?" and stops having written # nothing -- which leaves the previous build.zig.zon.nix in place looking # untouched rather than obviously broken. Wrap it so the Zig it finds is # this project's. wrappedZon2nix = pkgs: pkgs.symlinkJoin { name = "zon2nix"; paths = [ zon2nix.packages.${pkgs.stdenv.hostPlatform.system}.zon2nix ]; nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' wrapProgram $out/bin/zon2nix \ --prefix PATH : ${lib.makeBinPath [ pkgs.zig_0_17 ]} ''; }; in { devShells = forAllSystems ( system: let pkgs = makePackages system; in { default = pkgs.mkShell { name = "zig-avahi"; nativeBuildInputs = [ (wrappedZon2nix pkgs) pkgs.git-pages-cli pkgs.reuse pkgs.zig_0_17 ]; }; } ); packages = forAllSystems ( system: let pkgs = makePackages system; in rec { zig-avahi = pkgs.callPackage ./package.nix { }; default = zig-avahi; # The Zig dependency farm on its own, so a job that runs `zig build` # for something other than the package -- the documentation, say -- # can hand it straight to `--system`. zig-deps = pkgs.callPackage ./build.zig.zon.nix { }; } ); # The package, whose build runs the unit tests, on every system; and on # Linux `zavahi` against a real Avahi daemon in a virtual machine. checks = forAllSystems ( system: let pkgs = makePackages system; zig-avahi = pkgs.callPackage ./package.nix { }; in { inherit zig-avahi; } // lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { avahi = (import nixos-unstable { inherit system; }).testers.runNixOSTest ( import ./tests/nixos/avahi.nix { inherit zig-avahi; } ); } ); formatter = forAllSystems (system: (makePackages system).nixfmt-tree); }; }