MacOS SDK, Xcode on Nix Darwin Reoccurance

Hi there! I am the author of the post you linked.
I don’t quite remember how I solved this specific issue, but this is what I have in my flake.nix:

# NOTE: on MacOS, using the clang wrapper in pkgs.mkShell is interfering
# with Bazel compilation, as Bazel is trying to access some Mac-specific
# frameworks using the wrapped clang, and can't find them.
mkShell = if pkgs.stdenv.isDarwin then pkgs.mkShellNoCC else pkgs.mkShell;

So essentially, mkShell is bringing in some wrappers that obfuscate some of the toolchains installed on the host machine, outside the Nix store.

Additionally, this is what I have on my devshell init:

shellHook = lib.optionalString stdenv.isDarwin ''
    # NOTE: on macOS, Go and other derivations bring in an 'xcodebuild' dependency
    # that will mess with the native Xcode.app, preventing developers from running
    # the iOS app on their machines using 'pnpm expo:start:ios' or 'pnpm run ios'.
    #
    # Here we're filtering the /bin path to the 'xcodebuild' dependency brought in,
    # so that 'xcodebuild' resolves to the version installed outside the devshell.
    export PATH="$(echo "$PATH" | tr ':' '\n' | grep -v xcodebuild | paste -sd ':')"
    export PATH="$(echo "$PATH" | tr ':' '\n' | grep -v XcodeDefault | paste -sd ':')"
    export PATH="$(echo "$PATH" | tr ':' '\n' | grep -v coreutils | paste -sd ':')"
  '';

It is mostly relevant for the code path that builds the React Native mobile apps in my monorepo, but maybe it also helps in this case.

Happy debugging!

2 Likes