Origin of CC env variable in nix-shell

Inside nix-shell --pure -p hello the CC variable is set to gcc on Linux and to clang on aarch64 Darwin. Where is the logic that decides this? I figured it gets set by stdenv but with nix-shell -p stdenvNoCC the result is the same.

nix-shell -p always uses stdenv, since it constructs an evironment based on stdenv.mkDerivation with the supplied packages in buildInputs.

Running nix-shell -E 'with import <nixpkgs> {}; stdenvNoCC.mkDerivation { name = "f"; }' --pure will drop you in a shell without CC set. The variables are actually set by cc-wrapper, not stdenv itself, in pkgs/build-support/cc-wrapper/setup-hook.sh.

3 Likes