# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie # SPDX-License-Identifier: MIT { description = "zig-imap — a IMAP client library for Zig"; inputs = { nixpkgs = { url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"; }; }; outputs = { self, nixpkgs, ... }: let inherit (nixpkgs) lib; makePackages = system: import nixpkgs { inherit system; }; forAllSystems = lib.genAttrs lib.systems.flakeExposed; in { packages = forAllSystems ( system: let pkgs = makePackages system; # Generated from build.zig.zon by zon2nix; regenerate with # nix develop -c nix run github:jcollie/zon2nix#zon2nix -- --nix=build.zig.zon.nix --17 build.zig.zon # A Nix build has no network, and zig-sasl is a dependency now, so # this farm is where it comes from instead. zig-deps = pkgs.callPackage ./build.zig.zon.nix { }; in { # Exposed so a CI job running `zig build` for something other than # this package can hand the same farm to it. inherit zig-deps; # The driver the NixOS test runs inside the guest. It is a package of # its own rather than part of a library build, because the thing it # needs -- a Dovecot on another machine -- only exists in that test. integration = pkgs.stdenv.mkDerivation (finalAttrs: { pname = "zig-imap-integration"; version = "0.2.0"; src = lib.fileset.toSource { root = ./.; # Named file by file, so that editing the NixOS test or the # README does not rebuild this and every virtual machine with it. fileset = lib.fileset.unions [ ./build.zig ./build.zig.zon ./build.zig.zon.nix ./src ./tests/integration.zig ./tests/e2e.zig ./tests/fuzz.zig ./tools ]; }; # `zig_0_17` is the setup hook as well as the compiler in current # nixpkgs, and it builds ReleaseSafe for a baseline CPU. nativeBuildInputs = [ pkgs.zig_0_17 ]; # `--system` does not merely offer the farm, it forbids fetching: # a dependency missing from it is a build error naming the package # rather than a network attempt that fails less legibly. zigBuildFlags = [ "-Dintegration=true" "--system" "${zig-deps}" ]; # The check phase assembles its own flags rather than reusing the # build's, so without this the tests would be built without the # option above. zigCheckFlags = finalAttrs.zigBuildFlags; # The unit tests and the loopback end-to-end tests run here: the # build sandbox has a loopback interface, and a driver built from a # tree whose own tests fail is not worth carrying into a guest. doCheck = true; }); } ); # Linux only: without this `nix flake check` tries to evaluate a NixOS # test for Darwin and fails before running anything. checks = lib.genAttrs (lib.filter (system: lib.hasSuffix "-linux" system) lib.systems.flakeExposed) ( system: let pkgs = makePackages system; in { # `nix build .#checks.x86_64-linux.dovecot -L` runs it by hand; it # needs /dev/kvm, so in CI it goes on an ephemeral runner. dovecot = pkgs.testers.runNixOSTest ( import ./tests/nixos/dovecot.nix { inherit pkgs; integration = self.packages.${system}.integration; } ); } ); devShells = forAllSystems ( system: let pkgs = makePackages system; in { default = pkgs.mkShell { name = "zig-imap"; nativeBuildInputs = [ pkgs.zig_0_17 pkgs.git-pages-cli pkgs.reuse ] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.kcov pkgs.perf ]; }; } ); }; }