# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie # SPDX-License-Identifier: MIT { description = "Classic Unix mailbox files for Zig"; inputs = { nixpkgs = { url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"; }; # Mine, not the one in nixpkgs, which is Jari Vetoniemi's original 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-mbox = pkgs.callPackage ./package.nix { }; default = zig-mbox; # 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 interoperability test, which is here rather than in `zig build # test` because what it tests is disagreement between implementations: # procmail's `formail` and Python's `mailbox` module reading a mailbox # this library wrote, and this library reading one they wrote. A fixture # written to suit this parser would hide exactly the differences that # are the whole difficulty of the format. # # Linux-only because that is where those two are reliably packaged, not # because it needs a guest: see `tests/interop.nix` for why an mbox # test, unlike a maildir one, does not. checks = forLinuxSystems ( system: let pkgs = makePackages system; zig-mbox = pkgs.callPackage ./package.nix { }; test = file: pkgs.callPackage (import file { inherit zig-mbox; }) { }; in { inherit zig-mbox; interop = test ./tests/interop.nix; } ); devShells = forAllSystems ( system: let pkgs = makePackages system; in { default = pkgs.mkShell { name = "zig-mbox"; nativeBuildInputs = [ pkgs.zig_0_17 pkgs.git-pages-cli pkgs.pinact pkgs.reuse # Wrapped so that the Zig it shells out to for `zig env` is the # one this project builds with, rather than whatever happens to # be on the caller's PATH. Without a Zig at all it prints # "unable to execute zig" and writes nothing, leaving the # previous build.zig.zon.nix in place looking untouched. (pkgs.symlinkJoin { name = "zon2nix"; paths = [ zon2nix.packages.${system}.zon2nix ]; nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' wrapProgram $out/bin/zon2nix \ --prefix PATH : ${lib.makeBinPath [ pkgs.zig_0_17 ]} ''; }) ] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ # The other implementations, to read what this one writes and # to write what it has to read. `formail -s` is the splitter # every mail script on earth reaches for, and Python's `mailbox` # module is the most widely deployed second opinion on where a # message ends. Both can be driven from a script, which is why # they and not mutt: a reader that insists on a terminal cannot # be asked anything by a test. pkgs.procmail pkgs.python3 pkgs.kcov ]; }; } ); }; }