top-level: {build,host,target}Platform are defined in the stdenv instead

See #27069 for a discussion of this

+90 -124
+3 -2
pkgs/build-support/cc-wrapper/default.nix
··· 10 10 , zlib ? null, extraPackages ? [], extraBuildCommands ? "" 11 11 , dyld ? null # TODO: should this be a setup-hook on dyld? 12 12 , isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null 13 - , hostPlatform, targetPlatform 14 13 , runCommand ? null 15 14 }: 16 15 ··· 22 21 assert !(nativeLibc && noLibc); 23 22 assert (noLibc || nativeLibc) == (libc == null); 24 23 25 - assert targetPlatform != hostPlatform -> runCommand != null; 24 + assert stdenv.targetPlatform != stdenv.hostPlatform -> runCommand != null; 26 25 27 26 # For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper. 28 27 assert cc.langVhdl or false -> zlib != null; 29 28 30 29 let 30 + inherit (stdenv) hostPlatform targetPlatform; 31 + 31 32 # Prefix for binaries. Customarily ends with a dash separator. 32 33 # 33 34 # TODO(@Ericson2314) Make unconditional, or optional but always true by
+3 -5
pkgs/stdenv/adapters.nix
··· 61 61 , buildPlatform, hostPlatform, targetPlatform 62 62 } @ overrideArgs: let 63 63 stdenv = overrideArgs.stdenv.override { 64 - # TODO(@Ericson2314): Cannot do this for now because then Nix thinks the 65 - # resulting derivation should be built on the host platform. 66 - #hostPlatform = buildPlatform; 67 - #targetPlatform = hostPlatform; 68 - inherit cc; 64 + inherit 65 + buildPlatform hostPlatform targetPlatform 66 + cc; 69 67 70 68 allowedRequisites = null; 71 69
+4 -7
pkgs/stdenv/cross/default.nix
··· 14 14 15 15 # Build Packages 16 16 (vanillaPackages: { 17 - buildPlatform = localSystem; 18 - hostPlatform = localSystem; 19 - targetPlatform = crossSystem; 20 17 inherit config overlays; 21 18 selfBuild = false; 19 + stdenv = 20 + assert vanillaPackages.hostPlatform == localSystem; 21 + assert vanillaPackages.targetPlatform == localSystem; 22 + vanillaPackages.stdenv.override { targetPlatform = crossSystem; }; 22 23 # It's OK to change the built-time dependencies 23 24 allowCustomOverrides = true; 24 - inherit (vanillaPackages) stdenv; 25 25 }) 26 26 27 27 # Run Packages 28 28 (buildPackages: { 29 - buildPlatform = localSystem; 30 - hostPlatform = crossSystem; 31 - targetPlatform = crossSystem; 32 29 inherit config overlays; 33 30 selfBuild = false; 34 31 stdenv = buildPackages.makeStdenvCross {
+4 -4
pkgs/stdenv/custom/default.nix
··· 15 15 16 16 # Additional stage, built using custom stdenv 17 17 (vanillaPackages: { 18 - buildPlatform = localSystem; 19 - hostPlatform = localSystem; 20 - targetPlatform = localSystem; 21 18 inherit config overlays; 22 - stdenv = config.replaceStdenv { pkgs = vanillaPackages; }; 19 + stdenv = 20 + assert vanillaPackages.hostPlatform == localSystem; 21 + assert vanillaPackages.targetPlatform == localSystem; 22 + config.replaceStdenv { pkgs = vanillaPackages; }; 23 23 }) 24 24 25 25 ]
+8 -16
pkgs/stdenv/darwin/default.nix
··· 65 65 66 66 name = "stdenv-darwin-boot-${toString step}"; 67 67 68 + buildPlatform = localSystem; 69 + hostPlatform = localSystem; 70 + targetPlatform = localSystem; 71 + 68 72 cc = if isNull last then "/dev/null" else import ../../build-support/cc-wrapper { 69 73 inherit shell; 70 74 inherit (last) stdenv; ··· 73 77 nativeTools = true; 74 78 nativePrefix = bootstrapTools; 75 79 nativeLibc = false; 76 - hostPlatform = localSystem; 77 - targetPlatform = localSystem; 78 80 libc = last.pkgs.darwin.Libsystem; 79 81 isClang = true; 80 82 cc = { name = "clang-9.9.9"; outPath = bootstrapTools; }; ··· 90 92 ''; 91 93 initialPath = [ bootstrapTools ]; 92 94 93 - hostPlatform = localSystem; 94 - targetPlatform = localSystem; 95 - 96 95 fetchurlBoot = import ../../build-support/fetchurl { 97 96 stdenv = stage0.stdenv; 98 97 curl = bootstrapTools; ··· 107 106 }; 108 107 109 108 in { 110 - buildPlatform = localSystem; 111 - hostPlatform = localSystem; 112 - targetPlatform = localSystem; 113 109 inherit config overlays; 114 110 stdenv = thisStdenv; 115 111 }; ··· 279 275 280 276 name = "stdenv-darwin"; 281 277 278 + buildPlatform = localSystem; 279 + hostPlatform = localSystem; 280 + targetPlatform = localSystem; 281 + 282 282 preHook = commonPreHook + '' 283 283 export PATH_LOCALE=${pkgs.darwin.locale}/share/locale 284 284 ''; ··· 286 286 stdenvSandboxProfile = binShClosure + libSystemProfile; 287 287 extraSandboxProfile = binShClosure + libSystemProfile; 288 288 289 - hostPlatform = localSystem; 290 - targetPlatform = localSystem; 291 - 292 289 initialPath = import ../common-path.nix { inherit pkgs; }; 293 290 shell = "${pkgs.bash}/bin/bash"; 294 291 ··· 297 294 inherit shell; 298 295 nativeTools = false; 299 296 nativeLibc = false; 300 - hostPlatform = localSystem; 301 - targetPlatform = localSystem; 302 297 inherit (pkgs) coreutils binutils gnugrep; 303 298 inherit (pkgs.darwin) dyld; 304 299 cc = pkgs.llvmPackages.clang-unwrapped; ··· 338 333 stage3 339 334 stage4 340 335 (prevStage: { 341 - buildPlatform = localSystem; 342 - hostPlatform = localSystem; 343 - targetPlatform = localSystem; 344 336 inherit config overlays; 345 337 stdenv = stdenvDarwin prevStage; 346 338 })
+9 -5
pkgs/stdenv/freebsd/default.nix
··· 35 35 36 36 stdenv = import ../generic { 37 37 name = "stdenv-freebsd-boot-1"; 38 + buildPlatform = localSystem; 39 + hostPlatform = localSystem; 40 + targetPlatform = localSystem; 38 41 inherit config; 39 42 initialPath = [ "/" "/usr" ]; 40 43 hostPlatform = localSystem; ··· 52 55 53 56 stdenv = import ../generic { 54 57 name = "stdenv-freebsd-boot-0"; 58 + buildPlatform = localSystem; 59 + hostPlatform = localSystem; 60 + targetPlatform = localSystem; 55 61 inherit config; 56 62 initialPath = [ prevStage.bootstrapTools ]; 57 63 inherit (prevStage.stdenv) ··· 62 68 }) 63 69 64 70 (prevStage: { 65 - buildPlatform = localSystem; 66 - hostPlatform = localSystem; 67 - targetPlatform = localSystem; 68 71 inherit config overlays; 69 72 stdenv = import ../generic { 70 73 name = "stdenv-freebsd-boot-3"; 74 + buildPlatform = localSystem; 75 + hostPlatform = localSystem; 76 + targetPlatform = localSystem; 71 77 inherit config; 72 78 73 79 inherit (prevStage.stdenv) ··· 77 83 nativeTools = true; 78 84 nativePrefix = "/usr"; 79 85 nativeLibc = true; 80 - hostPlatform = localSystem; 81 - targetPlatform = localSystem; 82 86 inherit (prevStage) stdenv; 83 87 cc = { 84 88 name = "clang-9.9.9";
+31 -14
pkgs/stdenv/generic/default.nix
··· 15 15 , stdenvSandboxProfile ? "" 16 16 , extraSandboxProfile ? "" 17 17 18 - , # The platforms here do *not* correspond to the stage the stdenv is 19 - # used in, but rather the previous one, in which it was built. We 20 - # use the latter two platforms, like a cross compiler, because the 21 - # stand environment is a build tool if you squint at it, and because 22 - # neither of these are used when building stdenv so we know the 23 - # build platform is irrelevant. 24 - hostPlatform, targetPlatform 18 + ## Platform parameters 19 + ## 20 + ## The "build" "host" "target" terminology below comes from GNU Autotools. See 21 + ## its documentation for more information on what those words mean. Note that 22 + ## each should always be defined, even when not cross compiling. 23 + ## 24 + ## For purposes of bootstrapping, think of each stage as a "sliding window" 25 + ## over a list of platforms. Specifically, the host platform of the previous 26 + ## stage becomes the build platform of the current one, and likewise the 27 + ## target platform of the previous stage becomes the host platform of the 28 + ## current one. 29 + ## 30 + 31 + , # The platform on which packages are built. Consists of `system`, a 32 + # string (e.g.,`i686-linux') identifying the most import attributes of the 33 + # build platform, and `platform` a set of other details. 34 + buildPlatform 35 + 36 + , # The platform on which packages run. 37 + hostPlatform 38 + 39 + , # The platform which build tools (especially compilers) build for in this stage, 40 + targetPlatform 25 41 }: 26 42 27 43 let 28 - inherit (targetPlatform) system; 29 - 30 44 defaultNativeBuildInputs = extraBuildInputs ++ 31 45 [ ../../build-support/setup-hooks/move-docs.sh 32 46 ../../build-support/setup-hooks/compress-man-pages.sh ··· 49 63 derivation ( 50 64 (if isNull allowedRequisites then {} else { allowedRequisites = allowedRequisites ++ defaultNativeBuildInputs; }) // 51 65 { 52 - inherit system name; 66 + inherit name; 67 + 68 + # Nix itself uses the `system` field of a derivation to decide where to 69 + # build it. This is a bit confusing for cross compilation. 70 + inherit (buildPlatform) system; 53 71 54 72 builder = shell; 55 73 ··· 59 77 60 78 inherit preHook initialPath shell defaultNativeBuildInputs; 61 79 } 62 - // lib.optionalAttrs hostPlatform.isDarwin { 80 + // lib.optionalAttrs buildPlatform.isDarwin { 63 81 __sandboxProfile = stdenvSandboxProfile; 64 82 __impureHostDeps = __stdenvImpureHostDeps; 65 83 }) ··· 71 89 platforms = lib.platforms.all; 72 90 }; 73 91 92 + inherit buildPlatform hostPlatform targetPlatform; 93 + 74 94 inherit extraBuildInputs __extraImpureHostDeps extraSandboxProfile; 75 95 76 96 # Utility flags to test the type of platform. ··· 85 105 86 106 inherit (import ./make-derivation.nix { 87 107 inherit lib config stdenv; 88 - # TODO(@Ericson2314): Remove 89 - inherit 90 - hostPlatform targetPlatform; 91 108 }) mkDerivation; 92 109 93 110 # For convenience, bring in the library functions in lib/ so
+8 -10
pkgs/stdenv/generic/make-derivation.nix
··· 1 - { lib, config, stdenv 2 - 3 - # TODO(@Ericson2314): get off stdenv 4 - , hostPlatform, targetPlatform 5 - }: 1 + { lib, config, stdenv }: 6 2 7 3 rec { 8 4 # `mkDerivation` wraps the builtin `derivation` function to ··· 49 45 50 46 outputs' = 51 47 outputs ++ 52 - (if separateDebugInfo then assert targetPlatform.isLinux; [ "debug" ] else []); 48 + (if separateDebugInfo then assert stdenv.hostPlatform.isLinux; [ "debug" ] else []); 53 49 54 50 dependencies' = let 55 51 justMap = map lib.chooseDevOutputs dependencies; 56 52 nativeBuildInputs = lib.elemAt justMap 0 57 - ++ lib.optional targetPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh; 53 + ++ lib.optional stdenv.hostPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh; 58 54 buildInputs = lib.elemAt justMap 1 59 55 # TODO(@Ericson2314): Should instead also be appended to `nativeBuildInputs`. 60 56 ++ lib.optional separateDebugInfo ../../build-support/setup-hooks/separate-debug-info.sh; ··· 82 78 builder = attrs.realBuilder or stdenv.shell; 83 79 args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; 84 80 inherit stdenv; 85 - system = stdenv.system; # TODO(@Ericson2314): be correct about cross compilation 81 + inherit (stdenv) system; 86 82 userHook = config.stdenv.userHook or null; 87 83 __ignoreNulls = true; 88 84 ··· 91 87 92 88 propagatedNativeBuildInputs = lib.elemAt propagatedDependencies' 0; 93 89 propagatedBuildInputs = lib.elemAt propagatedDependencies' 1; 94 - } // lib.optionalAttrs (hostPlatform.isDarwin) { 90 + } // lib.optionalAttrs (stdenv.buildPlatform.isDarwin) { 95 91 # TODO: remove lib.unique once nix has a list canonicalization primitive 96 92 __sandboxProfile = 97 93 let profiles = [ stdenv.extraSandboxProfile ] ++ computedSandboxProfile ++ computedPropagatedSandboxProfile ++ [ propagatedSandboxProfile sandboxProfile ]; ··· 139 135 { 140 136 inherit lib config meta derivationArg; 141 137 mkDerivationArg = attrs; 142 - inherit (stdenv) system; # TODO: cross-compilation? 138 + # Nix itself uses the `system` field of a derivation to decide where 139 + # to build it. This is a bit confusing for cross compilation. 140 + inherit (stdenv) system; 143 141 })) 144 142 ( { 145 143 overrideAttrs = f: mkDerivation (attrs // (f attrs));
+7 -17
pkgs/stdenv/linux/default.nix
··· 52 52 let 53 53 54 54 thisStdenv = import ../generic { 55 + name = "stdenv-linux-boot"; 56 + buildPlatform = localSystem; 57 + hostPlatform = localSystem; 58 + targetPlatform = localSystem; 55 59 inherit config extraBuildInputs; 56 - name = "stdenv-linux-boot"; 57 60 preHook = 58 61 '' 59 62 # Don't patch #!/interpreter because it leads to retained ··· 64 67 shell = "${bootstrapTools}/bin/bash"; 65 68 initialPath = [bootstrapTools]; 66 69 67 - hostPlatform = localSystem; 68 - targetPlatform = localSystem; 69 - 70 70 fetchurlBoot = import ../../build-support/fetchurl/boot.nix { 71 71 inherit system; 72 72 }; ··· 76 76 else lib.makeOverridable (import ../../build-support/cc-wrapper) { 77 77 nativeTools = false; 78 78 nativeLibc = false; 79 - hostPlatform = localSystem; 80 - targetPlatform = localSystem; 81 79 cc = prevStage.gcc-unwrapped; 82 80 isGNU = true; 83 81 libc = prevStage.glibc; ··· 99 97 }; 100 98 101 99 in { 102 - buildPlatform = localSystem; 103 - hostPlatform = localSystem; 104 - targetPlatform = localSystem; 105 100 inherit config overlays; 106 101 stdenv = thisStdenv; 107 102 }; ··· 241 236 nativeTools = false; 242 237 nativeLibc = false; 243 238 isGNU = true; 244 - hostPlatform = localSystem; 245 - targetPlatform = localSystem; 246 239 cc = prevStage.gcc-unwrapped; 247 240 libc = self.glibc; 248 241 inherit (self) stdenv binutils coreutils gnugrep; ··· 263 256 # dependency (`nix-store -qR') on bootstrapTools or the first 264 257 # binutils built. 265 258 (prevStage: { 266 - buildPlatform = localSystem; 267 - hostPlatform = localSystem; 268 - targetPlatform = localSystem; 269 259 inherit config overlays; 270 260 stdenv = import ../generic rec { 261 + buildPlatform = localSystem; 262 + hostPlatform = localSystem; 263 + targetPlatform = localSystem; 271 264 inherit config; 272 265 273 266 preHook = '' ··· 279 272 280 273 initialPath = 281 274 ((import ../common-path.nix) {pkgs = prevStage;}); 282 - 283 - hostPlatform = localSystem; 284 - targetPlatform = localSystem; 285 275 286 276 extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++ 287 277 # Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64.
+1 -8
pkgs/stdenv/native/default.nix
··· 81 81 { cc, fetchurl, extraPath ? [], overrides ? (self: super: { }) }: 82 82 83 83 import ../generic { 84 + buildPlatform = localSystem; 84 85 hostPlatform = localSystem; 85 86 targetPlatform = localSystem; 86 87 ··· 125 126 "i686-solaris" = "/usr/gnu"; 126 127 "x86_64-solaris" = "/opt/local/gcc47"; 127 128 }.${system} or "/usr"; 128 - hostPlatform = localSystem; 129 - targetPlatform = localSystem; 130 129 inherit stdenv; 131 130 }; 132 131 ··· 140 139 141 140 # First build a stdenv based only on tools outside the store. 142 141 (prevStage: { 143 - buildPlatform = localSystem; 144 - hostPlatform = localSystem; 145 - targetPlatform = localSystem; 146 142 inherit config overlays; 147 143 stdenv = makeStdenv { 148 144 inherit (prevStage) cc fetchurl; ··· 152 148 # Using that, build a stdenv that adds the ‘xz’ command (which most systems 153 149 # don't have, so we mustn't rely on the native environment providing it). 154 150 (prevStage: { 155 - buildPlatform = localSystem; 156 - hostPlatform = localSystem; 157 - targetPlatform = localSystem; 158 151 inherit config overlays; 159 152 stdenv = makeStdenv { 160 153 inherit (prevStage.stdenv) cc fetchurl;
+4 -3
pkgs/stdenv/nix/default.nix
··· 10 10 (prevStage: let 11 11 inherit (prevStage) stdenv; 12 12 in { 13 - inherit (prevStage) buildPlatform hostPlatform targetPlatform; 14 13 inherit config overlays; 15 14 16 15 stdenv = import ../generic rec { 16 + buildPlatform = localSystem; 17 + hostPlatform = localSystem; 18 + targetPlatform = localSystem; 19 + 17 20 inherit config; 18 21 19 22 preHook = '' ··· 30 33 nativeTools = false; 31 34 nativePrefix = stdenv.lib.optionalString hostPlatform.isSunOS "/usr"; 32 35 nativeLibc = true; 33 - hostPlatform = localSystem; 34 - targetPlatform = localSystem; 35 36 inherit stdenv; 36 37 inherit (prevStage) binutils coreutils gnugrep; 37 38 cc = prevStage.gcc.cc;
+8 -33
pkgs/top-level/stage.nix
··· 18 18 , # Use to reevaluate Nixpkgs; a dirty hack that should be removed 19 19 nixpkgsFun 20 20 21 - ## Platform parameters 22 - ## 23 - ## The "build" "host" "target" terminology below comes from GNU Autotools. See 24 - ## its documentation for more information on what those words mean. Note that 25 - ## each should always be defined, even when not cross compiling. 26 - ## 27 - ## For purposes of bootstrapping, think of each stage as a "sliding window" 28 - ## over a list of platforms. Specifically, the host platform of the previous 29 - ## stage becomes the build platform of the current one, and likewise the 30 - ## target platform of the previous stage becomes the host platform of the 31 - ## current one. 32 - ## 33 - 34 - , # The platform on which packages are built. Consists of `system`, a 35 - # string (e.g.,`i686-linux') identifying the most import attributes of the 36 - # build platform, and `platform` a set of other details. 37 - buildPlatform 38 - 39 - , # The platform on which packages run. 40 - hostPlatform 41 - 42 - , # The platform which build tools (especially compilers) build for in this stage, 43 - targetPlatform 44 - 45 21 ## Other parameters 46 22 ## 47 23 ··· 69 45 , # Non-GNU/Linux OSes are currently "impure" platforms, with their libc 70 46 # outside of the store. Thus, GCC, GFortran, & co. must always look for files 71 47 # in standard system directories (/usr/include, etc.) 72 - noSysDirs ? buildPlatform.system != "x86_64-freebsd" 73 - && buildPlatform.system != "i686-freebsd" 74 - && buildPlatform.system != "x86_64-solaris" 75 - && buildPlatform.system != "x86_64-kfreebsd-gnu" 48 + noSysDirs ? stdenv.buildPlatform.system != "x86_64-freebsd" 49 + && stdenv.buildPlatform.system != "i686-freebsd" 50 + && stdenv.buildPlatform.system != "x86_64-solaris" 51 + && stdenv.buildPlatform.system != "x86_64-kfreebsd-gnu" 76 52 77 53 , # The configuration attribute set 78 54 config ··· 98 74 // { recurseForDerivations = false; }; 99 75 __targetPackages = (if __targetPackages == null then self else __targetPackages) 100 76 // { recurseForDerivations = false; }; 101 - inherit stdenv 102 - buildPlatform hostPlatform targetPlatform; 77 + inherit stdenv; 103 78 }; 104 79 105 80 # The old identifiers for cross-compiling. These should eventually be removed, 106 81 # and the packages that rely on them refactored accordingly. 107 82 platformCompat = self: super: let 108 - # TODO(@Ericson2314) this causes infinite recursion 109 - #inherit (self) buildPlatform hostPlatform targetPlatform; 83 + inherit (super.stdenv) buildPlatform hostPlatform targetPlatform; 110 84 in { 111 85 stdenv = super.stdenv // { 112 - inherit (buildPlatform) platform; 86 + inherit (super.stdenv.buildPlatform) platform; 113 87 }; 88 + inherit buildPlatform hostPlatform targetPlatform; 114 89 inherit (buildPlatform) system platform; 115 90 }; 116 91