1 { lib, stdenvNoCC, buildPackages, fetchurl, xar, cpio, pkgs, python3, pbzx, MacOSX-SDK }:
3 # TODO: reorganize to make this just frameworks, and move libs to default.nix
8 standardFrameworkPath = name: private:
9 "/System/Library/${lib.optionalString private "Private"}Frameworks/${name}.framework";
11 mkDepsRewrites = deps:
13 mergeRewrites = x: y: {
14 prefix = lib.mergeAttrs (x.prefix or {}) (y.prefix or {});
15 const = lib.mergeAttrs (x.const or {}) (y.const or {});
18 rewriteArgs = { prefix ? {}, const ? {} }: lib.concatLists (
19 (lib.mapAttrsToList (from: to: [ "-p" "${from}:${to}" ]) prefix) ++
20 (lib.mapAttrsToList (from: to: [ "-c" "${from}:${to}" ]) const)
23 rewrites = depList: lib.fold mergeRewrites {}
24 (map (dep: dep.tbdRewrites)
25 (lib.filter (dep: dep ? tbdRewrites) depList));
27 lib.escapeShellArgs (rewriteArgs (rewrites (builtins.attrValues deps)));
29 mkFramework = { name, deps, private ? false }:
30 let self = stdenv.mkDerivation {
31 pname = "apple-${lib.optionalString private "private-"}framework-${name}";
32 version = MacOSX-SDK.version;
36 # because we copy files from the system
37 preferLocalBuild = true;
39 disallowedRequisites = [ MacOSX-SDK ];
41 nativeBuildInputs = [ buildPackages.darwin.rewrite-tbd ];
44 mkdir -p $out/Library/Frameworks
46 cp -r ${MacOSX-SDK}${standardFrameworkPath name private} $out/Library/Frameworks
48 if [[ -d ${MacOSX-SDK}/usr/lib/swift/${name}.swiftmodule ]]; then
49 mkdir -p $out/lib/swift
50 cp -r -t $out/lib/swift \
51 ${MacOSX-SDK}/usr/lib/swift/${name}.swiftmodule \
52 ${MacOSX-SDK}/usr/lib/swift/libswift${name}.tbd
55 # Fix and check tbd re-export references
57 find $out -name '*.tbd' -type f | while read tbd; do
58 echo "Fixing re-exports in $tbd"
60 -p ${standardFrameworkPath name private}/:$out/Library/Frameworks/${name}.framework/ \
61 -p /usr/lib/swift/:$out/lib/swift/ \
62 ${mkDepsRewrites deps} \
63 -r ${builtins.storeDir} \
68 propagatedBuildInputs = builtins.attrValues deps;
72 prefix."${standardFrameworkPath name private}/" = "${self}/Library/Frameworks/${name}.framework/";
77 description = "Apple SDK framework ${name}";
78 maintainers = with maintainers; [ copumpkin ];
79 platforms = platforms.darwin;
84 framework = name: deps: mkFramework { inherit name deps; private = false; };
85 privateFramework = name: deps: mkFramework { inherit name deps; private = true; };
88 xpc = stdenv.mkDerivation {
89 name = "apple-lib-xpc";
94 pushd $out/include >/dev/null
95 cp -r "${MacOSX-SDK}/usr/include/xpc" $out/include/xpc
96 cp "${MacOSX-SDK}/usr/include/launch.h" $out/include/launch.h
101 Xplugin = stdenv.mkDerivation {
102 name = "apple-lib-Xplugin";
105 propagatedBuildInputs = with frameworks; [
106 OpenGL ApplicationServices Carbon IOKit CoreGraphics CoreServices CoreText
110 mkdir -p $out/include $out/lib
111 ln -s "${MacOSX-SDK}/include/Xplugin.h" $out/include/Xplugin.h
112 cp ${MacOSX-SDK}/usr/lib/libXplugin.1.tbd $out/lib
113 ln -s libXplugin.1.tbd $out/lib/libXplugin.tbd
117 utmp = stdenv.mkDerivation {
118 name = "apple-lib-utmp";
122 mkdir -p $out/include
123 pushd $out/include >/dev/null
124 ln -s "${MacOSX-SDK}/include/utmp.h"
125 ln -s "${MacOSX-SDK}/include/utmpx.h"
130 sandbox = stdenv.mkDerivation {
131 name = "apple-lib-sandbox";
137 mkdir -p $out/include $out/lib
138 ln -s "${MacOSX-SDK}/usr/include/sandbox.h" $out/include/sandbox.h
139 cp "${MacOSX-SDK}/usr/lib/libsandbox.1.tbd" $out/lib
140 ln -s libsandbox.1.tbd $out/lib/libsandbox.tbd
144 libDER = stdenv.mkDerivation {
145 name = "apple-lib-libDER";
148 mkdir -p $out/include
149 cp -r ${MacOSX-SDK}/usr/include/libDER $out/include
153 simd = stdenv.mkDerivation {
154 name = "apple-lib-simd";
157 mkdir -p $out/include
158 cp -r ${MacOSX-SDK}/usr/include/simd $out/include
164 # Dependency map created by gen-frameworks.py.
165 generatedDeps = import ./frameworks.nix {
166 inherit frameworks libs;
169 # Additional dependencies that are not picked up by gen-frameworks.py.
170 # Some of these are simply private frameworks the generator does not see.
171 extraDeps = with libs; with frameworks; let
172 inherit (pkgs.darwin.apple_sdk_11_0) libnetwork;
173 libobjc = pkgs.darwin.apple_sdk_11_0.objc4;
175 # Below this comment are entries migrated from before the generator was
176 # added. If, for a given framework, you are able to reverify the extra
177 # deps are really necessary on top of the generator deps, move it above
178 # this comment (and maybe document your findings).
179 AVFoundation = { inherit ApplicationServices AVFCapture AVFCore; };
180 Accelerate = { inherit CoreWLAN IOBluetooth; };
181 AddressBook = { inherit AddressBookCore ContactsPersistence libobjc; };
182 AppKit = { inherit AudioToolbox AudioUnit UIFoundation; };
183 AudioToolbox = { inherit AudioToolboxCore; };
184 AudioUnit = { inherit Carbon CoreAudio; };
185 Carbon = { inherit IOKit QuartzCore libobjc; };
186 CoreAudio = { inherit IOKit; };
187 CoreFoundation = { inherit libobjc; };
188 CoreGraphics = { inherit SystemConfiguration; };
189 CoreMIDIServer = { inherit CoreMIDI; };
190 CoreMedia = { inherit ApplicationServices AudioToolbox AudioUnit; };
191 CoreServices = { inherit CoreAudio NetFS ServiceManagement; };
192 CoreWLAN = { inherit SecurityFoundation; };
193 DiscRecording = { inherit IOKit libobjc; };
194 Foundation = { inherit SystemConfiguration libobjc; };
195 GameKit = { inherit GameCenterFoundation GameCenterUI GameCenterUICore ReplayKit; };
196 ICADevices = { inherit Carbon libobjc; };
197 IOBluetooth = { inherit CoreBluetooth; };
198 JavaScriptCore = { inherit libobjc; };
199 Kernel = { inherit IOKit; };
200 LinkPresentation = { inherit URLFormatting; };
201 MediaToolbox = { inherit AudioUnit; };
202 MetricKit = { inherit SignpostMetrics; };
203 Network = { inherit libnetwork; };
204 PCSC = { inherit CoreData; };
205 PassKit = { inherit PassKitCore; };
206 QTKit = { inherit CoreMedia CoreMediaIO MediaToolbox VideoToolbox; };
207 Quartz = { inherit QTKit; };
208 QuartzCore = { inherit ApplicationServices CoreImage CoreVideo Metal OpenCL libobjc; };
209 Security = { inherit IOKit libDER; };
210 TWAIN = { inherit Carbon; };
211 VideoDecodeAcceleration = { inherit CoreVideo; };
212 WebKit = { inherit ApplicationServices Carbon libobjc; };
215 # Overrides for framework derivations.
217 CoreFoundation = lib.overrideDerivation super.CoreFoundation (drv: {
218 setupHook = ./cf-setup-hook.sh;
221 # This framework doesn't exist in newer SDKs (somewhere around 10.13), but
222 # there are references to it in nixpkgs.
223 QuickTime = throw "QuickTime framework not available";
225 # Seems to be appropriate given https://developer.apple.com/forums/thread/666686
226 JavaVM = super.JavaNativeFoundation;
228 CoreVideo = lib.overrideDerivation super.CoreVideo (drv: {
229 installPhase = drv.installPhase + ''
230 # When used as a module, complains about a missing import for
231 # Darwin.C.stdint. Apparently fixed in later SDKs.
232 sed -e "/CFBase.h/ i #include <stdint.h>" \
233 -i $out/Library/Frameworks/CoreVideo.framework/Headers/CVBase.h
237 System = lib.overrideDerivation super.System (drv: {
238 installPhase = drv.installPhase + ''
239 # Contrarily to the other frameworks, System framework's TBD file
240 # is a symlink pointing to ${MacOSX-SDK}/usr/lib/libSystem.B.tbd.
241 # This produces an error when installing the framework as:
242 # 1. The original file is not copied into the output directory
243 # 2. Even if it was copied, the relative path wouldn't match
244 # Thus, it is easier to replace the file than to fix the symlink.
245 cp --remove-destination ${MacOSX-SDK}/usr/lib/libSystem.B.tbd \
246 $out/Library/Frameworks/System.framework/Versions/B/System.tbd
251 # Merge extraDeps into generatedDeps.
252 deps = generatedDeps // (
254 (name: deps: generatedDeps.${name} // deps)
258 # Create derivations, and add private frameworks.
259 bareFrameworks = (lib.mapAttrs framework deps) // (
260 lib.mapAttrs privateFramework (import ./private-frameworks.nix {
262 libobjc = pkgs.darwin.apple_sdk_11_0.objc4;
266 # Apply derivation overrides.
267 bareFrameworks // overrides bareFrameworks;