feat(build): add a macOS cross-architecture Nix dev shell - #1761
Merged
Conversation
`nix develop .#cross` on macOS exposes the OTHER darwin architecture's zlib, so `scripts/build.sh --arch <target>` can link an x86_64 binary on Apple Silicon and vice versa. The native clang already cross-emits object code via -arch; zlib is the product's single link-time dependency, and the host-arch copy cannot satisfy a cross link, which is the whole gap. Darwin-gated and opt-in: the attribute set is empty on Linux, the default shell is untouched, flake.lock is unchanged and no new flake input is introduced. The shell deliberately does not use inputsFrom, since that would put the host-arch zlib back on the link path. Distilled from #724 by Kris Williams. That version also wired libgit2 via pkg-config, which is now dead weight: libgit2 was removed project-wide for GPL-licensing reasons and appears nowhere in the tree, so both it and pkg-config are dropped here — leaving zlib as the only library the cross shell needs to place. Validated by parsing the flake with nix-instantiate in a nixos/nix container (no Nix toolchain on the maintainer host), which also confirms the shellHook's ''${...} escaping resolves to literal shell expansions. Evaluating or entering the shell needs a macOS host with Nix; no CI leg exercises it, as noted on the original PR. Addresses #705. Co-authored-by: Kris Williams <115474+kriswill@users.noreply.github.com> Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(build): add a macOS cross-architecture Nix dev shell
Addresses #705. Distilled from #724 by @kriswill, credited via
Co-authored-by.What
nix develop .#crosson macOS exposes the other darwin architecture's zlib, soscripts/build.sh --arch <target>can link an x86_64 binary on Apple Silicon and vice versa.The native clang already cross-emits object code via
-arch(that's whatscripts/env.sh'sARCHFLAGSdoes, fixed in #723). The only remaining gap is the link: zlib is the product's single link-time dependency (-lz), and the host-arch copy cannot satisfy a cross link. This shell puts the target-arch zlib on the include and link paths, and nothing else.Cost
Close to zero:
crossDevShellsreturns{}on Linux, so the attribute doesn't exist there.flake.lockuntouched, no new flake input. The target-arch packages resolve through the same pinned nixpkgs, and come from prebuilt substitutes, so entering the shell is a download rather than a cross-build of a dependency tree.One deliberate design point: the cross shell does not use
inputsFromthe default package. Doing so would put the host-arch zlib back on the link path, which is exactly the wrong-arch copy the shell exists to displace.What changed from #724
The original also wired
libgit2throughpkg-config. That's now dead weight: libgit2 was removed project-wide for GPL-licensing reasons, and I verified it appears nowhere in the tree — not inflake.nix, not in any Makefile. Carrying it forward would have reintroduced a GPL-adjacent reference for a library we no longer link. Both it andpkg-configare dropped, leaving zlib as the only library the cross shell needs to place, which also makes the shell hook considerably smaller.Verification, stated honestly
There is no Nix toolchain on this machine, so I validated by parsing the flake with
nix-instantiate --parseinside anixos/nixcontainer. That confirms the syntax and — the part most likely to break — that the shell hook's''${...}escaping resolves to literal shell expansions rather than Nix interpolations.What that does not cover: actually evaluating the derivation or entering the shell, which needs a macOS host with Nix installed. @kriswill validated the original shell end-to-end and posted a transcript; this version is that shell minus the libgit2/pkg-config wiring, so the untested delta is a deletion. If anyone with Nix on macOS wants to confirm
nix develop .#crossbefore this merges, I'd welcome it.