1 # This file contains the standard build environment for Darwin. It is based on LLVM and is patterned
2 # after the Linux stdenv. It shares similar goals to the Linux standard environment in that the
3 # resulting environment should be built purely and not contain any references to it.
5 # For more on the design of the stdenv and updating it, see `README.md`.
7 # See also the top comments of the Linux stdenv `../linux/default.nix` for a good overview of
8 # the bootstrap process and working with it.
17 # Allow passing in bootstrap files directly so we can test the stdenv bootstrap process when changing the bootstrap tools
18 bootstrapFiles ? (config.replaceBootstrapFiles or lib.id) (
19 if localSystem.isAarch64 then
20 import ./bootstrap-files/aarch64-apple-darwin.nix
22 import ./bootstrap-files/x86_64-apple-darwin.nix
26 assert crossSystem == localSystem;
29 inherit (localSystem) system;
33 inherit (localSystem) darwinSdkVersion;
35 if lib.versionOlder darwinSdkVersion "11" then
36 lib.versions.majorMinor darwinSdkVersion
38 lib.versions.major darwinSdkVersion;
40 commonImpureHostDeps = [
42 "/usr/lib/libSystem.B.dylib"
43 "/usr/lib/system/libunc.dylib" # This dependency is "hidden", so our scanning code doesn't pick it up
46 isFromNixpkgs = pkg: !(isFromBootstrapFiles pkg);
47 isFromBootstrapFiles = pkg: pkg.passthru.isFromBootstrapFiles or false;
48 isBuiltByNixpkgsCompiler = pkg: isFromNixpkgs pkg && isFromNixpkgs pkg.stdenv.cc.cc;
49 isBuiltByBootstrapFilesCompiler = pkg: isFromNixpkgs pkg && isFromBootstrapFiles pkg.stdenv.cc.cc;
51 # Dependencies in dependency sets should be mutually exclusive.
52 mergeDisjointAttrs = lib.foldl' lib.attrsets.unionOfDisjoint { };
55 export NIX_ENFORCE_NO_NATIVE=''${NIX_ENFORCE_NO_NATIVE-1}
56 export NIX_ENFORCE_PURITY=''${NIX_ENFORCE_PURITY-1}
57 export NIX_IGNORE_LD_THROUGH_GCC=1
65 name = "bootstrap-tools";
66 builder = "${bootstrapFiles.unpack}/bin/bash";
69 "${bootstrapFiles.unpack}/bootstrap-tools-unpack.sh"
70 bootstrapFiles.bootstrapTools
73 PATH = lib.makeBinPath [
78 __impureHostDeps = commonImpureHostDeps;
80 // lib.optionalAttrs config.contentAddressedByDefault {
81 __contentAddressed = true;
82 outputHashAlgo = "sha256";
83 outputHashMode = "recursive";
87 passthru.isFromBootstrapFiles = true;
94 overrides ? (self: super: { }),
95 extraNativeBuildInputs ? [ ],
101 if prevStage.llvmPackages.clang-unwrapped == null then
104 prevStage.wrapCCWith {
105 name = "${name}-clang-wrapper";
110 expand-response-params = lib.optionalString (
111 prevStage.stdenv.hasCC or false && prevStage.stdenv.cc != "/dev/null"
112 ) prevStage.expand-response-params;
114 extraPackages = [ prevStage.llvmPackages.compiler-rt ];
118 inherit (prevStage.llvmPackages) clang-unwrapped compiler-rt;
121 function clangResourceRootIncludePath() {
122 clangLib="$1/lib/clang"
123 if (( $(ls "$clangLib" | wc -l) > 1 )); then
124 echo "Multiple LLVM versions were found at "$clangLib", but there must only be one used when building the stdenv." >&2
127 echo "$clangLib/$(ls -1 "$clangLib")/include"
130 rsrc="$out/resource-root"
132 ln -s "$(clangResourceRootIncludePath "${lib.getLib clang-unwrapped}")" "$rsrc"
133 ln -s "${compiler-rt.out}/lib" "$rsrc/lib"
134 ln -s "${compiler-rt.out}/share" "$rsrc/share"
135 echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
137 + lib.optionalString (isFromBootstrapFiles prevStage.llvmPackages.clang-unwrapped) ''
138 # Work around the `-nostdlibinc` patch in the bootstrap tools.
139 # TODO: Remove after the bootstrap tools have been updated.
140 substituteAll ${builtins.toFile "add-flags-extra.sh" ''
141 if [ "@darwinMinVersion@" ]; then
142 NIX_CFLAGS_COMPILE_@suffixSalt@+=" -idirafter $SDKROOT/usr/include"
143 NIX_CFLAGS_COMPILE_@suffixSalt@+=" -iframework $SDKROOT/System/Library/Frameworks"
145 ''} add-flags-extra.sh
146 cat add-flags-extra.sh >> $out/nix-support/add-flags.sh
149 cc = prevStage.llvmPackages.clang-unwrapped;
150 bintools = prevStage.darwin.binutils;
153 libc = prevStage.darwin.libSystem;
154 inherit (prevStage.llvmPackages) libcxx;
157 inherit (prevStage) coreutils gnugrep;
159 stdenvNoCC = prevStage.ccWrapperStdenv;
160 runtimeShell = prevStage.ccWrapperStdenv.shell;
163 bash = prevStage.bash or bootstrapTools;
165 thisStdenv = import ../generic {
166 name = "${name}-stdenv-darwin";
168 buildPlatform = localSystem;
169 hostPlatform = localSystem;
170 targetPlatform = localSystem;
174 extraBuildInputs = [ prevStage.apple-sdk ];
175 inherit extraNativeBuildInputs;
178 lib.optionalString (!isBuiltByNixpkgsCompiler bash) ''
179 # Don't patch #!/interpreter because it leads to retained
180 # dependencies on the bootstrapTools in the final stdenv.
187 + lib.optionalString (prevStage.darwin ? locale) ''
188 export PATH_LOCALE=${prevStage.darwin.locale}/share/locale
191 shell = bash + "/bin/bash";
198 fetchurlBoot = import ../../build-support/fetchurl {
200 stdenvNoCC = prevStage.ccWrapperStdenv or thisStdenv;
201 curl = bootstrapTools;
206 # The stdenvs themselves don't use mkDerivation, so I need to specify this here
207 __stdenvImpureHostDeps = commonImpureHostDeps;
208 __extraImpureHostDeps = commonImpureHostDeps;
210 # Using the bootstrap tools curl for fetchers allows the stdenv bootstrap to avoid
211 # having a dependency on curl, allowing curl to be updated without triggering a
212 # new stdenv bootstrap on Darwin.
215 (overrides self super)
217 fetchurl = thisStdenv.fetchurlBoot;
218 fetchpatch = super.fetchpatch.override { inherit (self) fetchurl; };
219 fetchzip = super.fetchzip.override { inherit (self) fetchurl; };
225 inherit config overlays;
229 # Dependencies - these are packages that are rebuilt together in groups. Defining them here ensures they are
230 # asserted and overlayed together. It also removes a lot of clutter from the stage definitions.
232 # When multiple dependency sets share a dependency, it should be put in the one that will be (re)built first.
233 # That makes sure everything else will share the same dependency in the final stdenv.
238 sets' = mergeDisjointAttrs sets;
239 result = lib.all checkFn (lib.attrValues sets');
240 resultDetails = lib.mapAttrs (_: checkFn) sets';
242 lib.traceIf (!result) (lib.deepSeq resultDetails resultDetails) result;
244 # These packages are built in stage 1 then never built again. They must not be included in the final overlay
245 # or as dependencies to packages that are in the final overlay. They are mostly tools used as native build inputs.
246 # Any libraries in the list must only be used as dependencies of packages in this list.
247 stage1Packages = prevStage: {
288 # These packages include both the core bintools (other than LLVM) packages as well as their dependencies.
289 bintoolsPackages = prevStage: {
305 darwinPackages = prevStage: { inherit (prevStage.darwin) sigtool; };
306 darwinPackagesNoCC = prevStage: {
307 inherit (prevStage.darwin)
315 # These packages are not allowed to be used in the Darwin bootstrap
316 disallowedPackages = prevStage: { inherit (prevStage) binutils-unwrapped curl; };
318 # LLVM tools packages are staged separately (xclang, stage3) from LLVM libs (xclang).
319 llvmLibrariesPackages = prevStage: { inherit (prevStage.llvmPackages) compiler-rt libcxx; };
320 llvmLibrariesDeps = _: { };
322 llvmToolsPackages = prevStage: {
323 inherit (prevStage.llvmPackages)
332 llvmToolsDeps = prevStage: { inherit (prevStage) libffi; };
334 # SDK packages include propagated packages and source release packages built during the bootstrap.
335 sdkPackages = prevStage: {
348 sdkDarwinPackages = prevStage: {
349 inherit (prevStage.darwin)
360 sdkPackagesNoCC = prevStage: { inherit (prevStage) apple-sdk; };
363 assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check
386 binutils-unwrapped = null;
392 clang-unwrapped = null;
400 # Create a stage with the bootstrap tools. This will be used to build the subsequent stages and
401 # build up the standard environment.
403 # Note: Each stage depends only on the the packages in `prevStage`. If a package is not to be
404 # rebuilt, it should be passed through by inheriting it.
408 name = "bootstrap-stage0";
410 overrides = self: super: {
411 # We thread stage0's stdenv through under this name so downstream stages
412 # can use it for wrapping gcc too. This way, downstream stages don't need
413 # to refer to this stage directly, which violates the principle that each
414 # stage should only access the stage that came before it.
415 ccWrapperStdenv = self.stdenv;
417 bash = bootstrapTools // {
418 shellPath = "/bin/bash";
421 coreutils = bootstrapTools;
422 cpio = bootstrapTools;
424 gnugrep = bootstrapTools;
425 pbzx = bootstrapTools;
429 cctools = bootstrapTools // {
430 libtool = bootstrapTools;
435 ld64 = bootstrapTools // {
440 darwin = super.darwin.overrideScope (
441 selfDarwin: superDarwin: {
442 binutils = super.wrapBintoolsWith {
443 name = "bootstrap-stage0-binutils-wrapper";
448 expand-response-params = "";
449 libc = selfDarwin.libSystem;
452 inherit (self) stdenvNoCC coreutils gnugrep;
453 runtimeShell = self.stdenvNoCC.shell;
455 bintools = selfDarwin.binutils-unwrapped;
457 # Bootstrap tools cctools needs the hook and wrappers to make sure things are signed properly,
458 # and additional linker flags to work around a since‐removed patch.
459 # This can be dropped once the bootstrap tools cctools has been updated to 1010.6.
460 extraBuildCommands = ''
461 printf %s ${lib.escapeShellArg ''
462 extraBefore+=("-F$DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks")
463 extraBefore+=("-L$DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib")
464 ''} >> $out/nix-support/add-local-ldflags-before.sh
466 echo 'source ${selfDarwin.postLinkSignHook}' >> $out/nix-support/post-link-hook
468 export signingUtils=${selfDarwin.signingUtils}
471 install_name_tool ${../../build-support/bintools-wrapper/darwin-install_name_tool-wrapper.sh} \
472 "${selfDarwin.binutils-unwrapped}/bin/install_name_tool"
475 strip ${../../build-support/bintools-wrapper/darwin-strip-wrapper.sh} \
476 "${selfDarwin.binutils-unwrapped}/bin/strip"
481 (superDarwin.binutils-unwrapped.override { enableManpages = false; }).overrideAttrs
484 passthru = (old.passthru or { }) // {
485 isFromBootstrapFiles = true;
489 locale = self.stdenv.mkDerivation {
490 name = "bootstrap-stage0-locale";
492 mkdir -p $out/share/locale
496 sigtool = bootstrapTools;
504 tools = super.llvmPackages.tools.extend (
506 libclang = self.stdenv.mkDerivation {
507 name = "bootstrap-stage0-clang";
516 ln -s ${bootstrapTools}/bin $out/bin
517 ln -s ${bootstrapTools}/lib/clang $out/lib
518 ln -s ${bootstrapTools}/include $out
521 isFromBootstrapFiles = true;
522 hardeningUnsupportedFlags = [
525 "stackclashprotection"
530 libllvm = self.stdenv.mkDerivation {
531 name = "bootstrap-stage0-llvm";
537 mkdir -p $out/bin $out/lib
539 for tool in ${toString super.darwin.binutils-unwrapped.llvm_cmds}; do
540 cctoolsTool=''${tool//-/_}
541 toolsrc="${bootstrapTools}/bin/$cctoolsTool"
542 if [ -e "$toolsrc" ]; then
543 ln -s "$toolsrc" $out/bin/llvm-$tool
546 ln -s ${bootstrapTools}/bin/dsymutil $out/bin/dsymutil
547 ln -s ${bootstrapTools}/lib/libLLVM* $out/lib
549 passthru.isFromBootstrapFiles = true;
551 lld = self.stdenv.mkDerivation {
552 name = "bootstrap-stage0-lld";
556 isFromBootstrapFiles = true;
561 libraries = super.llvmPackages.libraries.extend (
563 compiler-rt = self.stdenv.mkDerivation {
564 name = "bootstrap-stage0-compiler-rt";
566 mkdir -p $out/lib $out/share
567 ln -s ${bootstrapTools}/lib/libclang_rt* $out/lib
568 ln -s ${bootstrapTools}/lib/darwin $out/lib
570 passthru.isFromBootstrapFiles = true;
572 libcxx = self.stdenv.mkDerivation {
573 name = "bootstrap-stage0-libcxx";
575 mkdir -p $out/lib $out/include
576 ln -s ${bootstrapTools}/lib/libc++.dylib $out/lib
577 ln -s ${bootstrapTools}/include/c++ $out/include
581 isFromBootstrapFiles = true;
587 { inherit tools libraries; } // tools // libraries
592 stripDebugFlags="-S" # llvm-strip does not support "-p" for Mach-O
597 # This stage is primarily responsible for setting up versions of certain dependencies needed
598 # by the rest of the build process. This stage also builds CF and Libsystem to simplify assertions
599 # and assumptions for later by making sure both packages are present on x86_64-darwin and aarch64-darwin.
602 # previous stage0 stdenv:
603 assert allDeps isFromBootstrapFiles [
604 (llvmToolsPackages prevStage)
605 (llvmLibrariesPackages prevStage)
616 inherit (prevStage.darwin) binutils-unwrapped sigtool;
620 assert allDeps isFromNixpkgs [
621 (sdkPackagesNoCC prevStage)
622 { inherit (prevStage.darwin) binutils libSystem; }
626 name = "bootstrap-stage1";
628 overrides = self: super: {
629 inherit (prevStage) ccWrapperStdenv cctools ld64;
631 binutils-unwrapped = builtins.throw "nothing in the Darwin bootstrap should depend on GNU binutils";
632 curl = builtins.throw "nothing in the Darwin bootstrap can depend on curl";
634 # Use this stage’s CF to build CMake. It’s required but can’t be included in the stdenv.
635 cmake = self.cmakeMinimal;
637 # Use libiconvReal with gettext to break an infinite recursion.
638 gettext = super.gettext.override { libiconv = super.libiconvReal; };
640 # Disable tests because they use dejagnu, which fails to run.
641 libffi = super.libffi.override { doCheck = false; };
643 # Avoid pulling in a full python and its extra dependencies for the llvm/clang builds.
644 libxml2 = super.libxml2.override { pythonSupport = false; };
646 # Avoid pulling in openldap just to run Meson’s tests.
647 meson = super.meson.overrideAttrs { doInstallCheck = false; };
648 ninja = super.ninja.override { buildDocs = false; };
650 # pkg-config builds glib, which checks for `arpa/nameser.h` and fails to build if it can’t find it.
651 # libresolv is normally propagated by the SDK, but propagation is disabled early in the bootstrap.
652 # Trying to add libresolv as a dependency causes an infinite recursion. Use pkgconf instead.
654 (super.pkg-config.override {
655 pkg-config = self.libpkgconf.override {
656 removeReferencesTo = self.removeReferencesTo.override {
657 # Avoid an infinite recursion by using the previous stage‘s sigtool.
658 signingUtils = prevStage.darwin.signingUtils.override { inherit (prevStage.darwin) sigtool; };
661 baseBinName = "pkgconf";
663 # Passthru the wrapped pkgconf’s stdenv to make the bootstrap assertions happy.
666 passthru = old.passthru or { } // {
667 inherit (self) stdenv;
672 # Use a full Python for the bootstrap. This allows Meson to be built in stage 1 and makes it easier to build
673 # packages that have Python dependencies.
674 python3 = self.python3-bootstrap;
675 python3-bootstrap = super.python3.override {
676 self = self.python3-bootstrap;
677 pythonAttr = "python3-bootstrap";
679 # Workaround for ld64 crashes on x86_64-darwin. Remove after 11.0 is made the default.
680 inherit (prevStage) apple-sdk_11;
683 scons = super.scons.override { python3Packages = self.python3.pkgs; };
685 xar = super.xarMinimal;
687 darwin = super.darwin.overrideScope (
688 selfDarwin: superDarwin: {
689 signingUtils = prevStage.darwin.signingUtils.override { inherit (selfDarwin) sigtool; };
691 postLinkSignHook = prevStage.darwin.postLinkSignHook.override { inherit (selfDarwin) sigtool; };
693 adv_cmds = superDarwin.adv_cmds.override {
694 # Break an infinite recursion between CMake and libtapi. CMake requires adv_cmds.ps, and adv_cmds
695 # requires a newer SDK that requires libtapi to build, which requires CMake.
696 inherit (prevStage) apple-sdk_11;
699 # Rewrap binutils with the real libSystem
700 binutils = superDarwin.binutils.override {
701 inherit (self) coreutils;
702 bintools = selfDarwin.binutils-unwrapped;
703 libc = selfDarwin.libSystem;
705 # Bootstrap tools cctools needs the hook and wrappers to make sure things are signed properly.
706 # This can be dropped once the bootstrap tools cctools has been updated to 1010.6.
707 extraBuildCommands = ''
708 printf %s ${lib.escapeShellArg ''
709 extraBefore+=("-F$DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks")
710 extraBefore+=("-L$DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib")
711 ''} >> $out/nix-support/add-local-ldflags-before.sh
713 echo 'source ${selfDarwin.postLinkSignHook}' >> $out/nix-support/post-link-hook
715 export signingUtils=${selfDarwin.signingUtils}
718 install_name_tool ${../../build-support/bintools-wrapper/darwin-install_name_tool-wrapper.sh} \
719 "${selfDarwin.binutils-unwrapped}/bin/install_name_tool"
722 strip ${../../build-support/bintools-wrapper/darwin-strip-wrapper.sh} \
723 "${selfDarwin.binutils-unwrapped}/bin/strip"
727 # Avoid building unnecessary Python dependencies due to building LLVM manpages.
728 binutils-unwrapped = superDarwin.binutils-unwrapped.override {
729 inherit (self) cctools ld64;
730 enableManpages = false;
737 tools = super.llvmPackages.tools.extend (_: _: llvmToolsPackages prevStage);
738 libraries = super.llvmPackages.libraries.extend (_: _: llvmLibrariesPackages prevStage);
740 super.llvmPackages // { inherit tools libraries; } // tools // libraries;
743 extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [
744 prevStage.updateAutotoolsGnuConfigScriptsHook
749 stripDebugFlags="-S" # llvm-strip does not support "-p" for Mach-O
754 # First rebuild of LLVM. While this LLVM is linked to a bunch of junk from the bootstrap tools,
755 # the compiler-rt, libc++, and libc++abi it produces are not. The compiler will be
756 # rebuilt in a later stage, but those libraries will be used in the final stdenv.
759 # previous stage1 stdenv:
760 assert allDeps isFromBootstrapFiles [
761 (llvmLibrariesPackages prevStage)
762 (llvmToolsPackages prevStage)
763 { inherit (prevStage) ld64; }
766 assert allDeps isBuiltByBootstrapFilesCompiler [
767 (stage1Packages prevStage)
768 (darwinPackages prevStage)
769 (llvmLibrariesDeps prevStage)
770 (llvmToolsDeps prevStage)
771 (sdkPackages prevStage)
772 (sdkDarwinPackages prevStage)
775 assert allDeps isFromNixpkgs [
776 (darwinPackagesNoCC prevStage)
777 (sdkPackagesNoCC prevStage)
781 name = "bootstrap-stage-xclang";
786 (stage1Packages prevStage)
787 (disallowedPackages prevStage)
788 # Only cctools and ld64 are rebuilt from `bintoolsPackages` to avoid rebuilding their dependencies
789 # again in this stage after building them in stage 1.
790 (lib.filterAttrs (name: _: name != "ld64" && name != "cctools") (bintoolsPackages prevStage))
791 (llvmToolsDeps prevStage)
792 (sdkPackages prevStage)
793 (sdkPackagesNoCC prevStage)
795 inherit (prevStage) ccWrapperStdenv;
797 # Disable ld64’s install check phase because the required LTO libraries are not built yet.
798 ld64 = super.ld64.overrideAttrs { doInstallCheck = false; };
800 darwin = super.darwin.overrideScope (
801 selfDarwin: superDarwin:
802 darwinPackages prevStage
803 // sdkDarwinPackages prevStage
805 inherit (prevStage.darwin) libSystem;
806 binutils-unwrapped = superDarwin.binutils-unwrapped.override { enableManpages = false; };
812 extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [
813 prevStage.updateAutotoolsGnuConfigScriptsHook
818 stripDebugFlags="-S" # llvm-strip does not support "-p" for Mach-O
823 # This stage rebuilds the SDK. It also rebuilds bash, which will be needed in later stages
824 # to use in patched shebangs (e.g., to make sure `icu-config` uses bash from nixpkgs).
827 # previous stage-xclang stdenv:
828 assert allDeps isBuiltByBootstrapFilesCompiler [
829 (stage1Packages prevStage)
830 (bintoolsPackages prevStage)
831 (darwinPackages prevStage)
832 (llvmToolsDeps prevStage)
833 (llvmToolsPackages prevStage)
834 (sdkPackages prevStage)
835 (sdkDarwinPackages prevStage)
838 assert allDeps isBuiltByNixpkgsCompiler [
839 (llvmLibrariesDeps prevStage)
840 (llvmLibrariesPackages prevStage)
843 assert allDeps isFromNixpkgs [
844 (darwinPackagesNoCC prevStage)
845 (sdkPackagesNoCC prevStage)
849 name = "bootstrap-stage2";
854 (stage1Packages prevStage)
855 (disallowedPackages prevStage)
856 (bintoolsPackages prevStage)
857 (llvmLibrariesDeps prevStage)
858 (llvmToolsDeps prevStage)
860 inherit (prevStage) ccWrapperStdenv;
862 # Avoid an infinite recursion due to the SDK’s including ncurses, which depends on bash in its `dev` output.
863 bash = super.bash.override { stdenv = self.darwin.bootstrapStdenv; };
865 # Avoid pulling in a full python and its extra dependencies for the llvm/clang builds.
866 libxml2 = super.libxml2.override { pythonSupport = false; };
868 # Use Bash from this stage to avoid propagating Bash from a previous stage to the final stdenv.
869 ncurses = super.ncurses.override {
870 stdenv = self.darwin.bootstrapStdenv.override { shell = lib.getExe self.bash; };
873 darwin = super.darwin.overrideScope (
874 selfDarwin: superDarwin:
875 darwinPackages prevStage
877 inherit (prevStage.darwin) binutils-unwrapped;
878 # Rewrap binutils so it uses the rebuilt Libsystem.
879 binutils = superDarwin.binutils.override {
880 inherit (prevStage) expand-response-params;
881 libc = selfDarwin.libSystem;
888 tools = super.llvmPackages.tools.extend (
889 _: _: llvmToolsPackages prevStage // { inherit (prevStage.llvmPackages) clangNoCompilerRtWithLibc; }
891 libraries = super.llvmPackages.libraries.extend (_: _: llvmLibrariesPackages prevStage);
893 super.llvmPackages // { inherit tools libraries; } // tools // libraries;
897 extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [
898 prevStage.updateAutotoolsGnuConfigScriptsHook
903 stripDebugFlags="-S" # llvm-strip does not support "-p" for Mach-O
908 # Rebuild LLVM with LLVM. This stage also rebuilds certain dependencies needed by LLVM.
909 # The SDK (but not its other inputs) is also rebuilt this stage to pick up the rebuilt cctools for `libtool`.
912 # previous stage2 stdenv:
913 assert allDeps isBuiltByBootstrapFilesCompiler [
914 (stage1Packages prevStage)
915 (bintoolsPackages prevStage)
916 (darwinPackages prevStage)
917 (llvmToolsPackages prevStage)
918 (llvmToolsDeps prevStage)
921 assert allDeps isBuiltByNixpkgsCompiler [
922 (llvmLibrariesDeps prevStage)
923 (llvmLibrariesPackages prevStage)
924 (sdkPackages prevStage)
925 (sdkDarwinPackages prevStage)
928 assert allDeps isFromNixpkgs [
929 (darwinPackagesNoCC prevStage)
930 (sdkPackagesNoCC prevStage)
934 name = "bootstrap-stage3";
939 (stage1Packages prevStage)
940 (disallowedPackages prevStage)
941 (llvmLibrariesDeps prevStage)
942 (sdkPackages prevStage)
944 inherit (prevStage) ccWrapperStdenv;
946 # Disable tests because they use dejagnu, which fails to run.
947 libffi = super.libffi.override { doCheck = false; };
949 xar = super.xarMinimal;
951 darwin = super.darwin.overrideScope (
952 selfDarwin: superDarwin:
953 darwinPackages prevStage
954 // sdkDarwinPackages prevStage
956 inherit (prevStage.darwin) libSystem;
958 # binutils-unwrapped needs to build the LLVM man pages, which requires a lot of Python stuff
959 # that ultimately ends up depending on git. Fortunately, the git dependency is only for check
960 # inputs. The following set of overrides allow the LLVM documentation to be built without
961 # pulling curl (and other packages like ffmpeg) into the stdenv bootstrap.
962 binutils-unwrapped = superDarwin.binutils-unwrapped.override (old: {
963 llvm-manpages = super.llvmPackages.llvm-manpages.override {
964 python3Packages = self.python3.pkgs.overrideScope (
966 hatch-vcs = superPython.hatch-vcs.overrideAttrs { doInstallCheck = false; };
967 markdown-it-py = superPython.markdown-it-py.overrideAttrs { doInstallCheck = false; };
968 mdit-py-plugins = superPython.mdit-py-plugins.overrideAttrs { doInstallCheck = false; };
969 myst-parser = superPython.myst-parser.overrideAttrs { doInstallCheck = false; };
979 libraries = super.llvmPackages.libraries.extend (_: _: llvmLibrariesPackages prevStage);
981 super.llvmPackages // { inherit libraries; } // libraries;
985 extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [
986 prevStage.updateAutotoolsGnuConfigScriptsHook
991 stripDebugFlags="-S" # llvm-strip does not support "-p" for Mach-O
996 # Construct a standard environment with the new clang. Also use the new compiler to rebuild
997 # everything that will be part of the final stdenv and isn’t required by it, CF, or Libsystem.
1000 # previous stage3 stdenv:
1001 assert allDeps isBuiltByBootstrapFilesCompiler [
1002 (stage1Packages prevStage)
1003 (darwinPackages prevStage)
1006 assert allDeps isBuiltByNixpkgsCompiler [
1007 (bintoolsPackages prevStage)
1008 (llvmLibrariesDeps prevStage)
1009 (llvmLibrariesPackages prevStage)
1010 (llvmToolsDeps prevStage)
1011 (llvmToolsPackages prevStage)
1012 (sdkPackages prevStage)
1013 (sdkDarwinPackages prevStage)
1016 assert allDeps isFromNixpkgs [
1017 (darwinPackagesNoCC prevStage)
1018 (sdkPackagesNoCC prevStage)
1021 stageFun prevStage {
1022 name = "bootstrap-stage4";
1026 mergeDisjointAttrs [
1027 (bintoolsPackages prevStage)
1028 (disallowedPackages prevStage)
1029 (llvmLibrariesDeps prevStage)
1030 (llvmToolsDeps prevStage)
1031 (sdkPackages prevStage)
1032 (sdkPackagesNoCC prevStage)
1034 inherit (prevStage) ccWrapperStdenv;
1036 # Rebuild locales and sigtool with the new clang.
1037 darwin = super.darwin.overrideScope (
1039 sdkDarwinPackages prevStage
1041 inherit (prevStage.darwin) binutils-unwrapped libSystem;
1042 binutils = superDarwin.binutils.override {
1043 # Build expand-response-params with last stage like below
1044 inherit (prevStage) expand-response-params;
1046 # Avoid rebuilding bmake (and Python) just for locales
1047 locale = superDarwin.locale.override { inherit (prevStage) bmake; };
1053 tools = super.llvmPackages.tools.extend (
1055 llvmToolsPackages prevStage
1057 libcxxClang = super.wrapCCWith rec {
1058 nativeTools = false;
1061 inherit (prevStage) expand-response-params;
1063 extraPackages = [ self.llvmPackages.compiler-rt ];
1065 extraBuildCommands = ''
1066 rsrc="$out/resource-root"
1068 ln -s "${lib.getLib cc}/lib/clang/${lib.versions.major (lib.getVersion cc)}/include" "$rsrc"
1069 echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
1070 ln -s "${prevStage.llvmPackages.compiler-rt.out}/lib" "$rsrc/lib"
1071 ln -s "${prevStage.llvmPackages.compiler-rt.out}/share" "$rsrc/share"
1074 cc = self.llvmPackages.clang-unwrapped;
1075 bintools = self.darwin.binutils;
1078 libc = self.darwin.libSystem;
1079 inherit (self.llvmPackages) libcxx;
1091 libraries = super.llvmPackages.libraries.extend (_: _: llvmLibrariesPackages prevStage);
1093 super.llvmPackages // { inherit tools libraries; } // tools // libraries;
1097 extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [
1098 prevStage.updateAutotoolsGnuConfigScriptsHook
1099 prevStage.gnu-config
1103 stripDebugFlags="-S" # llvm-strip does not support "-p" for Mach-O
1108 # Construct the final stdenv. The version of LLVM provided should match the one defined in
1109 # `all-packages.nix` for Darwin. Nothing should depend on the bootstrap tools or originate from
1110 # the bootstrap tools.
1112 # When updating the Darwin stdenv, make sure that the result has no dependency (`nix-store -qR`)
1113 # on `bootstrapTools` or the binutils built in stage 1.
1116 # previous stage4 stdenv:
1118 assert allDeps isBuiltByNixpkgsCompiler [
1119 (lib.filterAttrs (_: pkg: lib.getName pkg != "pkg-config-wrapper") (stage1Packages prevStage)) # pkg-config is a wrapper
1120 (bintoolsPackages prevStage)
1121 (darwinPackages prevStage)
1122 (llvmLibrariesDeps prevStage)
1123 (llvmLibrariesPackages prevStage)
1124 (llvmToolsDeps prevStage)
1125 (llvmToolsPackages prevStage)
1126 (sdkPackages prevStage)
1127 (sdkDarwinPackages prevStage)
1128 { inherit (prevStage.pkg-config) pkg-config; }
1131 assert allDeps isFromNixpkgs [
1132 (darwinPackagesNoCC prevStage)
1133 (sdkPackagesNoCC prevStage)
1137 cc = prevStage.llvmPackages.clang;
1140 inherit config overlays;
1141 stdenv = import ../generic {
1142 name = "stdenv-darwin";
1144 buildPlatform = localSystem;
1145 hostPlatform = localSystem;
1146 targetPlatform = localSystem;
1152 stripDebugFlags="-S" # llvm-strip does not support "-p" for Mach-O
1153 export PATH_LOCALE=${prevStage.darwin.locale}/share/locale
1156 initialPath = ((import ../generic/common-path.nix) { pkgs = prevStage; });
1158 extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [
1159 prevStage.updateAutotoolsGnuConfigScriptsHook
1162 extraBuildInputs = [ prevStage.apple-sdk ];
1168 inherit (prevStage.stdenv) fetchurlBoot;
1171 inherit bootstrapTools;
1172 libc = prevStage.darwin.libSystem;
1173 shellPackage = prevStage.bash;
1176 disallowedRequisites = [ bootstrapTools.out ];
1186 cc.expand-response-params
1191 darwin.binutils.bintools
1226 ++ apple-sdk.propagatedBuildInputs
1228 ++ lib.optionals localSystem.isAarch64 [
1229 prevStage.updateAutotoolsGnuConfigScriptsHook
1230 prevStage.gnu-config
1232 ++ lib.optionals localSystem.isx86_64 [ prevStage.darwin.Csu ]
1233 ++ (with prevStage.darwin; [
1240 ++ (with prevStage.llvmPackages; [
1243 (lib.getLib clang-unwrapped)
1253 __stdenvImpureHostDeps = commonImpureHostDeps;
1254 __extraImpureHostDeps = commonImpureHostDeps;
1258 mergeDisjointAttrs [
1259 (llvmLibrariesDeps prevStage)
1260 (llvmToolsDeps prevStage)
1261 (sdkPackages prevStage)
1262 (sdkPackagesNoCC prevStage)
1278 # TODO: Simplify when dropping support for macOS < 11.
1279 "apple-sdk_${builtins.replaceStrings [ "." ] [ "_" ] sdkMajorVersion}" = self.apple-sdk;
1281 darwin = super.darwin.overrideScope (
1283 sdkDarwinPackages prevStage
1285 inherit (prevStage.darwin) libSystem locale sigtool;
1287 // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) {
1288 inherit (prevStage.darwin) binutils binutils-unwrapped;
1292 (lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) (
1293 (bintoolsPackages prevStage)
1295 inherit (prevStage.llvmPackages) clang;
1296 # Need to get rid of these when cross-compiling.
1297 "llvmPackages_${lib.versions.major prevStage.llvmPackages.release_version}" =
1299 llvmVersion = lib.versions.major prevStage.llvmPackages.release_version;
1300 tools = super."llvmPackages_${llvmVersion}".tools.extend (
1301 _: _: llvmToolsPackages prevStage // { inherit (prevStage.llvmPackages) clang; }
1303 libraries = super."llvmPackages_${llvmVersion}".libraries.extend (
1304 _: _: llvmLibrariesPackages prevStage
1307 super."llvmPackages_${llvmVersion}" // { inherit tools libraries; } // tools // libraries;
1315 # This "no-op" stage is just a place to put the assertions about the final stage.
1318 # previous final stage stdenv:
1319 assert isBuiltByNixpkgsCompiler prevStage.cctools;
1320 assert isBuiltByNixpkgsCompiler prevStage.ld64;
1321 assert isBuiltByNixpkgsCompiler prevStage.darwin.sigtool;
1323 assert isFromNixpkgs prevStage.darwin.libSystem;
1324 assert isFromNixpkgs prevStage.darwin.binutils-unwrapped;
1326 assert isBuiltByNixpkgsCompiler prevStage.llvmPackages.clang-unwrapped;
1327 assert isBuiltByNixpkgsCompiler prevStage.llvmPackages.libllvm;
1328 assert isBuiltByNixpkgsCompiler prevStage.llvmPackages.libcxx;
1329 assert isBuiltByNixpkgsCompiler prevStage.llvmPackages.compiler-rt;
1331 # Make sure these evaluate since they were disabled explicitly in the bootstrap.
1332 assert isBuiltByNixpkgsCompiler prevStage.binutils-unwrapped;
1333 assert isFromNixpkgs prevStage.binutils-unwrapped.src;
1334 assert isBuiltByNixpkgsCompiler prevStage.curl;
1336 # libiconv should be an alias for darwin.libiconv
1337 assert prevStage.libiconv == prevStage.darwin.libiconv;
1340 inherit (prevStage) config overlays stdenv;