From 13a21fc047d26827ee324268de427f0862289ab6 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Wed, 9 Sep 2026 13:17:40 -0500 Subject: [PATCH] nix: use --reflink=auto instead of --link Another Zig build system quirk worked around. --- build.zig.zon.nix | 25 +++++++++++++++++++------ flake.lock | 6 +++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/build.zig.zon.nix b/build.zig.zon.nix index f2356800d..b9f70311a 100644 --- a/build.zig.zon.nix +++ b/build.zig.zon.nix @@ -111,11 +111,24 @@ # puts it when the sandbox is off. Real directories make the two depths # agree, so it works either way. # - # Only the directories have to be real. `--symbolic-link` leaves the files - # pointing into each dependency's own store path, so the farm is a few - # megabytes of symlinks rather than a second copy of every dependency, two - # projects sharing a dependency share it in the store, and a file keeps the - # mode it was fetched with. + # 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 { @@ -130,7 +143,7 @@ } '' mkdir -p "$out" - cp --recursive --link --dereference --no-preserve=mode \ + cp --recursive --reflink=auto --dereference --no-preserve=mode \ ${linkFarm farm entries}/. "$out/" ''; in diff --git a/flake.lock b/flake.lock index e2b6600f1..532b33965 100644 --- a/flake.lock +++ b/flake.lock @@ -108,11 +108,11 @@ ] }, "locked": { - "lastModified": 1788972981, - "narHash": "sha256-MxVNwu1U7XWL/8HYzDDiaHjfIFE2yz/7J64vRUO7ZzA=", + "lastModified": 1788977680, + "narHash": "sha256-3vgICcen5N2oAlQrijqJhxn8HEsnXASGPxQLJVYzX0Q=", "owner": "jcollie", "repo": "zon2nix", - "rev": "36de3f085bffe0335774392111bff0ab0e0efeba", + "rev": "7b9c43312de08e176097b8c8920f0dd1a46982be", "type": "github" }, "original": {