2 , localSystem, crossSystem, config, overlays, crossOverlays ? []
6 bootStages = import ../. {
7 inherit lib localSystem overlays;
9 crossSystem = localSystem;
12 # Ignore custom stdenvs when cross compiling for compatibility
13 # Use replaceCrossStdenv instead.
14 config = builtins.removeAttrs config [ "replaceStdenv" ];
17 in lib.init bootStages ++ [
19 # Regular native packages
20 (somePrevStage: lib.last bootStages somePrevStage // {
21 # It's OK to change the built-time dependencies
22 allowCustomOverrides = true;
27 inherit config overlays;
30 assert vanillaPackages.stdenv.buildPlatform == localSystem;
31 assert vanillaPackages.stdenv.hostPlatform == localSystem;
32 assert vanillaPackages.stdenv.targetPlatform == localSystem;
33 vanillaPackages.stdenv.override { targetPlatform = crossSystem; };
34 # It's OK to change the built-time dependencies
35 allowCustomOverrides = true;
41 if crossSystem.isStatic
42 then buildPackages.stdenvAdapters.makeStatic
44 stdenvNoCC = adaptStdenv (buildPackages.stdenv.override (old: rec {
45 buildPlatform = localSystem;
46 hostPlatform = crossSystem;
47 targetPlatform = crossSystem;
49 # Prior overrides are surely not valid as packages built with this run on
50 # a different platform, and so are disabled.
52 extraBuildInputs = [ ]; # Old ones run on wrong platform
53 allowedRequisites = null;
58 extraNativeBuildInputs = old.extraNativeBuildInputs
60 (hostPlatform.isLinux && !buildPlatform.isLinux)
61 [ buildPackages.patchelf ]
63 (let f = p: !p.isx86 || builtins.elem p.libc [ "musl" "wasilibc" "relibc" ] || p.isiOS || p.isGenode;
64 in f hostPlatform && !(f buildPlatform) )
65 buildPackages.updateAutotoolsGnuConfigScriptsHook
70 overlays = overlays ++ crossOverlays;
74 inherit (stdenvNoCC) hostPlatform targetPlatform;
75 baseStdenv = stdenvNoCC.override {
76 # Old ones run on wrong platform
77 extraBuildInputs = lib.optionals hostPlatform.isDarwin [
78 buildPackages.targetPackages.darwin.apple_sdk.frameworks.CoreFoundation
81 hasCC = !stdenvNoCC.targetPlatform.isGhcjs;
83 cc = if crossSystem.useiOSPrebuilt or false
84 then buildPackages.darwin.iosSdkPkgs.clang
85 else if crossSystem.useAndroidPrebuilt or false
86 then buildPackages."androidndkPkgs_${crossSystem.androidNdkVersion}".clang
87 else if targetPlatform.isGhcjs
88 # Need to use `throw` so tryEval for splicing works, ugh. Using
89 # `null` or skipping the attribute would cause an eval failure
90 # `tryEval` wouldn't catch, wrecking accessing previous stages
91 # when there is a C compiler and everything should be fine.
92 then throw "no C compiler provided for this platform"
93 else if crossSystem.isDarwin
94 then buildPackages.llvmPackages.libcxxClang
95 else if crossSystem.useLLVM or false
96 then buildPackages.llvmPackages.clang
97 else if crossSystem.useZig or false
98 then buildPackages.zig.cc
99 else if crossSystem.useArocc or false
100 then buildPackages.arocc
101 else buildPackages.gcc;
104 in if config ? replaceCrossStdenv then config.replaceCrossStdenv { inherit buildPackages baseStdenv; } else baseStdenv;