Something went wrong. Try again.
The WebSocket Protocol (RFC 6455) for Zig: framing, a client, and a server handshake on zig-http
Something went wrong. Try again.
zig-websocket flake.nix
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us># SPDX-License-Identifier: MIT
{ description = "zig-websocket";
inputs = { nixpkgs = { url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"; }; # Not the `zon2nix` in nixpkgs, which is a different program by a # different author and takes 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-websocket = pkgs.callPackage ./package.nix { }; default = zig-websocket; # The dependency farm on its own, so that a workflow job which runs # `zig build` for something other than the package -- the # documentation -- can be handed it without building the package to # get at it. zig-deps = pkgs.callPackage ./build.zig.zon.nix { }; } );
# The test that needs a machine rather than a process: another # implementation of RFC 6455, on a host of its own, over a real socket. # `tests/e2e.zig` checks what this server does with a given sequence of # octets far more thoroughly than that can; what it cannot check is # whether anybody else agrees, since every assertion in it is this # library reading what this library wrote. checks = forLinuxSystems ( system: let pkgs = makePackages system; zig-websocket = pkgs.callPackage ./package.nix { }; test = file: pkgs.testers.runNixOSTest (import file { inherit zig-websocket; }); in { inherit zig-websocket; interop = test ./tests/nixos/interop.nix; } );
devShells = forAllSystems ( system: let pkgs = makePackages system; in { default = pkgs.mkShell { name = "zig-websocket"; nativeBuildInputs = [ pkgs.zig_0_17 pkgs.git-pages-cli pkgs.reuse
# Regenerates `build.zig.zon.nix`, which is how the Nix build # gets the zig-http dependency without a network. Wrapped so # that the `zig env` it shells out to is the one this project # builds with rather than whatever is on the caller's PATH. (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 implementation to test against, and the one worth # being judged by: `websockets` is strict, widely used, and # reports a framing disagreement as an error rather than # quietly recovering from it. (pkgs.python3.withPackages (ps: [ ps.websockets ])) pkgs.curl ]; }; } ); };}