Fatal error: 'os/availability.h' file not found

Hi,

I am running OSX Catalina (10.15.2), nix-shell (Nix) 2.3.1 and managed to install go (go1.13.5 darwin/amd64) and everything looks fine so far. But, when I try to build a go project in a nix-shell I get this error:

# crypto/x509
In file included from /nix/store/6ds9ms1k7xb50w6l6fkw29gvf37bkkws-go-1.13.5/share/go/src/crypto/x509/root_cgo_darwin.go:16:
In file included from /nix/store/2zx4fx20bnmvvf6vdrsjqj79kvml7cmm-apple-framework-CoreFoundation/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:43:
In file included from /nix/store/2zx4fx20bnmvvf6vdrsjqj79kvml7cmm-apple-framework-CoreFoundation/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h:18:
/nix/store/2zx4fx20bnmvvf6vdrsjqj79kvml7cmm-apple-framework-CoreFoundation/Library/Frameworks/CoreFoundation.framework/Headers/CFAvailability.h:21:10: fatal error: 'os/availability.h' file not found
#include <os/availability.h>

So I guess there is a problem with the linking of the header files.

This issue is very similar to my problem: fatal error: 'os/availability.h' file not found #include <os/availability.h> · Issue #23859 · NixOS/nixpkgs · GitHub but unfortunately there is no resolution.

Does anybody have a suggestion how to fix this?

(Yes, I am new to NixOs)

thanks!

That header is part of Libsystem which should be included in every build environment. Perhaps something in the build is using the system compiler instead. Using nix-shell --pure might help if that’s the case.

You are right. The problem is rather with OSX (Catlina) than NixOs. Adding a CPATH environment variable helped the compiler to find the Header files:

export CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/

This thread was useful:

That might work but it’s impure, unlike homebrew we build everything from scratch including the compiler, etc. We don’t depend on the CLT and this won’t work if those are not installed, but I think something in the build process is using clang the CLT instead of $CC which points to our version.

While this won’t solve the compiler problem, adding the following to shell.nix expression is equivalent to your workaround but will work even if the CLT are not present.

CPATH = "${darwin.Libsystem}/include";