Changing the stdenv on x86_64-darwin to use the apple command line tools

Hi folks, I’m running x86_64-darwin, and I’m currently trying to figure out how to make a flake that can build a package (specifically, I’m using zig as the package here) which requires a newer version of libSystem that is currently picked by default on x86_64-darwin (it seems we’re using one from macos 10.12 from macOS libSystem and other libraries haven't been updated since macOS Sierra · Issue #86299 · NixOS/nixpkgs · GitHub).

It does look like nixpkgs includes the binary apple_sdk for at least 11.0, which seems like it should work. I’ve tried to use apple_sdk_11_0 to build zig, but I’ve run into the issue that while it does seem to get the libSystem needed to be used, the libcxx in the stdenv appears to (potentially) be incompatible with the llvm 13 headers (zig requires llvm 13), and complains:

In file included from /tmp/nix-build-zig.drv-0/source/src/zig_llvm-ar.cpp:14:
In file included from /nix/store/hxzkwm61h1pjcdp63wi4zr7g4v5wq683-llvm-13.0.0-dev/include/llvm/ADT/StringExtras.h:16:
In file included from /nix/store/hxzkwm61h1pjcdp63wi4zr7g4v5wq683-llvm-13.0.0-dev/include/llvm/ADT/APSInt.h:17:
In file included from /nix/store/hxzkwm61h1pjcdp63wi4zr7g4v5wq683-llvm-13.0.0-dev/include/llvm/ADT/APInt.h:19:
In file included from /nix/store/hxzkwm61h1pjcdp63wi4zr7g4v5wq683-llvm-13.0.0-dev/include/llvm/Support/MathExtras.h:19
/nix/store/1k8br8gxlsqp41i0a6279qrvxscpw9n6-libcxx-7.1.0-dev/include/c++/v1/cmath:313:9: error: no member named 'signb
using ::signbit;
      ~~^
/nix/store/1k8br8gxlsqp41i0a6279qrvxscpw9n6-libcxx-7.1.0-dev/include/c++/v1/cmath:314:9: error: no member named 'fpcla
using ::fpclassify;
      ~~^
/nix/store/1k8br8gxlsqp41i0a6279qrvxscpw9n6-libcxx-7.1.0-dev/include/c++/v1/cmath:315:9: error: no member named 'isfin
using ::isfinite;
      ~~^
/nix/store/dkj8y8djzhr7cr38s0x6k0fjnaq1y7b8-libSystem-11.0.0/include/math.h:752:12: note: 'finite' declared here
extern int finite(double)
           ^

Similar issues occur if using clang12Stdenv. clang13Stdenv does not exist.

It seems like using the clang shipped by apple in their sdk might resolve things here, is there a way to use that compiler?

Alternately, perhaps a clang13Stdenv could make this work. If so, is there a way to get a clang13Stdenv on x86_64-darwin?

Relatedly, is there a way to make the build non-pure and use an existing SDK install outside the nix store?

Here’s my work-in-progress flake for reference: zig-flake/flake.nix at 23d80ceb657d89939c13ceb60fdb751bf2608dca · jmesmon/zig-flake · GitHub

Alternatively, you could use the statically-linked binaries provided by the Zig Software Foundation in Nix via arqv/zig-overlay:

Here’s an example of how I integrated it into my dotfiles: Install `zig` from `zig-overlay` · evanrelf/dotfiles@c936e4f · GitHub

2 Likes