I’ve stumbled into a particularly tricky issue when building a package in Nix. The package in question builds a Nim lang library with lots of dependencies. Along the way, Nim compiler invokes
clang and provides header search paths to it.
nix-build, the build fails with a message that a particular header cannot be found, and dumps the compiler invocation. It is clear that the header is there because the relevant header search path is included (it belongs to another Nix package). What is strange is that if i enter
nix-shell and run
genericBuild, it all works fine.
What could possibly cause this? Tried to compare environment variables between
nix-shell, everything is identical, except for unrelated stuff. I’m completely confused. Will be super-grateful for any pointers.
Intriguing. Can you post the
default.nix file so someone can reproduce this locally and maybe help you figure out what’s going on?
Thanks for your response @roni ! Just to add more context, i’ve posted this same issue to Reddit channel https://www.reddit.com/r/NixOS/comments/m5gqtc/difference_between_nixbuild_and_nixshell/, and as it turned out, it seems that
source $stdenv/setup is what breaks things. Meaning, if i enter
nix-shell and run
genericBuild, it’s ok, but if i do
source $stdenv/setup before running
genericBuild, it cannot find the header anymore!
Also, this might only affect macOS - i’ve asked my colleague to run this on Linux (NixOS actually), and it built just fine.
This is the actual code: https://github.com/status-im/nim-status/tree/feat/nix-build. In order to reproduce the problem, run
nix-build --pure --attr targets.main.nim-status.host from within parent source directory. This will run the derivation in
So right now i’m trying to figure out what’s the problem by looking at
I’m glad you’re making some progress. I’m sorry I can’t help further, as I don’t run any MacOS boxes. Good luck!