# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie # SPDX-License-Identifier: MIT { lib, stdenv, callPackage, zig_0_16, }: let # Generated from build.zig.zon by zon2nix; regenerate with # nix develop -c zon2nix --16 --nix=build.zig.zon.nix build.zig.zon zigDeps = callPackage ./build.zig.zon.nix { }; in stdenv.mkDerivation (finalAttrs: { pname = "zig-http"; version = "0.1.0"; # Named rather than filtered, so that editing something outside this list -- # the flake, a scratch file, the NixOS test that consumes the result -- does # not rebuild the package and, in the test, the whole virtual machine. src = lib.fileset.toSource { root = ./.; fileset = lib.fileset.unions [ ./build.zig ./build.zig.zon ./build.zig.zon.nix ./src # Without the difference, editing a virtual machine test rebuilds the # package -- and with it every machine in every one of those tests, # since they all depend on it. The Nix files under `tests/nixos` are # read by the flake's `checks`, never by `zig build`. (lib.fileset.difference ./tests ./tests/nixos) ./tools ./LICENSES ./README.md ./REUSE.toml ]; }; nativeBuildInputs = [ zig_0_16.hook ]; # A Nix build has no network and the Zig package manager wants one, so the # dependencies are realised by Nix and handed over as a directory. `--system` # does not merely offer it, it forbids fetching outright: a dependency # missing from it is a build error naming the package rather than a silent # attempt to reach the network that fails somewhere less legible. zigBuildFlags = [ "--system" "${zigDeps}" ]; # The check phase assembles its own flags rather than reusing the build's, # so without this `zig build test` runs without `--system`, tries to fetch, # and fails in the sandbox. zigCheckFlags = finalAttrs.zigBuildFlags; # `zig build test` here rather than only in CI: the unit tests are pure, and # the ones that want a socket only want a loopback one, which the build # sandbox has. doCheck = true; meta = { description = "Transport-agnostic HTTP for Zig: server and client, HTTP/1.0 through HTTP/3"; homepage = "https://git.jcollie.dev/jeff/zig-http"; license = lib.licenses.mit; mainProgram = "zig-http"; platforms = lib.platforms.unix; }; })