Best Practices for Expo / React Native development with devenv

Hi everyone,

I’m working on setting up my Macbook for mobile app development with Expo, and I’m looking for some guidance on the best practices, especially when using devenv.

My current setup involves manually installing some tools outside of Nix:

With this initial setup, things seem to be working fine for the most part. My first question is: Is this a reasonable approach, or are there better recommendations for managing Xcode and its command-line tools in a Nix-Darwin context?

Next, I’m trying to integrate devenv into my workflow, and I’ve hit a couple of snags.

The first issue I encountered was related to an incorrect clang version within the devenv shell. I was able to resolve this by following the advice in this discourse post and using stdenvNoCC in my devenv.yaml configuration.

My second question related to this is: Is using stdenvNoCC the recommended way to handle this clang conflict?

After fixing the clang issue, I ran into this problem. It feels like a configuration issue on my end, although I have created an issue. Basically, the issue is that the tools installed in my default shell are not available in the devenv environment (it resolves its own thing inside).

I’ve researched this topic and have found some related threads like:

However, I haven’t found a clear and reliable solution that addresses this.

So, my third and final question is: What are the recommended practices for setting up devenv on Nix-Darwin when command-line tools and Xcode are required for development? How can I ensure that my default shell tools are accessible within the devenv environment, or is there a better approach to this?

Any insights or suggestions would be greatly appreciated! Thanks in advance.

P.S. If anyone knows of any good documentation or resources that outline a recommended or best-practice approach for this setup, I’d be very grateful if you could share them!

nix-homebrew (GitHub - zhaofengli/nix-homebrew: Homebrew installation manager for nix-darwin) can grab stuff using mas; not sure about xcode under homebrew but i’d be surprised if not. nix-homebrew lets you manage that stuff mostly declaratively. This video is pretty useful about that: https://www.youtube.com/watch?v=Z8BL8mdzWHI&t=282s&pp=ygUMbml4LWhvbWVicmV3 . I think, however, it would not be manageable via devenv, but only via nix-darwin.

Not sure about the stderr/stdout problem with clang/devenv, sorry.

1 Like

Last time I tried to setup development for a bazel/go project using nixos on mac I gave up. I probably should try again now that nixos 24.11 has been released. I don’t have high hopes though.

This was so much easier on Linux.

1 Like

Thanks @chrism! This is exactly what I am doing right now. Things are working fine as long as I don’t go into a devshell. Once I am inside the devshell, it uses some non-standard versions of xc* tools and things break.

What I would love to do is to use the tools on the host inside devshells as well. But, I haven’t had any luck on that so far. :frowning:

1 Like

Thanks @penguin_brian, I saw this thread and tried the PATH manipulation that was recommended in the thread, that didn’t work for me either.

For anyone that ends up here, I ended up using xcrun from Xcode/command-line tools instead of the Nix version that uses the xcrun from the deprecated xcbuild.

Before sharing how, a quick note: This breaks hermiticity as you’ll be using a tool not managed by Nix. While this might not be the recommended approach, I personally prefer using Apple’s version since many ecosystem tools are built around it (Expo, for example, relies on specific messages going to stdout/stderr - that’s fixed in xcbuild: fix interactive applications run by xcrun by midchildan · Pull Request #359721 · NixOS/nixpkgs · GitHub, but who knows what other deviations we might have). Again, this might not be the community recommended way, this is what worked for me and I’m happy with it.

To implement this, add the following to your devshell shellHook (or enterShell in devenv):

export PATH=$(echo $PATH | sd "${pkgs.xcbuild.xcrun}/bin" "")
unset DEVELOPER_DIR

Special thanks to @reckenrode for all the help in arriving at this solution!

2 Likes