Nix devShell use XCode command line tools for react native build

I’m trying to create a devShell for an existing large project that, among other things, runs React Native. When running react-native run-ios it runs an xcodebuild which relies on clang flags that are only valid for the XCode command line tools version of clang.

It seems like nix develop in and of itself depends on clang-wrapper so clang is in my devShells PATH ahead of XCode’s tools which causes my builds to fail when we run xcodebuild as it tries to pass arguments to clang which the devShell version does not support.

$ which clang
$ react-native run-ios
clang-11: error: unknown argument: '-index-store-path'
clang-11: error: cannot specify -o when generating multiple output files

Unfortunately, just shoving all of /Library/Developer/CommandLineTools/usr/bin in front of my PATH when running this command leads to other issues of it then using ld instead of clang for linking which it seems others have run into without any answers.

My flake.nix isn’t doing anything special, just some packages and a few env vars to setup Apple framework SDKs, and I confirmed with just a simple flake that clang is still shadowed by the dev shell:

  outputs = { self, nixpkgs }: 
  let pkgs = import nixpkgs { system = "aarch64-darwin"; };
  in {
	devShells.aarch64-darwin.default = pkgs.mkShell {
         packages = with pkgs; [ cowsay ];

Is there any way to run react native build tooling inside a nix shell? I’ve struggled to find any examples and the docs only really talk about the quirks with creating xcode ios derivations, not devshells that work with existing build tools.

To clarify, I’m currently just trying to get a dev shell suitable to run our existing build pipelines (yarn, node, react-native cli), not fully convert to a nix derivation. I’ve been able to figure out all the other bits, but the react-native build is still stumping me.


Hey josephmr, did you ever find a solution for this? Having the exact same issue.

You can try GitHub - numtide/devshell: Per project developer environments or GitHub - viperML/mkshell-minimal

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.05 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: 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