diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 935e6fb6267..e6576e5a389 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -10,7 +10,6 @@ , zlib ? null, extraPackages ? [], extraBuildCommands ? "" , dyld ? null # TODO: should this be a setup-hook on dyld? , isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null -, hostPlatform, targetPlatform , runCommand ? null }: @@ -22,12 +21,14 @@ assert !nativeTools -> assert !(nativeLibc && noLibc); assert (noLibc || nativeLibc) == (libc == null); -assert targetPlatform != hostPlatform -> runCommand != null; +assert stdenv.targetPlatform != stdenv.hostPlatform -> runCommand != null; # For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper. assert cc.langVhdl or false -> zlib != null; let + inherit (stdenv) hostPlatform targetPlatform; + # Prefix for binaries. Customarily ends with a dash separator. # # TODO(@Ericson2314) Make unconditional, or optional but always true by diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 7515a72fcfd..5848ee87b1b 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -61,11 +61,9 @@ rec { , buildPlatform, hostPlatform, targetPlatform } @ overrideArgs: let stdenv = overrideArgs.stdenv.override { - # TODO(@Ericson2314): Cannot do this for now because then Nix thinks the - # resulting derivation should be built on the host platform. - #hostPlatform = buildPlatform; - #targetPlatform = hostPlatform; - inherit cc; + inherit + buildPlatform hostPlatform targetPlatform + cc; allowedRequisites = null; diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index 125c4300975..c83714d01f2 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -14,21 +14,18 @@ in bootStages ++ [ # Build Packages (vanillaPackages: { - buildPlatform = localSystem; - hostPlatform = localSystem; - targetPlatform = crossSystem; inherit config overlays; selfBuild = false; + stdenv = + assert vanillaPackages.hostPlatform == localSystem; + assert vanillaPackages.targetPlatform == localSystem; + vanillaPackages.stdenv.override { targetPlatform = crossSystem; }; # It's OK to change the built-time dependencies allowCustomOverrides = true; - inherit (vanillaPackages) stdenv; }) # Run Packages (buildPackages: { - buildPlatform = localSystem; - hostPlatform = crossSystem; - targetPlatform = crossSystem; inherit config overlays; selfBuild = false; stdenv = buildPackages.makeStdenvCross { diff --git a/pkgs/stdenv/custom/default.nix b/pkgs/stdenv/custom/default.nix index d5dc977b37a..b6ea8685f8e 100644 --- a/pkgs/stdenv/custom/default.nix +++ b/pkgs/stdenv/custom/default.nix @@ -15,11 +15,11 @@ in bootStages ++ [ # Additional stage, built using custom stdenv (vanillaPackages: { - buildPlatform = localSystem; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit config overlays; - stdenv = config.replaceStdenv { pkgs = vanillaPackages; }; + stdenv = + assert vanillaPackages.hostPlatform == localSystem; + assert vanillaPackages.targetPlatform == localSystem; + config.replaceStdenv { pkgs = vanillaPackages; }; }) ] diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 03a815109c2..0e68b5c8e12 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -65,6 +65,10 @@ in rec { name = "stdenv-darwin-boot-${toString step}"; + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; + cc = if isNull last then "/dev/null" else import ../../build-support/cc-wrapper { inherit shell; inherit (last) stdenv; @@ -73,8 +77,6 @@ in rec { nativeTools = true; nativePrefix = bootstrapTools; nativeLibc = false; - hostPlatform = localSystem; - targetPlatform = localSystem; libc = last.pkgs.darwin.Libsystem; isClang = true; cc = { name = "clang-9.9.9"; outPath = bootstrapTools; }; @@ -90,9 +92,6 @@ in rec { ''; initialPath = [ bootstrapTools ]; - hostPlatform = localSystem; - targetPlatform = localSystem; - fetchurlBoot = import ../../build-support/fetchurl { stdenv = stage0.stdenv; curl = bootstrapTools; @@ -107,9 +106,6 @@ in rec { }; in { - buildPlatform = localSystem; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit config overlays; stdenv = thisStdenv; }; @@ -279,6 +275,10 @@ in rec { name = "stdenv-darwin"; + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; + preHook = commonPreHook + '' export PATH_LOCALE=${pkgs.darwin.locale}/share/locale ''; @@ -286,9 +286,6 @@ in rec { stdenvSandboxProfile = binShClosure + libSystemProfile; extraSandboxProfile = binShClosure + libSystemProfile; - hostPlatform = localSystem; - targetPlatform = localSystem; - initialPath = import ../common-path.nix { inherit pkgs; }; shell = "${pkgs.bash}/bin/bash"; @@ -297,8 +294,6 @@ in rec { inherit shell; nativeTools = false; nativeLibc = false; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit (pkgs) coreutils binutils gnugrep; inherit (pkgs.darwin) dyld; cc = pkgs.llvmPackages.clang-unwrapped; @@ -338,9 +333,6 @@ in rec { stage3 stage4 (prevStage: { - buildPlatform = localSystem; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit config overlays; stdenv = stdenvDarwin prevStage; }) diff --git a/pkgs/stdenv/freebsd/default.nix b/pkgs/stdenv/freebsd/default.nix index 389a5b9985f..d15afe76189 100644 --- a/pkgs/stdenv/freebsd/default.nix +++ b/pkgs/stdenv/freebsd/default.nix @@ -35,6 +35,9 @@ let inherit (localSystem) system; in stdenv = import ../generic { name = "stdenv-freebsd-boot-1"; + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; inherit config; initialPath = [ "/" "/usr" ]; hostPlatform = localSystem; @@ -52,6 +55,9 @@ let inherit (localSystem) system; in stdenv = import ../generic { name = "stdenv-freebsd-boot-0"; + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; inherit config; initialPath = [ prevStage.bootstrapTools ]; inherit (prevStage.stdenv) @@ -62,12 +68,12 @@ let inherit (localSystem) system; in }) (prevStage: { - buildPlatform = localSystem; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit config overlays; stdenv = import ../generic { name = "stdenv-freebsd-boot-3"; + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; inherit config; inherit (prevStage.stdenv) @@ -77,8 +83,6 @@ let inherit (localSystem) system; in nativeTools = true; nativePrefix = "/usr"; nativeLibc = true; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit (prevStage) stdenv; cc = { name = "clang-9.9.9"; diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index d7b736a12e5..a5d3c5a8ff5 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -15,18 +15,32 @@ let lib = import ../../../lib; in lib.makeOverridable ( , stdenvSandboxProfile ? "" , extraSandboxProfile ? "" -, # The platforms here do *not* correspond to the stage the stdenv is - # used in, but rather the previous one, in which it was built. We - # use the latter two platforms, like a cross compiler, because the - # stand environment is a build tool if you squint at it, and because - # neither of these are used when building stdenv so we know the - # build platform is irrelevant. - hostPlatform, targetPlatform + ## Platform parameters + ## + ## The "build" "host" "target" terminology below comes from GNU Autotools. See + ## its documentation for more information on what those words mean. Note that + ## each should always be defined, even when not cross compiling. + ## + ## For purposes of bootstrapping, think of each stage as a "sliding window" + ## over a list of platforms. Specifically, the host platform of the previous + ## stage becomes the build platform of the current one, and likewise the + ## target platform of the previous stage becomes the host platform of the + ## current one. + ## + +, # The platform on which packages are built. Consists of `system`, a + # string (e.g.,`i686-linux') identifying the most import attributes of the + # build platform, and `platform` a set of other details. + buildPlatform + +, # The platform on which packages run. + hostPlatform + +, # The platform which build tools (especially compilers) build for in this stage, + targetPlatform }: let - inherit (targetPlatform) system; - defaultNativeBuildInputs = extraBuildInputs ++ [ ../../build-support/setup-hooks/move-docs.sh ../../build-support/setup-hooks/compress-man-pages.sh @@ -49,7 +63,11 @@ let derivation ( (if isNull allowedRequisites then {} else { allowedRequisites = allowedRequisites ++ defaultNativeBuildInputs; }) // { - inherit system name; + inherit name; + + # Nix itself uses the `system` field of a derivation to decide where to + # build it. This is a bit confusing for cross compilation. + inherit (buildPlatform) system; builder = shell; @@ -59,7 +77,7 @@ let inherit preHook initialPath shell defaultNativeBuildInputs; } - // lib.optionalAttrs hostPlatform.isDarwin { + // lib.optionalAttrs buildPlatform.isDarwin { __sandboxProfile = stdenvSandboxProfile; __impureHostDeps = __stdenvImpureHostDeps; }) @@ -71,6 +89,8 @@ let platforms = lib.platforms.all; }; + inherit buildPlatform hostPlatform targetPlatform; + inherit extraBuildInputs __extraImpureHostDeps extraSandboxProfile; # Utility flags to test the type of platform. @@ -85,9 +105,6 @@ let inherit (import ./make-derivation.nix { inherit lib config stdenv; - # TODO(@Ericson2314): Remove - inherit - hostPlatform targetPlatform; }) mkDerivation; # For convenience, bring in the library functions in lib/ so diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index ec48e537413..31b0428eeb2 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -1,8 +1,4 @@ -{ lib, config, stdenv - -# TODO(@Ericson2314): get off stdenv -, hostPlatform, targetPlatform -}: +{ lib, config, stdenv }: rec { # `mkDerivation` wraps the builtin `derivation` function to @@ -49,12 +45,12 @@ rec { outputs' = outputs ++ - (if separateDebugInfo then assert targetPlatform.isLinux; [ "debug" ] else []); + (if separateDebugInfo then assert stdenv.hostPlatform.isLinux; [ "debug" ] else []); dependencies' = let justMap = map lib.chooseDevOutputs dependencies; nativeBuildInputs = lib.elemAt justMap 0 - ++ lib.optional targetPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh; + ++ lib.optional stdenv.hostPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh; buildInputs = lib.elemAt justMap 1 # TODO(@Ericson2314): Should instead also be appended to `nativeBuildInputs`. ++ lib.optional separateDebugInfo ../../build-support/setup-hooks/separate-debug-info.sh; @@ -82,7 +78,7 @@ rec { builder = attrs.realBuilder or stdenv.shell; args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; inherit stdenv; - system = stdenv.system; # TODO(@Ericson2314): be correct about cross compilation + inherit (stdenv) system; userHook = config.stdenv.userHook or null; __ignoreNulls = true; @@ -91,7 +87,7 @@ rec { propagatedNativeBuildInputs = lib.elemAt propagatedDependencies' 0; propagatedBuildInputs = lib.elemAt propagatedDependencies' 1; - } // lib.optionalAttrs (hostPlatform.isDarwin) { + } // lib.optionalAttrs (stdenv.buildPlatform.isDarwin) { # TODO: remove lib.unique once nix has a list canonicalization primitive __sandboxProfile = let profiles = [ stdenv.extraSandboxProfile ] ++ computedSandboxProfile ++ computedPropagatedSandboxProfile ++ [ propagatedSandboxProfile sandboxProfile ]; @@ -139,7 +135,9 @@ rec { { inherit lib config meta derivationArg; mkDerivationArg = attrs; - inherit (stdenv) system; # TODO: cross-compilation? + # Nix itself uses the `system` field of a derivation to decide where + # to build it. This is a bit confusing for cross compilation. + inherit (stdenv) system; })) ( { overrideAttrs = f: mkDerivation (attrs // (f attrs)); diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index b116a48a2bd..a27aca771ab 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -52,8 +52,11 @@ let let thisStdenv = import ../generic { - inherit config extraBuildInputs; name = "stdenv-linux-boot"; + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; + inherit config extraBuildInputs; preHook = '' # Don't patch #!/interpreter because it leads to retained @@ -64,9 +67,6 @@ let shell = "${bootstrapTools}/bin/bash"; initialPath = [bootstrapTools]; - hostPlatform = localSystem; - targetPlatform = localSystem; - fetchurlBoot = import ../../build-support/fetchurl/boot.nix { inherit system; }; @@ -76,8 +76,6 @@ let else lib.makeOverridable (import ../../build-support/cc-wrapper) { nativeTools = false; nativeLibc = false; - hostPlatform = localSystem; - targetPlatform = localSystem; cc = prevStage.gcc-unwrapped; isGNU = true; libc = prevStage.glibc; @@ -99,9 +97,6 @@ let }; in { - buildPlatform = localSystem; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit config overlays; stdenv = thisStdenv; }; @@ -241,8 +236,6 @@ in nativeTools = false; nativeLibc = false; isGNU = true; - hostPlatform = localSystem; - targetPlatform = localSystem; cc = prevStage.gcc-unwrapped; libc = self.glibc; inherit (self) stdenv binutils coreutils gnugrep; @@ -263,11 +256,11 @@ in # dependency (`nix-store -qR') on bootstrapTools or the first # binutils built. (prevStage: { - buildPlatform = localSystem; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit config overlays; stdenv = import ../generic rec { + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; inherit config; preHook = '' @@ -280,9 +273,6 @@ in initialPath = ((import ../common-path.nix) {pkgs = prevStage;}); - hostPlatform = localSystem; - targetPlatform = localSystem; - extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++ # Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64. lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook; diff --git a/pkgs/stdenv/native/default.nix b/pkgs/stdenv/native/default.nix index 31973c2cdc5..02734f2f3e5 100644 --- a/pkgs/stdenv/native/default.nix +++ b/pkgs/stdenv/native/default.nix @@ -81,6 +81,7 @@ let { cc, fetchurl, extraPath ? [], overrides ? (self: super: { }) }: import ../generic { + buildPlatform = localSystem; hostPlatform = localSystem; targetPlatform = localSystem; @@ -125,8 +126,6 @@ in "i686-solaris" = "/usr/gnu"; "x86_64-solaris" = "/opt/local/gcc47"; }.${system} or "/usr"; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit stdenv; }; @@ -140,9 +139,6 @@ in # First build a stdenv based only on tools outside the store. (prevStage: { - buildPlatform = localSystem; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit config overlays; stdenv = makeStdenv { inherit (prevStage) cc fetchurl; @@ -152,9 +148,6 @@ in # Using that, build a stdenv that adds the ‘xz’ command (which most systems # don't have, so we mustn't rely on the native environment providing it). (prevStage: { - buildPlatform = localSystem; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit config overlays; stdenv = makeStdenv { inherit (prevStage.stdenv) cc fetchurl; diff --git a/pkgs/stdenv/nix/default.nix b/pkgs/stdenv/nix/default.nix index 7ab797ce91b..aaf6c523ea4 100644 --- a/pkgs/stdenv/nix/default.nix +++ b/pkgs/stdenv/nix/default.nix @@ -10,10 +10,13 @@ bootStages ++ [ (prevStage: let inherit (prevStage) stdenv; in { - inherit (prevStage) buildPlatform hostPlatform targetPlatform; inherit config overlays; stdenv = import ../generic rec { + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; + inherit config; preHook = '' @@ -30,8 +33,6 @@ bootStages ++ [ nativeTools = false; nativePrefix = stdenv.lib.optionalString hostPlatform.isSunOS "/usr"; nativeLibc = true; - hostPlatform = localSystem; - targetPlatform = localSystem; inherit stdenv; inherit (prevStage) binutils coreutils gnugrep; cc = prevStage.gcc.cc; diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix index 2a8f4ff4b3c..617fa0c30ce 100644 --- a/pkgs/top-level/stage.nix +++ b/pkgs/top-level/stage.nix @@ -18,30 +18,6 @@ , # Use to reevaluate Nixpkgs; a dirty hack that should be removed nixpkgsFun - ## Platform parameters - ## - ## The "build" "host" "target" terminology below comes from GNU Autotools. See - ## its documentation for more information on what those words mean. Note that - ## each should always be defined, even when not cross compiling. - ## - ## For purposes of bootstrapping, think of each stage as a "sliding window" - ## over a list of platforms. Specifically, the host platform of the previous - ## stage becomes the build platform of the current one, and likewise the - ## target platform of the previous stage becomes the host platform of the - ## current one. - ## - -, # The platform on which packages are built. Consists of `system`, a - # string (e.g.,`i686-linux') identifying the most import attributes of the - # build platform, and `platform` a set of other details. - buildPlatform - -, # The platform on which packages run. - hostPlatform - -, # The platform which build tools (especially compilers) build for in this stage, - targetPlatform - ## Other parameters ## @@ -69,10 +45,10 @@ , # Non-GNU/Linux OSes are currently "impure" platforms, with their libc # outside of the store. Thus, GCC, GFortran, & co. must always look for files # in standard system directories (/usr/include, etc.) - noSysDirs ? buildPlatform.system != "x86_64-freebsd" - && buildPlatform.system != "i686-freebsd" - && buildPlatform.system != "x86_64-solaris" - && buildPlatform.system != "x86_64-kfreebsd-gnu" + noSysDirs ? stdenv.buildPlatform.system != "x86_64-freebsd" + && stdenv.buildPlatform.system != "i686-freebsd" + && stdenv.buildPlatform.system != "x86_64-solaris" + && stdenv.buildPlatform.system != "x86_64-kfreebsd-gnu" , # The configuration attribute set config @@ -98,19 +74,18 @@ let // { recurseForDerivations = false; }; __targetPackages = (if __targetPackages == null then self else __targetPackages) // { recurseForDerivations = false; }; - inherit stdenv - buildPlatform hostPlatform targetPlatform; + inherit stdenv; }; # The old identifiers for cross-compiling. These should eventually be removed, # and the packages that rely on them refactored accordingly. platformCompat = self: super: let - # TODO(@Ericson2314) this causes infinite recursion - #inherit (self) buildPlatform hostPlatform targetPlatform; + inherit (super.stdenv) buildPlatform hostPlatform targetPlatform; in { stdenv = super.stdenv // { - inherit (buildPlatform) platform; + inherit (super.stdenv.buildPlatform) platform; }; + inherit buildPlatform hostPlatform targetPlatform; inherit (buildPlatform) system platform; };