Merge pull request #27179 from obsidiansystems/platforms-from-stdenv

Define {build,host,target}Platform in stdenv

authored by John Ericson and committed by GitHub 89fcb633 3abfc161

+243 -264
+3 -2
doc/cross-compilation.xml
··· 37 37 </para> 38 38 <para> 39 39 In Nixpkgs, these three platforms are defined as attribute sets under the names <literal>buildPlatform</literal>, <literal>hostPlatform</literal>, and <literal>targetPlatform</literal>. 40 - All three are always defined at the top level, so one can get at them just like a dependency in a function that is imported with <literal>callPackage</literal>: 41 - <programlisting>{ stdenv, buildPlatform, hostPlatform, fooDep, barDep, .. }: ...</programlisting> 40 + All three are always defined as attributes in the standard environment, and at the top level. That means one can get at them just like a dependency in a function that is imported with <literal>callPackage</literal>: 41 + <programlisting>{ stdenv, buildPlatform, hostPlatform, fooDep, barDep, .. }: ...buildPlatform...</programlisting>, or just off <varname>stdenv</varname>: 42 + <programlisting>{ stdenv, fooDep, barDep, .. }: ...stdenv.buildPlatform...</programlisting>. 42 43 </para> 43 44 <variablelist> 44 45 <varlistentry>
+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";
+39 -162
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 - ifDarwin = attrs: if system == "x86_64-darwin" then attrs else {}; 31 - 32 44 defaultNativeBuildInputs = extraBuildInputs ++ 33 45 [ ../../build-support/setup-hooks/move-docs.sh 34 46 ../../build-support/setup-hooks/compress-man-pages.sh ··· 37 49 ] 38 50 # FIXME this on Darwin; see 39 51 # https://github.com/NixOS/nixpkgs/commit/94d164dd7#commitcomment-22030369 40 - ++ lib.optional result.isLinux ../../build-support/setup-hooks/audit-tmpdir.sh 52 + ++ lib.optional hostPlatform.isLinux ../../build-support/setup-hooks/audit-tmpdir.sh 41 53 ++ [ 42 54 ../../build-support/setup-hooks/multiple-outputs.sh 43 55 ../../build-support/setup-hooks/move-sbin.sh ··· 46 58 cc 47 59 ]; 48 60 49 - # `mkDerivation` wraps the builtin `derivation` function to 50 - # produce derivations that use this stdenv and its shell. 51 - # 52 - # See also: 53 - # 54 - # * https://nixos.org/nixpkgs/manual/#sec-using-stdenv 55 - # Details on how to use this mkDerivation function 56 - # 57 - # * https://nixos.org/nix/manual/#ssec-derivation 58 - # Explanation about derivations in general 59 - mkDerivation = 60 - { nativeBuildInputs ? [] 61 - , buildInputs ? [] 62 - 63 - , propagatedNativeBuildInputs ? [] 64 - , propagatedBuildInputs ? [] 65 - 66 - , crossConfig ? null 67 - , meta ? {} 68 - , passthru ? {} 69 - , pos ? # position used in error messages and for meta.position 70 - (if attrs.meta.description or null != null 71 - then builtins.unsafeGetAttrPos "description" attrs.meta 72 - else builtins.unsafeGetAttrPos "name" attrs) 73 - , separateDebugInfo ? false 74 - , outputs ? [ "out" ] 75 - , __impureHostDeps ? [] 76 - , __propagatedImpureHostDeps ? [] 77 - , sandboxProfile ? "" 78 - , propagatedSandboxProfile ? "" 79 - , ... } @ attrs: 80 - let 81 - dependencies = [ 82 - (map (drv: drv.nativeDrv or drv) nativeBuildInputs) 83 - (map (drv: drv.crossDrv or drv) buildInputs) 84 - ]; 85 - propagatedDependencies = [ 86 - (map (drv: drv.nativeDrv or drv) propagatedNativeBuildInputs) 87 - (map (drv: drv.crossDrv or drv) propagatedBuildInputs) 88 - ]; 89 - in let 90 - 91 - outputs' = 92 - outputs ++ 93 - (if separateDebugInfo then assert targetPlatform.isLinux; [ "debug" ] else []); 94 - 95 - dependencies' = let 96 - justMap = map lib.chooseDevOutputs dependencies; 97 - nativeBuildInputs = lib.elemAt justMap 0 98 - ++ lib.optional targetPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh; 99 - buildInputs = lib.elemAt justMap 1 100 - # TODO(@Ericson2314): Should instead also be appended to `nativeBuildInputs`. 101 - ++ lib.optional separateDebugInfo ../../build-support/setup-hooks/separate-debug-info.sh; 102 - in [ nativeBuildInputs buildInputs ]; 103 - 104 - propagatedDependencies' = map lib.chooseDevOutputs propagatedDependencies; 105 - 106 - derivationArg = 107 - (removeAttrs attrs 108 - ["meta" "passthru" "crossAttrs" "pos" 109 - "__impureHostDeps" "__propagatedImpureHostDeps" 110 - "sandboxProfile" "propagatedSandboxProfile"]) 111 - // (let 112 - # TODO(@Ericson2314): Reversing of dep lists is just temporary to avoid Darwin mass rebuild. 113 - computedSandboxProfile = 114 - lib.concatMap (input: input.__propagatedSandboxProfile or []) (extraBuildInputs ++ lib.concatLists (lib.reverseList dependencies')); 115 - computedPropagatedSandboxProfile = 116 - lib.concatMap (input: input.__propagatedSandboxProfile or []) (lib.concatLists (lib.reverseList propagatedDependencies')); 117 - computedImpureHostDeps = 118 - lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (extraBuildInputs ++ lib.concatLists (lib.reverseList dependencies'))); 119 - computedPropagatedImpureHostDeps = 120 - lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (lib.concatLists (lib.reverseList propagatedDependencies'))); 121 - in 122 - { 123 - builder = attrs.realBuilder or shell; 124 - args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; 125 - stdenv = result; 126 - system = result.system; 127 - userHook = config.stdenv.userHook or null; 128 - __ignoreNulls = true; 129 - 130 - nativeBuildInputs = lib.elemAt dependencies' 0; 131 - buildInputs = lib.elemAt dependencies' 1; 132 - 133 - propagatedNativeBuildInputs = lib.elemAt propagatedDependencies' 0; 134 - propagatedBuildInputs = lib.elemAt propagatedDependencies' 1; 135 - } // ifDarwin { 136 - # TODO: remove lib.unique once nix has a list canonicalization primitive 137 - __sandboxProfile = 138 - let profiles = [ extraSandboxProfile ] ++ computedSandboxProfile ++ computedPropagatedSandboxProfile ++ [ propagatedSandboxProfile sandboxProfile ]; 139 - final = lib.concatStringsSep "\n" (lib.filter (x: x != "") (lib.unique profiles)); 140 - in final; 141 - __propagatedSandboxProfile = lib.unique (computedPropagatedSandboxProfile ++ [ propagatedSandboxProfile ]); 142 - __impureHostDeps = computedImpureHostDeps ++ computedPropagatedImpureHostDeps ++ __propagatedImpureHostDeps ++ __impureHostDeps ++ __extraImpureHostDeps ++ [ 143 - "/dev/zero" 144 - "/dev/random" 145 - "/dev/urandom" 146 - "/bin/sh" 147 - ]; 148 - __propagatedImpureHostDeps = computedPropagatedImpureHostDeps ++ __propagatedImpureHostDeps; 149 - } // (if outputs' != [ "out" ] then { 150 - outputs = outputs'; 151 - } else { })); 152 - 153 - # The meta attribute is passed in the resulting attribute set, 154 - # but it's not part of the actual derivation, i.e., it's not 155 - # passed to the builder and is not a dependency. But since we 156 - # include it in the result, it *is* available to nix-env for queries. 157 - meta = { } 158 - # If the packager hasn't specified `outputsToInstall`, choose a default, 159 - # which is the name of `p.bin or p.out or p`; 160 - # if he has specified it, it will be overridden below in `// meta`. 161 - # Note: This default probably shouldn't be globally configurable. 162 - # Services and users should specify outputs explicitly, 163 - # unless they are comfortable with this default. 164 - // { outputsToInstall = 165 - let 166 - outs = outputs'; # the value passed to derivation primitive 167 - hasOutput = out: builtins.elem out outs; 168 - in [( lib.findFirst hasOutput null (["bin" "out"] ++ outs) )]; 169 - } 170 - // attrs.meta or {} 171 - # Fill `meta.position` to identify the source location of the package. 172 - // lib.optionalAttrs (pos != null) 173 - { position = pos.file + ":" + toString pos.line; } 174 - ; 175 - 176 - in 177 - 178 - lib.addPassthru 179 - (derivation (import ./check-meta.nix 180 - { 181 - inherit lib config meta derivationArg; 182 - mkDerivationArg = attrs; 183 - inherit system; # TODO: cross-compilation? 184 - })) 185 - ( { 186 - overrideAttrs = f: mkDerivation (attrs // (f attrs)); 187 - inherit meta passthru; 188 - } // 189 - # Pass through extra attributes that are not inputs, but 190 - # should be made available to Nix expressions using the 191 - # derivation (e.g., in assertions). 192 - passthru); 193 - 194 61 # The stdenv that we are producing. 195 - result = 62 + stdenv = 196 63 derivation ( 197 64 (if isNull allowedRequisites then {} else { allowedRequisites = allowedRequisites ++ defaultNativeBuildInputs; }) // 198 65 { 199 - 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; 200 71 201 72 builder = shell; 202 73 ··· 206 77 207 78 inherit preHook initialPath shell defaultNativeBuildInputs; 208 79 } 209 - // ifDarwin { 80 + // lib.optionalAttrs buildPlatform.isDarwin { 210 81 __sandboxProfile = stdenvSandboxProfile; 211 82 __impureHostDeps = __stdenvImpureHostDeps; 212 83 }) ··· 217 88 description = "The default build environment for Unix packages in Nixpkgs"; 218 89 platforms = lib.platforms.all; 219 90 }; 91 + 92 + inherit buildPlatform hostPlatform targetPlatform; 93 + 94 + inherit extraBuildInputs __extraImpureHostDeps extraSandboxProfile; 220 95 221 96 # Utility flags to test the type of platform. 222 97 inherit (hostPlatform) ··· 228 103 # Whether we should run paxctl to pax-mark binaries. 229 104 needsPax = isLinux; 230 105 231 - inherit mkDerivation; 106 + inherit (import ./make-derivation.nix { 107 + inherit lib config stdenv; 108 + }) mkDerivation; 232 109 233 110 # For convenience, bring in the library functions in lib/ so 234 111 # packages don't have to do that themselves. ··· 247 124 # like curl = if stdenv ? curl then stdenv.curl else ...). 248 125 // extraAttrs; 249 126 250 - in result) 127 + in stdenv)
+150
pkgs/stdenv/generic/make-derivation.nix
··· 1 + { lib, config, stdenv }: 2 + 3 + rec { 4 + # `mkDerivation` wraps the builtin `derivation` function to 5 + # produce derivations that use this stdenv and its shell. 6 + # 7 + # See also: 8 + # 9 + # * https://nixos.org/nixpkgs/manual/#sec-using-stdenv 10 + # Details on how to use this mkDerivation function 11 + # 12 + # * https://nixos.org/nix/manual/#ssec-derivation 13 + # Explanation about derivations in general 14 + mkDerivation = 15 + { nativeBuildInputs ? [] 16 + , buildInputs ? [] 17 + 18 + , propagatedNativeBuildInputs ? [] 19 + , propagatedBuildInputs ? [] 20 + 21 + , crossConfig ? null 22 + , meta ? {} 23 + , passthru ? {} 24 + , pos ? # position used in error messages and for meta.position 25 + (if attrs.meta.description or null != null 26 + then builtins.unsafeGetAttrPos "description" attrs.meta 27 + else builtins.unsafeGetAttrPos "name" attrs) 28 + , separateDebugInfo ? false 29 + , outputs ? [ "out" ] 30 + , __impureHostDeps ? [] 31 + , __propagatedImpureHostDeps ? [] 32 + , sandboxProfile ? "" 33 + , propagatedSandboxProfile ? "" 34 + , ... } @ attrs: 35 + let 36 + dependencies = [ 37 + (map (drv: drv.nativeDrv or drv) nativeBuildInputs) 38 + (map (drv: drv.crossDrv or drv) buildInputs) 39 + ]; 40 + propagatedDependencies = [ 41 + (map (drv: drv.nativeDrv or drv) propagatedNativeBuildInputs) 42 + (map (drv: drv.crossDrv or drv) propagatedBuildInputs) 43 + ]; 44 + in let 45 + 46 + outputs' = 47 + outputs ++ 48 + (if separateDebugInfo then assert stdenv.hostPlatform.isLinux; [ "debug" ] else []); 49 + 50 + dependencies' = let 51 + justMap = map lib.chooseDevOutputs dependencies; 52 + nativeBuildInputs = lib.elemAt justMap 0 53 + ++ lib.optional stdenv.hostPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh; 54 + buildInputs = lib.elemAt justMap 1 55 + # TODO(@Ericson2314): Should instead also be appended to `nativeBuildInputs`. 56 + ++ lib.optional separateDebugInfo ../../build-support/setup-hooks/separate-debug-info.sh; 57 + in [ nativeBuildInputs buildInputs ]; 58 + 59 + propagatedDependencies' = map lib.chooseDevOutputs propagatedDependencies; 60 + 61 + derivationArg = 62 + (removeAttrs attrs 63 + ["meta" "passthru" "crossAttrs" "pos" 64 + "__impureHostDeps" "__propagatedImpureHostDeps" 65 + "sandboxProfile" "propagatedSandboxProfile"]) 66 + // (let 67 + # TODO(@Ericson2314): Reversing of dep lists is just temporary to avoid Darwin mass rebuild. 68 + computedSandboxProfile = 69 + lib.concatMap (input: input.__propagatedSandboxProfile or []) (stdenv.extraBuildInputs ++ lib.concatLists (lib.reverseList dependencies')); 70 + computedPropagatedSandboxProfile = 71 + lib.concatMap (input: input.__propagatedSandboxProfile or []) (lib.concatLists (lib.reverseList propagatedDependencies')); 72 + computedImpureHostDeps = 73 + lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (stdenv.extraBuildInputs ++ lib.concatLists (lib.reverseList dependencies'))); 74 + computedPropagatedImpureHostDeps = 75 + lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (lib.concatLists (lib.reverseList propagatedDependencies'))); 76 + in 77 + { 78 + builder = attrs.realBuilder or stdenv.shell; 79 + args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; 80 + inherit stdenv; 81 + inherit (stdenv) system; 82 + userHook = config.stdenv.userHook or null; 83 + __ignoreNulls = true; 84 + 85 + nativeBuildInputs = lib.elemAt dependencies' 0; 86 + buildInputs = lib.elemAt dependencies' 1; 87 + 88 + propagatedNativeBuildInputs = lib.elemAt propagatedDependencies' 0; 89 + propagatedBuildInputs = lib.elemAt propagatedDependencies' 1; 90 + } // lib.optionalAttrs (stdenv.buildPlatform.isDarwin) { 91 + # TODO: remove lib.unique once nix has a list canonicalization primitive 92 + __sandboxProfile = 93 + let profiles = [ stdenv.extraSandboxProfile ] ++ computedSandboxProfile ++ computedPropagatedSandboxProfile ++ [ propagatedSandboxProfile sandboxProfile ]; 94 + final = lib.concatStringsSep "\n" (lib.filter (x: x != "") (lib.unique profiles)); 95 + in final; 96 + __propagatedSandboxProfile = lib.unique (computedPropagatedSandboxProfile ++ [ propagatedSandboxProfile ]); 97 + __impureHostDeps = computedImpureHostDeps ++ computedPropagatedImpureHostDeps ++ __propagatedImpureHostDeps ++ __impureHostDeps ++ stdenv.__extraImpureHostDeps ++ [ 98 + "/dev/zero" 99 + "/dev/random" 100 + "/dev/urandom" 101 + "/bin/sh" 102 + ]; 103 + __propagatedImpureHostDeps = computedPropagatedImpureHostDeps ++ __propagatedImpureHostDeps; 104 + } // (if outputs' != [ "out" ] then { 105 + outputs = outputs'; 106 + } else { })); 107 + 108 + # The meta attribute is passed in the resulting attribute set, 109 + # but it's not part of the actual derivation, i.e., it's not 110 + # passed to the builder and is not a dependency. But since we 111 + # include it in the result, it *is* available to nix-env for queries. 112 + meta = { } 113 + # If the packager hasn't specified `outputsToInstall`, choose a default, 114 + # which is the name of `p.bin or p.out or p`; 115 + # if he has specified it, it will be overridden below in `// meta`. 116 + # Note: This default probably shouldn't be globally configurable. 117 + # Services and users should specify outputs explicitly, 118 + # unless they are comfortable with this default. 119 + // { outputsToInstall = 120 + let 121 + outs = outputs'; # the value passed to derivation primitive 122 + hasOutput = out: builtins.elem out outs; 123 + in [( lib.findFirst hasOutput null (["bin" "out"] ++ outs) )]; 124 + } 125 + // attrs.meta or {} 126 + # Fill `meta.position` to identify the source location of the package. 127 + // lib.optionalAttrs (pos != null) 128 + { position = pos.file + ":" + toString pos.line; } 129 + ; 130 + 131 + in 132 + 133 + lib.addPassthru 134 + (derivation (import ./check-meta.nix 135 + { 136 + inherit lib config meta derivationArg; 137 + mkDerivationArg = attrs; 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; 141 + })) 142 + ( { 143 + overrideAttrs = f: mkDerivation (attrs // (f attrs)); 144 + inherit meta passthru; 145 + } // 146 + # Pass through extra attributes that are not inputs, but 147 + # should be made available to Nix expressions using the 148 + # derivation (e.g., in assertions). 149 + passthru); 150 + }
+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