1 { appleDerivation', lib, stdenv, stdenvNoCC, buildPackages, pkgsBuildBuild
2 , bootstrap_cmds, bison, flex
3 , gnum4, unifdef, perl, python3
7 appleDerivation' (if headersOnly then stdenvNoCC else stdenv) (
8 let arch = if stdenv.hostPlatform.isx86_64 then "x86_64" else "arm64";
11 depsBuildBuild = [ buildPackages.stdenv.cc ];
13 nativeBuildInputs = [ bootstrap_cmds bison flex gnum4 unifdef perl python3 ];
15 patches = lib.optionals (lib.versionOlder stdenv.hostPlatform.darwinSdkVersion "11") [ ./python3.patch ];
18 substituteInPlace Makefile \
19 --replace "/bin/" "" \
20 --replace "MAKEJOBS := " '# MAKEJOBS := '
22 substituteInPlace makedefs/MakeInc.cmd \
23 --replace "/usr/bin/" "" \
24 --replace "/bin/" "" \
25 --replace "-Werror " ""
27 substituteInPlace makedefs/MakeInc.def \
28 --replace "-c -S -m" "-c -m"
30 substituteInPlace makedefs/MakeInc.top \
31 --replace "MEMORY_SIZE := " 'MEMORY_SIZE := 1073741824 # '
33 substituteInPlace libkern/kxld/Makefile \
34 --replace "-Werror " ""
36 substituteInPlace SETUP/kextsymboltool/Makefile \
37 --replace "-lstdc++" "-lc++"
39 substituteInPlace libsyscall/xcodescripts/mach_install_mig.sh \
40 --replace "/usr/include" "/include" \
41 --replace "/usr/local/include" "/include" \
42 --replace 'MIG=`' "# " \
43 --replace 'MIGCC=`' "# " \
44 --replace " -o 0" "" \
45 --replace '$SRC/$mig' '-I$DSTROOT/include $SRC/$mig' \
46 --replace '$SRC/servers/netname.defs' '-I$DSTROOT/include $SRC/servers/netname.defs' \
47 --replace '$BUILT_PRODUCTS_DIR/mig_hdr' '$BUILT_PRODUCTS_DIR'
50 '' + lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinSdkVersion "11") ''
51 # iig is closed-sourced, we don't have it
52 # create an empty file to the header instead
53 # this line becomes: echo "" > $@; echo --header ...
54 substituteInPlace iokit/DriverKit/Makefile \
55 --replace '--def $<' '> $@; echo'
60 CC = "${stdenv.cc.targetPrefix or ""}cc";
61 CXX = "${stdenv.cc.targetPrefix or ""}c++";
64 STRIP = "${stdenv.cc.bintools.targetPrefix or ""}strip";
65 RANLIB = "${stdenv.cc.bintools.targetPrefix or ""}ranlib";
66 NM = "${stdenv.cc.bintools.targetPrefix or ""}nm";
68 DSYMUTIL = "dsymutil";
69 HOST_OS_VERSION = "10.10";
70 HOST_CC = "${buildPackages.stdenv.cc.targetPrefix or ""}cc";
74 MIGCC = "${lib.getBin pkgsBuildBuild.stdenv.cc.cc}/bin/clang";
78 env.NIX_CFLAGS_COMPILE = "-Wno-error";
80 preBuild = let macosVersion =
81 "10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11" +
82 lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinSdkVersion "11") " 10.12 10.13 10.14 10.15 11.0";
84 # This is a bit of a hack...
85 mkdir -p sdk/usr/local/libexec
87 cat > sdk/usr/local/libexec/availability.pl <<EOF
89 if [ "\$1" == "--macosx" ]; then
91 elif [ "\$1" == "--ios" ]; then
92 echo 2.0 2.1 2.2 3.0 3.1 3.2 4.0 4.1 4.2 4.3 5.0 5.1 6.0 6.1 7.0 8.0 9.0
95 chmod +x sdk/usr/local/libexec/availability.pl
97 export SDKROOT_RESOLVED=$PWD/sdk
98 export HOST_SDKROOT_RESOLVED=$PWD/sdk
100 export BUILT_PRODUCTS_DIR=.
104 buildFlags = lib.optional headersOnly "exporthdrs";
105 installTargets = lib.optional headersOnly "installhdrs";
107 postInstall = lib.optionalString headersOnly ''
108 mv $out/usr/include $out
110 (cd BUILD/obj/EXPORT_HDRS && find -type f -exec install -D \{} $out/include/\{} \;)
112 # TODO: figure out why I need to do this
113 cp libsyscall/wrappers/*.h $out/include
114 install -D libsyscall/os/tsd.h $out/include/os/tsd.h
115 cp EXTERNAL_HEADERS/AssertMacros.h $out/include
116 cp EXTERNAL_HEADERS/Availability*.h $out/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/
117 cp -r EXTERNAL_HEADERS/corecrypto $out/include
119 # These headers are needed by Libsystem.
120 cp libsyscall/wrappers/{spawn/spawn.h,libproc/libproc.h} $out/include
122 # Build the mach headers we crave
123 export SRCROOT=$PWD/libsyscall
124 export DERIVED_SOURCES_DIR=$out/include
127 export BUILT_PRODUCTS_DIR=$out
128 libsyscall/xcodescripts/mach_install_mig.sh
130 # Get rid of the System prefix
131 mv $out/System/* $out/
134 # TODO: do I need this?
135 mv $out/internal_hdr/include/mach/*.h $out/include/mach
137 # Get rid of some junk lying around
138 rm -rf $out/internal_hdr $out/usr $out/local
141 ln -s $out/Library/Frameworks/System.framework/Versions/B \
142 $out/Library/Frameworks/System.framework/Versions/Current
143 ln -s $out/Library/Frameworks/System.framework/Versions/Current/PrivateHeaders \
144 $out/Library/Frameworks/System.framework/Headers
146 # IOKit (and possibly the others) is incomplete,
147 # so let's not make it visible from here...
148 mkdir $out/Library/PrivateFrameworks
149 mv $out/Library/Frameworks/IOKit.framework $out/Library/PrivateFrameworks
152 appleHeaders = builtins.readFile (./. + "/headers-${stdenv.hostPlatform.darwinSdkVersion}-${arch}.txt");
153 } // lib.optionalAttrs headersOnly {
154 HOST_CODESIGN = "echo";
155 HOST_CODESIGN_ALLOCATE = "echo";