Hello,
thanks to the great work on nix-darwin, the SDKs are now nicely separated.
I’m trying to create a devShell for a fairly complex project that uses:
pkgs.llvmPackages_16.stdenv
to build a few C++ files- Xcode’s (
pkgs.darwin.xcode_16_2
) clang (xcrun -sdk iphoneos... -find clang
) to build a binary for iOS.
Getting the second part to work seems difficult, because xcodebuild
doesn’t recognize darwin.xcode
. Normally you’d set DEVELOPER_DIR
and SDKROOT
to point to darwin.xcode/...
. But here it will break the standard env.
What I would like to get to work is that xcrun
/xcodebuild -showsdks
uses the SDKs from darwin.xcode
while still leaving the CMake/stdenv
environment intact. See the example (nix build -L github:pascalj/nix-darwin-example
):
{
# ...
outputs =
{ nixpkgs, ... }:
let
system = "aarch64-darwin";
pkgs = import nixpkgs { inherit system; };
# Xcode version I'd like to use
xcode = pkgs.darwin.xcode_16_2;
in
{
packages."${system}".default = pkgs.llvmPackages_16.stdenv.mkDerivation {
name = "hello-world";
src = ./.;
nativeBuildInputs = [ pkgs.cmake xcode ];
preBuild = ''
# DEVELOPER_DIR and SDKROOT point to pkgs.apple-sdk
env
# Lists only "macOS 11.3 -sdk macosx11.3"
${pkgs.xcodebuild}/bin/xcodebuild -showsdks
'';
};
};
}
In the example flake on GH I set CMAKE_OSX_SYSROOT
to xcode_16_2
’s SDKROOT
, so you can see the failing build: /nix/store/j64i7nhzwx2gvbsi2glnzywlbvpriwvw-libcxx-16.0.6-dev/include/c++/v1/ratio:99:11: error: reference to unresolved using declaration
. It also fails to look up files from the C++ stdlib.
If I understand it correctly, a proper solution would be to bootstrap using darwin.xcode
, so that llvmPackages
shares the same SDKROOT
(basically introduce a custom pkgs.apple-sdk
with all other SDKs). However, that seems like a larger undertaking and it would mean that there can only ever be one Xcode available.
Is there a simple alternative that I’m missing, e.g. just wrapping xcodebuild/xcrun? If not, do you have any hints for getting started with the custom version?
Any help is welcome - thank you!