# 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-__8AAJ77GgCr4jV_q5d8vuaUZIWMrHbXUMYV7il4sgLB"; path = fetchZigArtifact { name = "cldr_core"; url = "https://registry.npmjs.org/cldr-core/-/cldr-core-48.2.0.tgz"; hash = "sha256-UxDgx6BsH+uD3I5UyFhLvgucLqgyAXKhjVQZhrEkWF0="; unpack = false; }; } { name = "N-V-__8AAGszqAU24FLBIkgdecxizqeniOtXvaJyJNhnerSV"; path = fetchZigArtifact { name = "cldr_dates"; url = "https://registry.npmjs.org/cldr-dates-full/-/cldr-dates-full-48.2.0.tgz"; hash = "sha256-Albxzv7KFPfVFb5Ict2kj83X51OBQw8lqv0BQ+rltDA="; unpack = false; }; } { name = "N-V-__8AAP5iTQJ7vhRS_dLVKhpakujqxJsIbu89VYJgXryk"; path = fetchZigArtifact { name = "cldr_numbers"; url = "https://registry.npmjs.org/cldr-numbers-full/-/cldr-numbers-full-48.2.0.tgz"; hash = "sha256-LRehRTxVmmIRLK7tUuC8/jy4U5yZ0jmue37U0IJ2edk="; unpack = false; }; } { name = "datetime-0.0.1-6-va79gDDwCD7vUCwnd8YeSBQlXh5xq-yjnhzeT7VCYw"; path = fetchZigArtifact { name = "datetime"; url = "git+https://git.jcollie.dev/jeff/zig-datetime.git#bd76e05460dba019f7749e44a37ea5afe6c49609"; hash = "sha256-hVLUAc9Mm5HjLSkUURlb4nW2sn78ZvrWKsaC1cdzCuE="; unpack = true; }; } { name = "zig_mime-0.0.0-4saPF8Z6BQB9wid4v2A2LrT_OyhQYZUwQDx7aCdpm0Hc"; path = fetchZigArtifact { name = "mime"; url = "git+https://git.jcollie.dev/jeff/zig-mime.git#efdb9e8a7fd4a2d9c8318c663771832289259e89"; hash = "sha256-Q8B/Rdb4GuxEdwhbdrRPeYq5B81ulgijTbujBkclG80="; unpack = true; }; } { name = "N-V-__8AAHNhQgCiWfjOCo_LQgx55jnHBr2Z61ZAqPU9n5Uo"; path = fetchZigArtifact { name = "moment"; url = "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz"; hash = "sha256-UiGan+5eH6reTHJTbBc8VM7dXiYZJy3QwlGjCur83ow="; unpack = false; }; } { name = "N-V-__8AABybDwDd46ZHFqBjb0twea7p9vwNzdSzUHFwA55f"; path = fetchZigArtifact { name = "tzcode"; url = "https://data.iana.org/time-zones/releases/tzcode2026d.tar.gz"; hash = "sha256-L1yff+Kea4y4Y1g2Z4hLjOF7CkhTVaBUtZHGvfzYF5E="; unpack = false; }; } { name = "N-V-__8AAFiAFQDNovBNmFwF3hznlSfpY7KwAN3Jy7rhie29"; path = fetchZigArtifact { name = "tzdata"; url = "https://data.iana.org/time-zones/releases/tzdata2026d.tar.gz"; hash = "sha256-DLKqjjM8PcBJutxCoMYfIZh7jNROEH+pALrXZKrMd2c="; unpack = false; }; } { name = "win32-42.0.39-preview-mX5pFS564gPTezZn4v3TMxRnfJUrZNx1B_F2p2HKXOeG"; path = fetchZigArtifact { name = "zigwin32"; url = "git+https://github.com/marlersoft/zigwin32#9f15c276b4e9d05afd34a10d8662a7dfc34647ea"; hash = "sha256-JCmUrieEnOKQViUGjPNrlGwJMMM4X/BjC3iur5fRbqA="; unpack = true; }; } ] [ ]