"error: tool 'gcc' not found" on macOS 14.7.1 with M3

I am running into a strange problem on Apple ARM macOS 14.7.1.

Whenever I’m inside a Nix shell, gcc becomes inaccessible.

Steps to reproduce:

  1. nix-shell -p pkg-config
  2. gcc --version
$ gcc --version
error: tool 'gcc' not found

Notably, on the same machine, gcc --version outside of a Nix shell give the expected output.

$ gcc --version
Apple clang version 16.0.0 (clang-1600.0.26.4)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

This problem persists even after I factory-reset the laptop and install Nix from scratch. I’ve tried this several times now.

Notably, I have not been able to reproduce the problem on a different Apple ARM macOS Sonoma 14.7.1 machine I own. Installing Nix from scratch on that machine, entering a Nix shell, and issuing the gcc --version command gives the expected output.

clang version 16.0.6
Target: arm64-apple-darwin
Thread model: posix
InstalledDir: /nix/store/44hqr4414m3jldixkm4cq47q5pnpy83d-clang-16.0.6/bin

check your PATH before and after entering nix-shell

1 Like

Do you have Xcode installed on one machine but not the other? That GCC version is for the Clang alias found in the Xcode toolchain via the /usr/bin/gcc stub. If you don’t have Xcode (or the command-line tools) installed, you’ll get an error about a missing gcc tool.

Edit: I may have misread. This is probably xcbuild: look in native toolchain when `/usr/bin` is in path by reckenrode · Pull Request #353893 · NixOS/nixpkgs · GitHub. Try updating your channels on the other machine.

Does gcc --version outside of a Nix shell give the same results on both machines?

Yes, gcc --version gives the expected output on both machines.

$ gcc --version
Apple clang version 16.0.0 (clang-1600.0.26.4)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

@reckenrode I have the Xcode CLI tools installed on both machines. gcc is accessible outside of Nix shells on the problem machine.

I would definitely check whether you’re using the same Nixpkgs revision on both machines, then. If you update the channel on both I expect it’ll start working on both.

Ah, xcbuild: find system toolchain on macOS Sonoma and earlier by midchildan · Pull Request #357132 · NixOS/nixpkgs · GitHub may be relevant too.

1 Like

That’s almost certainly the problem. Thanks, very much, Emily. (Admittedly, I haven’t tested it. When I nix-shell with the staging channel, it tries to build and test the universe and eventually some tests fail. I didn’t have much time to look into it further.)