Something went wrong. Try again.
An HTTP library for Zig 0.17, server and client, HTTP/1.0 through HTTP/3, with the protocol in a module that owns no socket.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us># SPDX-License-Identifier: MIT
{ description = "zig-http";
inputs = { nixpkgs = { url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"; }; # Reads `build.zig.zon`, follows every transitive dependency, and writes a # Nix expression for the lot. A Nix build has no network and the Zig # package manager wants one; this is the bridge. Not the `zon2nix` in # nixpkgs, which is a different program taking different options. zon2nix = { url = "github:jcollie/zon2nix"; inputs.nixpkgs.follows = "nixpkgs"; }; };
outputs = { nixpkgs, zon2nix, ... }: let inherit (nixpkgs) lib; makePackages = system: import nixpkgs { inherit system; }; forAllSystems = lib.genAttrs lib.systems.flakeExposed; # The virtual machine tests are NixOS ones, so they exist only where # NixOS does. Without this `nix flake check` tries to evaluate them for # Darwin and fails before it has run anything. forLinuxSystems = lib.genAttrs ( lib.filter (system: lib.hasSuffix "-linux" system) lib.systems.flakeExposed ); in { packages = forAllSystems ( system: let pkgs = makePackages system; in rec { zig-http = pkgs.callPackage ./package.nix { }; default = zig-http; # The dependency farm on its own, for a job that runs `zig build` # for something other than the package -- the documentation, say -- # and needs the same dependencies without building the package to # get at them. zig-deps = pkgs.callPackage ./build.zig.zon.nix { }; } );
# The tests that need a machine rather than a process: a real curl, a # real h2spec and real load, each talking to the demonstration server # over a socket from a host of its own. None is reachable from a test # binary — they are about whether other implementations agree about the # framing, whether the HTTP/2 driver conforms, and what happens when # fifty clients are inside the server at once. checks = forLinuxSystems ( system: let pkgs = makePackages system; zig-http = pkgs.callPackage ./package.nix { }; test = file: pkgs.testers.runNixOSTest (import file { inherit zig-http; }); in { inherit zig-http; curl = test ./tests/nixos/curl.nix; h3 = test ./tests/nixos/h3.nix; aioquic = test ./tests/nixos/aioquic.nix; h2spec = test ./tests/nixos/h2spec.nix; load = test ./tests/nixos/load.nix; window = test ./tests/nixos/window.nix; tls = test ./tests/nixos/tls.nix; proxy = test ./tests/nixos/proxy.nix; client = test ./tests/nixos/client.nix; h3client = test ./tests/nixos/h3client.nix; traefik = test ./tests/nixos/traefik.nix; } );
devShells = forAllSystems ( system: let pkgs = makePackages system; in { default = pkgs.mkShell { name = "zig-http"; nativeBuildInputs = [ pkgs.zig_0_17 pkgs.git-pages-cli pkgs.reuse
# Wrapped so that the Zig it shells out to for `zig env` is this # project's rather than whatever happens to be on the caller's # PATH -- without one it prints "unable to execute zig" and # stops, having written nothing, which leaves the previous # generated file in place looking untouched. (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 ]} ''; })
# The other implementations to test against. curl is the # strictest reading of RFC 9112 likely to connect to this; # h2spec is the conformance suite for RFC 9113, and nghttp2 # brings `h2load` and the `nghttp` debug client. pkgs.curl pkgs.h2spec pkgs.httpie pkgs.nghttp2 pkgs.siege ]; }; } ); };}