# generated by zon2nix (https://github.com/jcollie/zon2nix) { lib, linkFarm, fetchzip, fetchurl, fetchgit, runCommandLocal, zig_0_16, zstd, name ? "zig-packages", }: let unpackZigArtifact = { name, artifact, }: runCommandLocal name { nativeBuildInputs = [ zig_0_16 ]; } '' # workaround https://codeberg.org/ziglang/zig/issues/31866 # https://github.com/Cloudef/zig2nix/issues/54 mkdir "$TMPDIR/src" "$TMPDIR/cache" "$TMPDIR/cache/tmp" touch "$TMPDIR/src/build.zig" hash="$(cd "$TMPDIR/src" && zig fetch --global-cache-dir "$TMPDIR/cache" ${artifact})" mkdir "$out" tar zxvf "$TMPDIR/cache/p/$hash.tar.gz" --directory "$out/" --strip-components=1 ''; fetchZig = { name, url, hash, unpack, }: let artifact = if unpack then fetchzip { inherit url hash; nativeBuildInputs = [ zstd ]; } else fetchurl { inherit url hash; }; in unpackZigArtifact { inherit name artifact; }; fetchGitZig = { name, url, hash, }: let parts = lib.splitString "#" url; url_base = builtins.elemAt parts 0; url_without_query = builtins.elemAt (lib.splitString "?" url_base) 0; rev_base = builtins.elemAt parts 1; rev = if builtins.match "^[a-fA-F0-9]{40}$" rev_base != null then rev_base else "refs/heads/${rev_base}"; in fetchgit { inherit name rev hash; url = url_without_query; deepClone = false; fetchSubmodules = false; }; fetchZigArtifact = { name, url, hash, unpack, }: let parts = lib.splitString "://" url; proto = builtins.elemAt parts 0; path = builtins.elemAt parts 1; fetcher = { "git+http" = fetchGitZig { inherit name hash; url = "http://${path}"; }; "git+https" = fetchGitZig { inherit name hash; url = "https://${path}"; }; http = fetchZig { inherit name hash unpack; url = "http://${path}"; }; https = fetchZig { inherit name hash unpack; url = "https://${path}"; }; }; in fetcher.${proto}; # The packages, as real directories holding symlinked files, rather than as # a farm of symlinked directories. # # Zig runs a dependency's own build steps with the working directory set to # that dependency, and points at the program to run with a path counted in # directories up from there. Through a symlink the two disagree: Zig counts # from `//`, four directories below the root, while the kernel # resolves the working directory to `/nix/store/`, which is three, so # the path lands one short of where the program is. # # It works anyway when the build directory is `/build`, because the sum then # overshoots into the root and going above the root stays there. It fails # when the build directory is under `/nix/var/nix/builds`, which is where Nix # puts it when the sandbox is off. Real directories make the two depths # agree, so it works either way. # # The files have to be real as well, which is the expensive part and cannot # be avoided. `--symbolic-link` would leave them pointing into each # dependency's own store path, so that the farm is a few megabytes rather # than a second copy of every dependency -- but Zig's # `installHeadersDirectory` walks the directory and copies only the entries # whose kind is `.file`. Symlinked headers are skipped without a word, and # the first thing to include one fails with `'dcimgui.h' not found`. # # `--link` is not the way out. A hard link into a Nix output is a file the # builder did not create: inside the Linux sandbox the store is a separate # mount and `link` fails with `Invalid cross-device link`, while on Darwin it # succeeds and leaves root-owned files in the output, which Nix refuses while # canonicalising with `invalid ownership on file`. # # So it is a real copy, with `--reflink=auto` to share the blocks on a # filesystem that can. `nix store optimise` recovers the duplication after # the fact, hard-linking identical files across the store, which is the # store's own business to do and not a build's. copyFarm = farm: entries: pathDependencyPackages: runCommandLocal farm { # The packages whose own manifest declares a dependency by `.path`. # Zig 0.16.0 cannot build these through `zig build --system`: it spins # in userspace forever, because a `.path` dependency's hash is computed # against the system package directory during the fetch and against the # real global cache afterwards, and in that mode the two disagree. A # package that wants `--system` copies each of these into its build # root and passes `--fork=`; see the README. passthru = { inherit pathDependencyPackages; }; } '' mkdir -p "$out" cp --recursive --reflink=auto --dereference --no-preserve=mode \ ${linkFarm farm entries}/. "$out/" ''; in copyFarm name [ { name = "N-V-__8AAFtMiwHRrbE2kejFyc1FTFciBTZJlJOPGt-eIVGJ"; path = fetchZigArtifact { name = "exim"; url = "https://github.com/Exim/exim/archive/13835a3c1e057efad7da269c0f93bf2eac850205.tar.gz"; hash = "sha256-mqyGOAONL1uvPWZbraGmBjzrsTRW2424lGae0x9CR1U="; unpack = false; }; } { name = "N-V-__8AAI5RBAAIsFSqnDYObnOsBo3t9cQMXnvu0vQQRSAf"; path = fetchZigArtifact { name = "isemail"; url = "https://github.com/dominicsayers/isemail/archive/cfeefc3f2f88cb195053f6a309fa4f640cd369b5.tar.gz"; hash = "sha256-bgW2Lj00UluNZWrydCU7sx9332PmbttAAER4fq5ACmo="; unpack = false; }; } { name = "sasl-0.0.0-s3YcOPiJAQCy9rnR9LEZY_Zc_x0oK6yc1FUCD57I2jvc"; path = fetchZigArtifact { name = "sasl"; url = "git+https://git.jcollie.dev/jeff/zig-sasl.git#c6452ffcb932c6cbf34651be2acd694cc18f2fd3"; hash = "sha256-6ddHRVnU7Ma6oadl/N+rQD/bgN7YTUljvDt2ZPzlxgw="; unpack = true; }; } { name = "tls-0.1.0-ER2e0jGpBgCkVC-Yp12NgSdHNUtZr52MleJ8roHlUa54"; path = fetchZigArtifact { name = "tls"; url = "https://github.com/ianic/tls.zig/archive/e04ae448ce7ee70c136d4d48b059314543203809.tar.gz"; hash = "sha256-afPTfauIV49IATX0szuOdKLloyqI4XKsyNk8KkasAvg="; unpack = true; }; } ] [ ]