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;
22 aliases = self: super: lib.optionalAttrs config.allowAliases (import ../top-level/darwin-aliases.nix lib self super pkgs);
25 makeScopeWithSplicing' {
26 otherSplices = generateSplicesForMkScope "darwin";
27 extra = spliced: spliced.apple_sdk.frameworks;
28 f = lib.extends aliases (self: let
29 inherit (self) mkDerivation callPackage;
31 # Must use pkgs.callPackage to avoid infinite recursion.
33 # Open source packages that are built from source
34 appleSourcePackages = pkgs.callPackage ../os-specific/darwin/apple-source-releases { } self;
36 impure-cmds = pkgs.callPackage ../os-specific/darwin/impure-cmds { };
39 apple_sdk_10_12 = pkgs.callPackage ../os-specific/darwin/apple-sdk {
40 inherit (buildPackages.darwin) print-reexports;
41 inherit (self) darwin-stubs;
42 fetchurl = fetchurlBoot;
46 apple_sdk_11_0 = pkgs.callPackage ../os-specific/darwin/apple-sdk-11.0 {
47 fetchurl = fetchurlBoot;
51 apple_sdk_12_3 = pkgs.callPackage ../os-specific/darwin/apple-sdk-12.3 { };
55 "10.12" = apple_sdk_10_12;
56 "11.0" = apple_sdk_11_0;
57 }.${stdenv.hostPlatform.darwinSdkVersion}
58 or (throw "Unsupported sdk: ${stdenv.hostPlatform.darwinSdkVersion}");
60 # Pick the source of libraries: either Apple's open source releases, or the
62 useAppleSDKLibs = lib.versionAtLeast stdenv.hostPlatform.darwinSdkVersion "11";
64 selectAttrs = attrs: names:
65 lib.listToAttrs (lib.concatMap (n: lib.optionals (attrs ? "${n}") [(lib.nameValuePair n attrs."${n}")]) names);
68 # There are differences in which libraries are exported. Avoid evaluation
69 # errors when a package is not provided.
73 else appleSourcePackages
74 ) ["Libsystem" "LibsystemCross" "libcharset" "libunwind" "objc4" "configd" "IOKit"]
78 then apple_sdk.frameworks
79 else appleSourcePackages
84 impure-cmds // appleSourcePackages // chooseLibs // {
86 inherit apple_sdk apple_sdk_10_12 apple_sdk_11_0 apple_sdk_12_3;
88 stdenvNoCF = stdenv.override {
89 extraBuildInputs = [];
92 binutils-unwrapped = callPackage ../os-specific/darwin/binutils {
93 inherit (pkgs) cctools;
94 inherit (pkgs.llvmPackages) clang-unwrapped llvm llvm-manpages;
97 binutils = pkgs.wrapBintoolsWith {
99 if stdenv.targetPlatform != stdenv.hostPlatform
101 else pkgs.stdenv.cc.libc;
102 bintools = self.binutils-unwrapped;
105 # x86-64 Darwin gnat-bootstrap emits assembly
106 # with MOVQ as the mnemonic for quadword interunit moves
107 # such as `movq %rbp, %xmm0`.
108 # The clang integrated assembler recognises this as valid,
109 # but unfortunately the cctools.gas GNU assembler does not;
110 # it instead uses MOVD as the mnemonic.
111 # The assembly that a GCC build emits is determined at build time
112 # and cannot be changed afterwards.
114 # To build GNAT on x86-64 Darwin, therefore,
115 # we need both the clang _and_ the cctools.gas assemblers to be available:
116 # the former to build at least the stage1 compiler,
117 # and the latter at least to be detectable
118 # as the target for the final compiler.
119 binutilsDualAs-unwrapped = pkgs.buildEnv {
120 name = "${lib.getName self.binutils-unwrapped}-dualas-${lib.getVersion self.binutils-unwrapped}";
122 self.binutils-unwrapped
123 (lib.getOutput "gas" pkgs.cctools)
127 binutilsDualAs = self.binutils.override {
128 bintools = self.binutilsDualAs-unwrapped;
131 binutilsNoLibc = pkgs.wrapBintoolsWith {
132 libc = preLibcCrossHeaders;
133 bintools = self.binutils-unwrapped;
136 # TODO(@connorbaker): See https://github.com/NixOS/nixpkgs/issues/229389.
137 cf-private = self.apple_sdk.frameworks.CoreFoundation;
139 DarwinTools = callPackage ../os-specific/darwin/DarwinTools { };
141 darwin-stubs = callPackage ../os-specific/darwin/darwin-stubs { };
143 print-reexports = callPackage ../os-specific/darwin/print-reexports { };
145 rewrite-tbd = callPackage ../os-specific/darwin/rewrite-tbd { };
147 checkReexportsHook = pkgs.makeSetupHook {
148 name = "darwin-check-reexports-hook";
149 propagatedBuildInputs = [ pkgs.darwin.print-reexports ];
150 } ../os-specific/darwin/print-reexports/setup-hook.sh;
152 sigtool = callPackage ../os-specific/darwin/sigtool { };
154 signingUtils = callPackage ../os-specific/darwin/signing-utils { };
156 postLinkSignHook = callPackage ../os-specific/darwin/signing-utils/post-link-sign-hook.nix { };
158 autoSignDarwinBinariesHook = pkgs.makeSetupHook {
159 name = "auto-sign-darwin-binaries-hook";
160 propagatedBuildInputs = [ self.signingUtils ];
161 } ../os-specific/darwin/signing-utils/auto-sign-hook.sh;
163 iosSdkPkgs = callPackage ../os-specific/darwin/xcode/sdk-pkgs.nix {
164 buildIosSdk = buildPackages.darwin.iosSdkPkgs.sdk;
165 targetIosSdkPkgs = targetPackages.darwin.iosSdkPkgs;
166 inherit (pkgs.llvmPackages) clang-unwrapped;
169 iproute2mac = callPackage ../os-specific/darwin/iproute2mac { };
171 libobjc = self.objc4;
173 lsusb = callPackage ../os-specific/darwin/lsusb { };
175 moltenvk = callPackage ../os-specific/darwin/moltenvk {
176 stdenv = pkgs.overrideSDK stdenv {
177 darwinMinVersion = "10.15";
178 darwinSdkVersion = "12.3";
180 inherit (apple_sdk.frameworks) AppKit Foundation Metal QuartzCore;
181 inherit (apple_sdk.libs) simd;
184 openwith = callPackage ../os-specific/darwin/openwith { };
186 stubs = pkgs.callPackages ../os-specific/darwin/stubs { };
188 trash = callPackage ../os-specific/darwin/trash { };
190 xattr = pkgs.python3Packages.callPackage ../os-specific/darwin/xattr { };
192 inherit (pkgs.callPackages ../os-specific/darwin/xcode { })
194 xcode_9_1 xcode_9_2 xcode_9_3 xcode_9_4 xcode_9_4_1
195 xcode_10_1 xcode_10_2 xcode_10_2_1 xcode_10_3
196 xcode_11 xcode_11_1 xcode_11_2 xcode_11_3_1 xcode_11_4 xcode_11_5 xcode_11_6 xcode_11_7
197 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
198 xcode_13 xcode_13_1 xcode_13_2 xcode_13_3 xcode_13_3_1 xcode_13_4 xcode_13_4_1
200 xcode_15 xcode_15_1 xcode_15_2 xcode_15_3 xcode_15_4
203 CoreSymbolication = callPackage ../os-specific/darwin/CoreSymbolication {
204 inherit (apple_sdk) darwin-stubs;
207 # TODO: Remove the CF hook if a solution to the crashes is not found.
209 # CF used to refer to the open source version of CoreFoundation from the Swift
210 # project. As of macOS 14, the rpath-based approach allowing packages to choose
211 # which version to use no longer seems to work reliably. Sometimes they works,
212 # but sometimes they crash with the error (in the system crash logs):
213 # CF objects must have a non-zero isa.
214 # See https://developer.apple.com/forums/thread/739355 for more on that error.
216 # In this branch, we only have a single "CoreFoundation" to choose from.
217 # To be compatible with the existing convention, we define
218 # CoreFoundation with the setup hook, and CF as the same package but
219 # with the setup hook removed.
221 # This may seem unimportant, but without it packages (e.g., bacula) will
222 # fail with linker errors referring ___CFConstantStringClassReference.
223 # It's not clear to me why some packages need this extra setup.
224 lib.overrideDerivation apple_sdk.frameworks.CoreFoundation (drv: {
228 # Formerly the CF attribute. Use this is you need the open source release.
229 swift-corelibs-foundation = callPackage ../os-specific/darwin/swift-corelibs/corefoundation.nix { };
231 # 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
232 # libdispatch-broken = callPackage ../os-specific/darwin/swift-corelibs/libdispatch.nix { };
234 libtapi = pkgs.libtapi;
236 ios-deploy = callPackage ../os-specific/darwin/ios-deploy {};
238 discrete-scroll = callPackage ../os-specific/darwin/discrete-scroll { };
240 # See doc/packages/darwin-builder.section.md
241 linux-builder = lib.makeOverridable ({ modules }:
243 toGuest = builtins.replaceStrings [ "darwin" ] [ "linux" ];
245 nixos = import ../../nixos {
248 ../../nixos/modules/profiles/macos-builder.nix
251 # If you need to override this, consider starting with the right Nixpkgs
252 # in the first place, ie change `pkgs` in `pkgs.darwin.linux-builder`.
253 # or if you're creating new wiring that's not `pkgs`-centric, perhaps use the
254 # macos-builder profile directly.
255 virtualisation.host = { inherit pkgs; };
257 nixpkgs.hostPlatform = lib.mkDefault (toGuest stdenv.hostPlatform.system);
264 nixos.config.system.build.macos-builder-installer) { modules = [ ]; };
266 linux-builder-x86_64 = self.linux-builder.override {
267 modules = [ { nixpkgs.hostPlatform = "x86_64-linux"; } ];