Nix devShell use XCode command line tools for react native build

A friend of mine ran into this problem, I found a solution:

It’s not nix develop that depends on clang, but rather pkgs.mkShell. It’s a wrapper around stdenv.mkDerivation (see Nixpkgs 23.11 manual | Nix & NixOS). So it uses the stdenv build environment, which includes a C compiler, seemingly clang on macOS.

There’s also stdenvNoCC, which doesn’t include a C compiler. That’s useful for builds that don’t need one, and can also help here. So the solution is just to use pkgs.mkShellNoCC instead of pkgs.mkShell, which is an (sadly undocumented) variant of mkShell that overrides stdenv with stdenvNoCC.

(it’s defined in all-packages.nix from nixpkgs: mkShellNoCC = mkShell.override { stdenv = stdenvNoCC; };)

I haven’t tested this myself with react-native, but the friend confirmed it works with react-native and mkShellNoCC.

Note: https://github.com/viperML/mkshell-minimal as suggested by @azuwis should work too as it also doesn’t include a C compiler, but mkShellNoCC is included in nixpkgs anyway, so it might be easier to use.

Edit: I made a PR to add a little documentation section for mkShellNoCC: doc: add section about mkShellNoCC by Eisfunke · Pull Request #259567 · NixOS/nixpkgs · GitHub

2 Likes