1 { stdenv, stdenvNoCC, fetchurl, cpio, pbzx, pkgs, lib, darwin-stubs, print-reexports }:
4 # sadly needs to be exported because security_tool needs it
5 sdk = stdenv.mkDerivation rec {
9 # This URL comes from https://swscan.apple.com/content/catalogs/others/index-10.12.merged-1.sucatalog, which we found by:
10 # 1. Google: site:swscan.apple.com and look for a name that seems appropriate for your version
11 # 2. In the resulting file, search for a file called DevSDK ending in .pkg
15 url = "http://swcdn.apple.com/content/downloads/33/36/041-90419-A_7JJ4H9ZHO2/xs88ob5wjz6riz7g6764twblnvksusg4ps/DevSDK_OSX1012.pkg";
16 sha256 = "13xq34sb7383b37hwy076gnhf96prpk1b4087p87xnwswxbrisih";
19 nativeBuildInputs = [ cpio pbzx ];
21 outputs = [ "out" "dev" "man" ];
32 cp -R System/Library $out
36 cp ${darwin-stubs}/usr/lib/libcups*.tbd .
37 ln -s libcups.2.tbd libcups.tbd
38 ln -s libcupscgi.1.tbd libcupscgi.tbd
39 ln -s libcupsimage.2.tbd libcupsimage.tbd
40 ln -s libcupsmime.1.tbd libcupsmime.tbd
41 ln -s libcupsppdc.1.tbd libcupsppdc.tbd
46 description = "Apple SDK ${version}";
47 maintainers = with maintainers; [ copumpkin ];
48 platforms = platforms.darwin;
52 mkFrameworkSubs = name: deps:
54 deps' = deps // { "${name}" = placeholder "out"; };
55 substArgs = lib.concatMap (x: [ "--subst-var-by" x deps'."${x}" ]) (lib.attrNames deps');
56 in lib.escapeShellArgs substArgs;
58 framework = name: deps: stdenv.mkDerivation {
59 name = "apple-framework-${name}";
63 # because we copy files from the system
64 preferLocalBuild = true;
66 disallowedRequisites = [ sdk ];
68 nativeBuildInputs = [ print-reexports ];
75 local nested_path="$1"
76 if [ "$path" == "JavaNativeFoundation.framework" ]; then
77 local nested_path="JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework"
79 if [ "$path" == "JavaRuntimeSupport.framework" ]; then
80 local nested_path="JavaVM.framework/Versions/A/Frameworks/JavaRuntimeSupport.framework"
82 local name="$(basename "$path" .framework)"
83 local current="$(readlink "/System/Library/Frameworks/$nested_path/Versions/Current")"
84 if [ -z "$current" ]; then
88 local dest="$out/Library/Frameworks/$path"
90 mkdir -p "$dest/Versions/$current"
91 pushd "$dest/Versions/$current" >/dev/null
93 if [ -d "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" ]; then
94 cp -R "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" .
95 elif [ -d "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" ]; then
96 current="$(readlink "/System/Library/Frameworks/$name.framework/Versions/Current")"
97 cp -R "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" .
100 local tbd_source=${darwin-stubs}/System/Library/Frameworks/$nested_path/Versions/$current
101 if [ "${name}" != "Kernel" ]; then
102 # The Kernel.framework has headers but no actual library component.
103 cp -v $tbd_source/*.tbd .
106 if [ -d "$tbd_source/Libraries" ]; then
108 cp -v $tbd_source/Libraries/*.tbd Libraries/
111 ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/Resources"
113 if [ -f "/System/Library/Frameworks/$nested_path/module.map" ]; then
114 ln -s "/System/Library/Frameworks/$nested_path/module.map"
117 pushd "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current" >/dev/null
118 local children=$(echo Frameworks/*.framework)
121 for child in $children; do
122 childpath="$path/Versions/$current/$child"
123 linkFramework "$childpath"
126 pushd ../.. >/dev/null
127 ln -s "$current" Versions/Current
128 ln -s Versions/Current/* .
134 linkFramework "${name}.framework"
136 # linkFramework is recursive, the rest of the processing is not.
138 local tbd_source=${darwin-stubs}/System/Library/Frameworks/${name}.framework
139 for tbd in $extraTBDFiles; do
140 local tbd_dest_dir=$out/Library/Frameworks/${name}.framework/$(dirname "$tbd")
141 mkdir -p "$tbd_dest_dir"
142 cp -v "$tbd_source/$tbd" "$tbd_dest_dir"
145 # Fix and check tbd re-export references
146 find $out -name '*.tbd' | while read tbd; do
147 echo "Fixing re-exports in $tbd"
148 substituteInPlace "$tbd" ${mkFrameworkSubs name deps}
150 echo "Checking re-exports in $tbd"
151 print-reexports "$tbd" | while read target; do
152 local expected="''${target%.dylib}.tbd"
153 if ! [ -e "$expected" ]; then
154 echo -e "Re-export missing:\n\t$target\n\t(expected $expected)"
155 echo -e "While processing\n\t$tbd"
158 echo "Re-exported target $target ok"
164 propagatedBuildInputs = builtins.attrValues deps;
167 description = "Apple SDK framework ${name}";
168 maintainers = with maintainers; [ copumpkin ];
169 platforms = platforms.darwin;
173 tbdOnlyFramework = name: { private ? true }: stdenv.mkDerivation {
174 name = "apple-framework-${name}";
177 mkdir -p $out/Library/Frameworks/
178 cp -r ${darwin-stubs}/System/Library/${lib.optionalString private "Private"}Frameworks/${name}.framework \
179 $out/Library/Frameworks
181 cd $out/Library/Frameworks/${name}.framework
183 versions=(./Versions/*)
184 if [ "''${#versions[@]}" != 1 ]; then
185 echo "Unable to determine current version of framework ${name}"
188 current=$(basename ''${versions[0]})
191 ln -s "$current" Versions/Current
192 ln -s Versions/Current/* .
194 # NOTE there's no re-export checking here, this is probably wrong
199 xpc = stdenv.mkDerivation {
200 name = "apple-lib-xpc";
204 mkdir -p $out/include
205 pushd $out/include >/dev/null
206 cp -r "${lib.getDev sdk}/include/xpc" $out/include/xpc
207 cp "${lib.getDev sdk}/include/launch.h" $out/include/launch.h
212 Xplugin = stdenv.mkDerivation {
213 name = "apple-lib-Xplugin";
217 __propagatedImpureHostDeps = [ "/usr/lib/libXplugin.1.dylib" ];
219 propagatedBuildInputs = with frameworks; [
220 OpenGL ApplicationServices Carbon IOKit CoreGraphics CoreServices CoreText
224 mkdir -p $out/include $out/lib
225 ln -s "${lib.getDev sdk}/include/Xplugin.h" $out/include/Xplugin.h
226 cp ${darwin-stubs}/usr/lib/libXplugin.1.tbd $out/lib
227 ln -s libXplugin.1.tbd $out/lib/libXplugin.tbd
231 utmp = stdenv.mkDerivation {
232 name = "apple-lib-utmp";
236 mkdir -p $out/include
237 pushd $out/include >/dev/null
238 ln -s "${lib.getDev sdk}/include/utmp.h"
239 ln -s "${lib.getDev sdk}/include/utmpx.h"
244 sandbox = stdenv.mkDerivation {
245 name = "apple-lib-sandbox";
249 mkdir -p $out/include $out/lib
250 ln -s "${lib.getDev sdk}/include/sandbox.h" $out/include/sandbox.h
251 cp "${darwin-stubs}/usr/lib/libsandbox.1.tbd" $out/lib
252 ln -s libsandbox.1.tbd $out/lib/libsandbox.tbd
256 simd = stdenvNoCC.mkDerivation {
257 name = "apple-lib-simd";
259 preferLocalBuild = true;
260 allowSubstitutes = false;
262 buildCommand = "echo 'simd library not available in the 10.12 SDK'; exit 1";
267 AppKit = lib.overrideDerivation super.AppKit (drv: {
268 __propagatedImpureHostDeps = drv.__propagatedImpureHostDeps or [] ++ [
269 "/System/Library/PrivateFrameworks/"
273 Carbon = lib.overrideDerivation super.Carbon (drv: {
274 extraTBDFiles = [ "Versions/A/Frameworks/HTMLRendering.framework/Versions/A/HTMLRendering.tbd" ];
277 CoreFoundation = lib.overrideDerivation super.CoreFoundation (drv: {
278 setupHook = ./cf-setup-hook.sh;
281 CoreMedia = lib.overrideDerivation super.CoreMedia (drv: {
282 __propagatedImpureHostDeps = drv.__propagatedImpureHostDeps or [] ++ [
283 "/System/Library/Frameworks/CoreImage.framework"
287 CoreMIDI = lib.overrideDerivation super.CoreMIDI (drv: {
288 __propagatedImpureHostDeps = drv.__propagatedImpureHostDeps or [] ++ [
289 "/System/Library/PrivateFrameworks/"
291 setupHook = ./private-frameworks-setup-hook.sh;
294 IMServicePlugIn = lib.overrideDerivation super.IMServicePlugIn (drv: {
295 extraTBDFiles = [ "Versions/A/Frameworks/IMServicePlugInSupport.framework/Versions/A/IMServicePlugInSupport.tbd" ];
298 Security = lib.overrideDerivation super.Security (drv: {
299 setupHook = ./security-setup-hook.sh;
302 QuartzCore = lib.overrideDerivation super.QuartzCore (drv: {
303 installPhase = drv.installPhase + ''
304 f="$out/Library/Frameworks/QuartzCore.framework/Headers/CoreImage.h"
305 substituteInPlace "$f" \
306 --replace "QuartzCore/../Frameworks/CoreImage.framework/Headers" "CoreImage"
310 MetalKit = lib.overrideDerivation super.MetalKit (drv: {
311 installPhase = drv.installPhase + ''
312 mkdir -p $out/include/simd
313 cp ${lib.getDev sdk}/include/simd/*.h $out/include/simd/
317 System = lib.overrideDerivation super.System (drv: {
319 mkdir -p $out/Library/Frameworks/System.framework/Versions/B
320 ln -s $out/Library/Frameworks/System.framework/Versions/{B,Current}
321 ln -s ${pkgs.darwin.Libsystem}/lib/libSystem.B.tbd $out/Library/Frameworks/System.framework/Versions/B/System.tbd
322 ln -s $out/Library/Frameworks/System.framework/{Versions/Current/,}System.tbd
326 WebKit = lib.overrideDerivation super.WebKit (drv: {
328 "Versions/A/Frameworks/WebCore.framework/Versions/A/WebCore.tbd"
329 "Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy.tbd"
333 "ContactsPersistence"
342 (x: tbdOnlyFramework x {});
344 bareFrameworks = lib.mapAttrs framework (import ./frameworks.nix {
345 inherit frameworks libs;
346 inherit (pkgs.darwin) libobjc;
349 frameworks = bareFrameworks // overrides bareFrameworks;
351 inherit darwin-stubs;
353 objc4 = pkgs.darwin.libobjc;
355 sdkRoot = pkgs.callPackage ./sdkRoot.nix { sdkVersion = "10.12.4"; };
357 inherit (pkgs.darwin) Libsystem;