An SMTP client and server library for Zig implementing RFC 5321.
2.2 kB
66 lines
1# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>
2# SPDX-License-Identifier: MIT
3
4{
5 lib,
6 stdenv,
7 callPackage,
8 zig_0_16,
9}:
10let
11 # Generated by zon2nix from build.zig.zon; regenerate with:
12 # nix run github:jcollie/zon2nix#zon2nix -- --nix=build.zig.zon.nix --16 build.zig.zon
13 zigDeps = callPackage ./build.zig.zon.nix { };
14in
15stdenv.mkDerivation (finalAttrs: {
16 pname = "zig-smtp";
17 # Keep in step with `.version` in build.zig.zon.
18 version = "0.0.0";
19
20 # Only what `zig build` actually reads. Narrowing the source this way keeps
21 # a stray .zig-cache out of the store, and means edits to the flake, the
22 # README or the license texts do not invalidate the derivation.
23 src = lib.fileset.toSource {
24 root = ./.;
25 fileset = lib.fileset.unions [
26 ./build.zig
27 ./build.zig.zon
28 ./src
29 ];
30 };
31
32 # Provides the configure/build/check/install phases for a `zig build`
33 # project, including a writable ZIG_GLOBAL_CACHE_DIR. It passes
34 # `-Dcpu=baseline --release=safe`, so the result is a portable ReleaseSafe
35 # binary rather than the Debug one `zig build` produces by default.
36 nativeBuildInputs = [ zig_0_16 ];
37
38 # All Zig dependencies come from nix, so the sandboxed build never
39 # fetches over the network.
40 zigBuildFlags = [
41 "--system"
42 "${zigDeps}"
43 ];
44 zigCheckFlags = finalAttrs.zigBuildFlags;
45
46 # `zig build test` is fully hermetic: scripted sessions over in-memory
47 # readers and writers. Interoperability against real MTAs is covered by
48 # the NixOS VM check instead.
49 doCheck = true;
50
51 meta = {
52 description = "SMTP client and server library for Zig";
53 longDescription = ''
54 zig-smtp is an SMTP client and server library (RFC 5321) for Zig. Both
55 sides run over plain std.Io.Reader/std.Io.Writer pairs, making them
56 transport-agnostic, and support STARTTLS and implicit TLS, AUTH,
57 streamed message bodies, and the SIZE, 8BITMIME, CHUNKING and
58 SMTPUTF8 extensions. A small demo CLI for sending and receiving is
59 included.
60 '';
61 homepage = "https://git.jcollie.dev/jeff/zig-smtp";
62 license = lib.licenses.mit;
63 mainProgram = "zig-smtp";
64 platforms = lib.platforms.unix;
65 };
66})