2 , buildPackages, pkgs, targetPackages
3 , generateSplicesForMkScope, makeScopeWithSplicing'
10 # Prefix for binaries. Customarily ends with a dash separator.
12 # TODO(@Ericson2314) Make unconditional, or optional but always true by
14 targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
15 (stdenv.targetPlatform.config + "-");
17 # Bootstrap `fetchurl` needed to build SDK packages without causing an infinite recursion.
18 fetchurlBoot = import ../build-support/fetchurl/boot.nix {
19 inherit (stdenv) system;
23 makeScopeWithSplicing' {
24 otherSplices = generateSplicesForMkScope "darwin";
25 extra = spliced: spliced.apple_sdk.frameworks;
27 inherit (self) mkDerivation callPackage;
29 # Must use pkgs.callPackage to avoid infinite recursion.
31 # Open source packages that are built from source
32 appleSourcePackages = pkgs.callPackage ../os-specific/darwin/apple-source-releases { } self;
34 impure-cmds = pkgs.callPackage ../os-specific/darwin/impure-cmds { };
37 apple_sdk_10_12 = pkgs.callPackage ../os-specific/darwin/apple-sdk {
38 inherit (buildPackages.darwin) print-reexports;
39 inherit (self) darwin-stubs;
40 fetchurl = fetchurlBoot;
44 apple_sdk_11_0 = pkgs.callPackage ../os-specific/darwin/apple-sdk-11.0 {
45 fetchurl = fetchurlBoot;
49 apple_sdk = if stdenv.hostPlatform.isAarch64 then apple_sdk_11_0 else apple_sdk_10_12;
51 # Pick the source of libraries: either Apple's open source releases, or the
53 useAppleSDKLibs = stdenv.hostPlatform.isAarch64;
55 selectAttrs = attrs: names:
56 lib.listToAttrs (lib.concatMap (n: lib.optionals (attrs ? "${n}") [(lib.nameValuePair n attrs."${n}")]) names);
59 # There are differences in which libraries are exported. Avoid evaluation
60 # errors when a package is not provided.
64 else appleSourcePackages
65 ) ["Libsystem" "LibsystemCross" "libcharset" "libunwind" "objc4" "configd" "IOKit"]
69 then apple_sdk.frameworks
70 else appleSourcePackages
75 impure-cmds // appleSourcePackages // chooseLibs // {
77 inherit apple_sdk apple_sdk_10_12 apple_sdk_11_0;
79 stdenvNoCF = stdenv.override {
80 extraBuildInputs = [];
83 binutils-unwrapped = callPackage ../os-specific/darwin/binutils {
84 inherit (pkgs) binutils-unwrapped;
85 inherit (pkgs.llvmPackages) llvm clang-unwrapped;
88 binutils = pkgs.wrapBintoolsWith {
90 if stdenv.targetPlatform != stdenv.hostPlatform
92 else pkgs.stdenv.cc.libc;
93 bintools = self.binutils-unwrapped;
96 binutilsDualAs-unwrapped = callPackage ../os-specific/darwin/binutils {
97 inherit (pkgs) binutils-unwrapped;
98 inherit (pkgs.llvmPackages) llvm clang-unwrapped;
102 binutilsDualAs = pkgs.wrapBintoolsWith {
104 if stdenv.targetPlatform != stdenv.hostPlatform
106 else pkgs.stdenv.cc.libc;
107 bintools = self.binutilsDualAs-unwrapped;
110 binutilsNoLibc = pkgs.wrapBintoolsWith {
111 libc = preLibcCrossHeaders;
112 bintools = self.binutils-unwrapped;
115 cctools = self.cctools-llvm;
117 cctools-apple = callPackage ../os-specific/darwin/cctools/apple.nix {
118 stdenv = if stdenv.isDarwin then stdenv else pkgs.libcxxStdenv;
121 cctools-llvm = callPackage ../os-specific/darwin/cctools/llvm.nix {
122 stdenv = if stdenv.isDarwin then stdenv else pkgs.libcxxStdenv;
125 cctools-port = callPackage ../os-specific/darwin/cctools/port.nix {
126 stdenv = if stdenv.isDarwin then stdenv else pkgs.libcxxStdenv;
129 # TODO(@connorbaker): See https://github.com/NixOS/nixpkgs/issues/229389.
130 cf-private = self.apple_sdk.frameworks.CoreFoundation;
132 DarwinTools = callPackage ../os-specific/darwin/DarwinTools { };
134 darwin-stubs = callPackage ../os-specific/darwin/darwin-stubs { };
136 print-reexports = callPackage ../os-specific/darwin/print-reexports { };
138 rewrite-tbd = callPackage ../os-specific/darwin/rewrite-tbd { };
140 checkReexportsHook = pkgs.makeSetupHook {
141 name = "darwin-check-reexports-hook";
142 propagatedBuildInputs = [ pkgs.darwin.print-reexports ];
143 } ../os-specific/darwin/print-reexports/setup-hook.sh;
145 sigtool = callPackage ../os-specific/darwin/sigtool { };
147 signingUtils = callPackage ../os-specific/darwin/signing-utils { };
149 postLinkSignHook = callPackage ../os-specific/darwin/signing-utils/post-link-sign-hook.nix { };
151 autoSignDarwinBinariesHook = pkgs.makeSetupHook {
152 name = "auto-sign-darwin-binaries-hook";
153 propagatedBuildInputs = [ self.signingUtils ];
154 } ../os-specific/darwin/signing-utils/auto-sign-hook.sh;
156 maloader = callPackage ../os-specific/darwin/maloader {
159 insert_dylib = callPackage ../os-specific/darwin/insert_dylib { };
161 iosSdkPkgs = callPackage ../os-specific/darwin/xcode/sdk-pkgs.nix {
162 buildIosSdk = buildPackages.darwin.iosSdkPkgs.sdk;
163 targetIosSdkPkgs = targetPackages.darwin.iosSdkPkgs;
164 inherit (pkgs.llvmPackages) clang-unwrapped;
167 iproute2mac = callPackage ../os-specific/darwin/iproute2mac { };
169 libobjc = self.objc4;
171 lsusb = callPackage ../os-specific/darwin/lsusb { };
173 moltenvk = pkgs.darwin.apple_sdk_11_0.callPackage ../os-specific/darwin/moltenvk {
174 inherit (apple_sdk_11_0.frameworks) AppKit Foundation Metal QuartzCore;
175 inherit (apple_sdk_11_0) MacOSX-SDK Libsystem;
176 inherit (pkgs.darwin) cctools sigtool;
179 opencflite = callPackage ../os-specific/darwin/opencflite { };
181 openwith = pkgs.darwin.apple_sdk_11_0.callPackage ../os-specific/darwin/openwith {
182 inherit (apple_sdk_11_0.frameworks) AppKit Foundation UniformTypeIdentifiers;
185 stubs = pkgs.callPackages ../os-specific/darwin/stubs { };
187 trash = callPackage ../os-specific/darwin/trash { };
189 xattr = pkgs.python3Packages.callPackage ../os-specific/darwin/xattr { };
191 inherit (pkgs.callPackages ../os-specific/darwin/xcode { })
193 xcode_9_1 xcode_9_2 xcode_9_3 xcode_9_4 xcode_9_4_1
194 xcode_10_1 xcode_10_2 xcode_10_2_1 xcode_10_3
195 xcode_11 xcode_11_1 xcode_11_2 xcode_11_3_1 xcode_11_4 xcode_11_5 xcode_11_6 xcode_11_7
196 xcode_12 xcode_12_0_1 xcode_12_1 xcode_12_2 xcode_12_3 xcode_12_4 xcode_12_5 xcode_12_5_1
197 xcode_13 xcode_13_1 xcode_13_2 xcode_13_3 xcode_13_3_1 xcode_13_4 xcode_13_4_1
201 CoreSymbolication = callPackage ../os-specific/darwin/CoreSymbolication { };
203 # TODO: Remove the CF hook if a solution to the crashes is not found.
205 # CF used to refer to the open source version of CoreFoundation from the Swift
206 # project. As of macOS 14, the rpath-based approach allowing packages to choose
207 # which version to use no longer seems to work reliably. Sometimes they works,
208 # but sometimes they crash with the error (in the system crash logs):
209 # CF objects must have a non-zero isa.
210 # See https://developer.apple.com/forums/thread/739355 for more on that error.
212 # In this branch, we only have a single "CoreFoundation" to choose from.
213 # To be compatible with the existing convention, we define
214 # CoreFoundation with the setup hook, and CF as the same package but
215 # with the setup hook removed.
217 # This may seem unimportant, but without it packages (e.g., bacula) will
218 # fail with linker errors referring ___CFConstantStringClassReference.
219 # It's not clear to me why some packages need this extra setup.
220 lib.overrideDerivation apple_sdk.frameworks.CoreFoundation (drv: {
224 # Formerly the CF attribute. Use this is you need the open source release.
225 swift-corelibs-foundation = callPackage ../os-specific/darwin/swift-corelibs/corefoundation.nix { };
227 # As the name says, this is broken, but I don't want to lose it since it's a direction we want to go in
228 # libdispatch-broken = callPackage ../os-specific/darwin/swift-corelibs/libdispatch.nix { };
230 libtapi = callPackage ../os-specific/darwin/libtapi {};
232 ios-deploy = callPackage ../os-specific/darwin/ios-deploy {};
234 discrete-scroll = callPackage ../os-specific/darwin/discrete-scroll { };
236 # See doc/builders/special/darwin-builder.section.md
237 linux-builder = lib.makeOverridable ({ modules }:
239 toGuest = builtins.replaceStrings [ "darwin" ] [ "linux" ];
241 nixos = import ../../nixos {
244 ../../nixos/modules/profiles/macos-builder.nix
247 # If you need to override this, consider starting with the right Nixpkgs
248 # in the first place, ie change `pkgs` in `pkgs.darwin.linux-builder`.
249 # or if you're creating new wiring that's not `pkgs`-centric, perhaps use the
250 # macos-builder profile directly.
251 virtualisation.host = { inherit pkgs; };
253 nixpkgs.hostPlatform = lib.mkDefault (toGuest stdenv.hostPlatform.system);
260 nixos.config.system.build.macos-builder-installer) { modules = [ ]; };
262 linux-builder-x86_64 = self.linux-builder.override {
263 modules = [ { nixpkgs.hostPlatform = "x86_64-linux"; } ];
266 } // lib.optionalAttrs config.allowAliases {
267 builder = throw "'darwin.builder' has been changed and renamed to 'darwin.linux-builder'. The default ssh port is now 31022. Please update your configuration or override the port back to 22. See https://nixos.org/manual/nixpkgs/unstable/#sec-darwin-builder"; # added 2023-07-06