An SMTP client and server library for Zig implementing RFC 5321.
1# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>
2# SPDX-License-Identifier: MIT
3
4{
5 lib,
6 stdenv,
7 zig_0_16,
8 fetchzip,
9}:
10let
11 # Must match the url/hash pinned in build.zig.zon. Only the files listed in
12 # the dependency's `paths` may end up in zig-pkg/, since Zig hashes the
13 # package contents against the directory name.
14 tlsDep = fetchzip {
15 name = "tls.zig-src";
16 url = "https://github.com/ianic/tls.zig/archive/e04ae448ce7ee70c136d4d48b059314543203809.tar.gz";
17 hash = "sha256-afPTfauIV49IATX0szuOdKLloyqI4XKsyNk8KkasAvg=";
18 };
19 tlsDepId = "tls-0.1.0-ER2e0jGpBgCkVC-Yp12NgSdHNUtZr52MleJ8roHlUa54";
20in
21stdenv.mkDerivation {
22 pname = "zsmtp";
23 version = "0.0.0";
24
25 src = lib.cleanSource ../.;
26
27 nativeBuildInputs = [ zig_0_16 ];
28
29 # Provide the dependency offline through the project-local package
30 # directory, which the build consults before fetching.
31 postPatch = ''
32 mkdir -p zig-pkg/${tlsDepId}
33 cp -r ${tlsDep}/{build.zig,build.zig.zon,readme.md,src} zig-pkg/${tlsDepId}/
34 '';
35
36 dontConfigure = true;
37
38 buildPhase = ''
39 runHook preBuild
40 export ZIG_GLOBAL_CACHE_DIR=$TMPDIR/zig-global-cache
41 zig build install -Doptimize=ReleaseSafe --prefix $out
42 runHook postBuild
43 '';
44
45 doCheck = true;
46 checkPhase = ''
47 runHook preCheck
48 zig build test
49 runHook postCheck
50 '';
51
52 dontInstall = true;
53
54 meta = {
55 description = "SMTP client and server library for Zig";
56 license = lib.licenses.mit;
57 mainProgram = "zsmtp";
58 };
59}