An SMTP client and server library for Zig implementing RFC 5321.
6.7 kB
197 lines
1# generated by zon2nix (https://github.com/jcollie/zon2nix)
2{
3 lib,
4 linkFarm,
5 fetchzip,
6 fetchurl,
7 fetchgit,
8 runCommandLocal,
9 zig_0_16,
10 zstd,
11 name ? "zig-packages",
12}:
13let
14 unpackZigArtifact =
15 {
16 name,
17 artifact,
18 }:
19 runCommandLocal name
20 {
21 nativeBuildInputs = [ zig_0_16 ];
22 }
23 ''
24 # workaround https://codeberg.org/ziglang/zig/issues/31866
25 # https://github.com/Cloudef/zig2nix/issues/54
26 mkdir "$TMPDIR/src" "$TMPDIR/cache" "$TMPDIR/cache/tmp"
27 touch "$TMPDIR/src/build.zig"
28 hash="$(cd "$TMPDIR/src" && zig fetch --global-cache-dir "$TMPDIR/cache" ${artifact})"
29 mkdir "$out"
30 tar zxvf "$TMPDIR/cache/p/$hash.tar.gz" --directory "$out/" --strip-components=1
31 '';
32
33 fetchZig =
34 {
35 name,
36 url,
37 hash,
38 unpack,
39 }:
40 let
41 artifact =
42 if unpack then
43 fetchzip {
44 inherit url hash;
45 nativeBuildInputs = [ zstd ];
46 }
47 else
48 fetchurl { inherit url hash; };
49 in
50 unpackZigArtifact { inherit name artifact; };
51
52 fetchGitZig =
53 {
54 name,
55 url,
56 hash,
57 }:
58 let
59 parts = lib.splitString "#" url;
60 url_base = builtins.elemAt parts 0;
61 url_without_query = builtins.elemAt (lib.splitString "?" url_base) 0;
62 rev_base = builtins.elemAt parts 1;
63 rev =
64 if builtins.match "^[a-fA-F0-9]{40}$" rev_base != null then rev_base else "refs/heads/${rev_base}";
65 in
66 fetchgit {
67 inherit name rev hash;
68 url = url_without_query;
69 deepClone = false;
70 fetchSubmodules = false;
71 };
72
73 fetchZigArtifact =
74 {
75 name,
76 url,
77 hash,
78 unpack,
79 }:
80 let
81 parts = lib.splitString "://" url;
82 proto = builtins.elemAt parts 0;
83 path = builtins.elemAt parts 1;
84 fetcher = {
85 "git+http" = fetchGitZig {
86 inherit name hash;
87 url = "http://${path}";
88 };
89 "git+https" = fetchGitZig {
90 inherit name hash;
91 url = "https://${path}";
92 };
93 http = fetchZig {
94 inherit name hash unpack;
95 url = "http://${path}";
96 };
97 https = fetchZig {
98 inherit name hash unpack;
99 url = "https://${path}";
100 };
101 };
102 in
103 fetcher.${proto};
104 # The packages, as real directories holding symlinked files, rather than as
105 # a farm of symlinked directories.
106 #
107 # Zig runs a dependency's own build steps with the working directory set to
108 # that dependency, and points at the program to run with a path counted in
109 # directories up from there. Through a symlink the two disagree: Zig counts
110 # from `<farm>/<package>/`, four directories below the root, while the kernel
111 # resolves the working directory to `/nix/store/<hash>`, which is three, so
112 # the path lands one short of where the program is.
113 #
114 # It works anyway when the build directory is `/build`, because the sum then
115 # overshoots into the root and going above the root stays there. It fails
116 # when the build directory is under `/nix/var/nix/builds`, which is where Nix
117 # puts it when the sandbox is off. Real directories make the two depths
118 # agree, so it works either way.
119 #
120 # The files have to be real as well, which is the expensive part and cannot
121 # be avoided. `--symbolic-link` would leave them pointing into each
122 # dependency's own store path, so that the farm is a few megabytes rather
123 # than a second copy of every dependency -- but Zig's
124 # `installHeadersDirectory` walks the directory and copies only the entries
125 # whose kind is `.file`. Symlinked headers are skipped without a word, and
126 # the first thing to include one fails with `'dcimgui.h' not found`.
127 #
128 # `--link` is not the way out. A hard link into a Nix output is a file the
129 # builder did not create: inside the Linux sandbox the store is a separate
130 # mount and `link` fails with `Invalid cross-device link`, while on Darwin it
131 # succeeds and leaves root-owned files in the output, which Nix refuses while
132 # canonicalising with `invalid ownership on file`.
133 #
134 # So it is a real copy, with `--reflink=auto` to share the blocks on a
135 # filesystem that can. `nix store optimise` recovers the duplication after
136 # the fact, hard-linking identical files across the store, which is the
137 # store's own business to do and not a build's.
138 copyFarm =
139 farm: entries: pathDependencyPackages:
140 runCommandLocal farm
141 {
142 # The packages whose own manifest declares a dependency by `.path`.
143 # Zig 0.16.0 cannot build these through `zig build --system`: it spins
144 # in userspace forever, because a `.path` dependency's hash is computed
145 # against the system package directory during the fetch and against the
146 # real global cache afterwards, and in that mode the two disagree. A
147 # package that wants `--system` copies each of these into its build
148 # root and passes `--fork=`; see the README.
149 passthru = { inherit pathDependencyPackages; };
150 }
151 ''
152 mkdir -p "$out"
153 cp --recursive --reflink=auto --dereference --no-preserve=mode \
154 ${linkFarm farm entries}/. "$out/"
155 '';
156in
157copyFarm name
158 [
159 {
160 name = "N-V-__8AAFtMiwHRrbE2kejFyc1FTFciBTZJlJOPGt-eIVGJ";
161 path = fetchZigArtifact {
162 name = "exim";
163 url = "https://github.com/Exim/exim/archive/13835a3c1e057efad7da269c0f93bf2eac850205.tar.gz";
164 hash = "sha256-mqyGOAONL1uvPWZbraGmBjzrsTRW2424lGae0x9CR1U=";
165 unpack = false;
166 };
167 }
168 {
169 name = "N-V-__8AAI5RBAAIsFSqnDYObnOsBo3t9cQMXnvu0vQQRSAf";
170 path = fetchZigArtifact {
171 name = "isemail";
172 url = "https://github.com/dominicsayers/isemail/archive/cfeefc3f2f88cb195053f6a309fa4f640cd369b5.tar.gz";
173 hash = "sha256-bgW2Lj00UluNZWrydCU7sx9332PmbttAAER4fq5ACmo=";
174 unpack = false;
175 };
176 }
177 {
178 name = "sasl-0.0.0-s3YcODkwAQCo2OfGTBE8FKq0VIv6xhQIY_tay5YvReJl";
179 path = fetchZigArtifact {
180 name = "sasl";
181 url = "git+https://git.jcollie.dev/jeff/zig-sasl.git#7c423d857ba07482e6fdc44d2c6581c25206b272";
182 hash = "sha256-Ft4FPCeoZmNmj8lOaE+Py4a2sJ2JzWWGFoolfoQQhGM=";
183 unpack = true;
184 };
185 }
186 {
187 name = "tls-0.1.0-ER2e0jGpBgCkVC-Yp12NgSdHNUtZr52MleJ8roHlUa54";
188 path = fetchZigArtifact {
189 name = "tls";
190 url = "https://github.com/ianic/tls.zig/archive/e04ae448ce7ee70c136d4d48b059314543203809.tar.gz";
191 hash = "sha256-afPTfauIV49IATX0szuOdKLloyqI4XKsyNk8KkasAvg=";
192 unpack = true;
193 };
194 }
195 ]
196 [
197 ]