Nix-darwin cannot compile using libgccjit

Hi al,

I’ve got a M3 laptop and decided to try out nix to bootstrap it. I’ve followed instructions from Dream Of Autonomy here. I’ve read the tutorial on nix lang and it feels familiar if a bit semi-colon happy.

Everything is fine for the simple stuff the video included, but I got an error compiling emacs30

configure: error: The installed libgccjit failed to compile and run a test program using
the libgccjit library; see config.log for the details of the failure.
The test program can be found here:
Tutorial part 1: “Hello world” — libgccjit 16.0.0 (experimental ) documentation.
You can try compiling it yourself to investigate the issues.
Please report the issue to your distribution if libgccjit was installed
through that.
You can find the instructions on how to compile and install libgccjit from
source on this site:
Making sure you're not a bot!.

I tried to compile the example program linked and got this error:

fatal error: _stdio.h: No such file or directory

I messed around with it and had to add -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/ to the gcc command to get the binary compiled.

However when I ran the binary, I got this error:

dyld[53420]: Library not loaded: /nix/store/jjgan3zjj4j74wfqbkn501agzhmfhmcb-libgccjit-14.2.1.20250322/lib/libgccjit.0.dylib
Referenced from: <05DCC1F1-AF14-36DA-9C84-BCDF3FAAF532> /Users/lewang/.config/nix-darwin/libgccjit-test/tut01-hello-world
Reason: tried: ‘/nix/store/jjgan3zjj4j74wfqbkn501agzhmfhmcb-libgccjit-14.2.1.20250322/lib/libgccjit.0.dylib’ (duplicate LC_RPATH ‘@loader_path’), ‘/System/Volumes/Preboot/Cryptexes/OS/nix/store/jjgan3zjj4j74wfqbkn501agzhmfhmcb-libgccjit-14.2.1.20250322/lib/libgccjit.0.dylib’ (no such file), ‘/nix/store/jjgan3zjj4j74wfqbkn501agzhmfhmcb-libgccjit-14.2.1.20250322/lib/libgccjit.0.dylib’ (duplicate LC_RPATH ‘@loader_path’), ‘/usr/local/lib/libgccjit.0.dylib’ (no such file), ‘/usr/lib/libgccjit.0.dylib’ (no such file, not in dyld cache)

I think I’m missing something fundamental about how the develop environment is assembled.

What am I missing?

Nothing it is a known issue,

However it is usually referred to in emacs related threads as emacs uses libgccjit for native compilation.

I thought the workround is in current nixpkgs

See emacs: disable native compilation on Darwin by emilazy · Pull Request #401160 · NixOS/nixpkgs · GitHub for the workround in nixpkgs.
And setup-hooks: add fix-darwin-duplicate-lc-rpaths by chadac · Pull Request #398156 · NixOS/nixpkgs · GitHub for discussion on other fixes