Ran into this while running nix-build (for buildling a haskell project:
"checking whether the C compiler works... no osx"
This fixed it:
xcode-select --install
This didn't seem to fix the problem. Also ran this:
sudo xcode-select --switch /Library/Developer/CommandLineTools