See the entire conversation

Any @nixpkg @nixos_org savvy people out there? Having read almost everything I could find about Nix and cross-compilation, I still don't fully understand whether it's possible to cross-compile on Linux for Darwin (both x86_64). Should I even try? /cc @grhmc
17 replies and sub-replies as of Oct 15 2021

I’m pretty sure it is possible, yes, but only if you’re not linking to any MacOS libraries. IE you’d need to be targeting *pure* Darwin.
Another approach to cross would be having macOS build hosts that you remote build on.
It is probably nearly possible, but there's enough issues with e.g. libSystem impurities and SDK licenses to have scared me off from trying it in earnest.
Yeah to clarify my remote build approach to the problem is “just don’t, build natively”
You'd need to copy the macOS platform SDKs for that, and either a copy of the cctools port, or a custom build of clang+llvm with additional tools enabled not found in the regular distribution, and then you need a good cmake toolchain file to use all of that.
I've got the Linux cctools port prebuilt here, along with multiple GitHub Actions you can reuse and adapt, including one that creates tarballs of the files you'd need from Xcode using the GHA macOS build runners:
Releases · awakecoding/llvm-prebuilt
LLVM prebuilt distribution. Contribute to awakecoding/llvm-prebuilt development by creating an account on GitHub.
I haven't got all the way to make proper macOS/iOS cmake toolchain files that can work on Linux yet, but I've got cross-compilation tools for Linux (cross-distro!) and working Windows MSVC cross-compilation using clang-cl:
GitHub - Devolutions/CBake: Baking CMake toolchain files like they were cookies
Baking CMake toolchain files like they were cookies - GitHub - Devolutions/CBake: Baking CMake toolchain files like they were cookies
But if somewhere were to do it, it would mostly be a matter of taking one of those iOS CMake toolchain files and replacing all the calls to "xcode-select -p" and "xcrun" that are normally used on a macOS host to find the macOS platform SDKS and Apple Clang
I think so, surely saw the other stuff from that person, but thanks.
I remember seeing and thinking that some smart people could definitely make it useful in Nixpkgs for cross-compilation purposes.… explains that you can't (currently)
Besides what I said below about "probably not quite", yes definitely try a `nix-build '<nixpkgs>' --arg crossSystem '{ config = "x86_64-unknown-linux-gnu"; }' -A hello` or whatever when in doubt. Never hurts to try!
If you are willing to break EULAs, you can frankenstein yourself a macOS SDK, which will in principle allow you to cross compile. For those tools where you have to rely on the open source versions (e.g. your compiler, linker, …) expect to potentially run into bugs.
I bought a MacBook pro just to be a remote builder. If that tells you anything