···37 </para>
38 <para>
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>
042 </para>
43 <variablelist>
44 <varlistentry>
···37 </para>
38 <para>
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 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>.
43 </para>
44 <variablelist>
45 <varlistentry>
+3-2
pkgs/build-support/cc-wrapper/default.nix
···10, zlib ? null, extraPackages ? [], extraBuildCommands ? ""
11, dyld ? null # TODO: should this be a setup-hook on dyld?
12, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
13-, hostPlatform, targetPlatform
14, runCommand ? null
15}:
16···22assert !(nativeLibc && noLibc);
23assert (noLibc || nativeLibc) == (libc == null);
2425-assert targetPlatform != hostPlatform -> runCommand != null;
2627# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper.
28assert cc.langVhdl or false -> zlib != null;
2930let
0031 # Prefix for binaries. Customarily ends with a dash separator.
32 #
33 # TODO(@Ericson2314) Make unconditional, or optional but always true by
···10, zlib ? null, extraPackages ? [], extraBuildCommands ? ""
11, dyld ? null # TODO: should this be a setup-hook on dyld?
12, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
013, runCommand ? null
14}:
15···21assert !(nativeLibc && noLibc);
22assert (noLibc || nativeLibc) == (libc == null);
2324+assert stdenv.targetPlatform != stdenv.hostPlatform -> runCommand != null;
2526# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper.
27assert cc.langVhdl or false -> zlib != null;
2829let
30+ inherit (stdenv) hostPlatform targetPlatform;
31+32 # Prefix for binaries. Customarily ends with a dash separator.
33 #
34 # TODO(@Ericson2314) Make unconditional, or optional but always true by
+3-5
pkgs/stdenv/adapters.nix
···61 , buildPlatform, hostPlatform, targetPlatform
62 } @ overrideArgs: let
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;
6970 allowedRequisites = null;
71
···15, stdenvSandboxProfile ? ""
16, extraSandboxProfile ? ""
1718-, # 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
000000000000000025}:
2627let
28- inherit (targetPlatform) system;
29-30- ifDarwin = attrs: if system == "x86_64-darwin" then attrs else {};
31-32 defaultNativeBuildInputs = extraBuildInputs ++
33 [ ../../build-support/setup-hooks/move-docs.sh
34 ../../build-support/setup-hooks/compress-man-pages.sh
···37 ]
38 # FIXME this on Darwin; see
39 # https://github.com/NixOS/nixpkgs/commit/94d164dd7#commitcomment-22030369
40- ++ lib.optional result.isLinux ../../build-support/setup-hooks/audit-tmpdir.sh
41 ++ [
42 ../../build-support/setup-hooks/multiple-outputs.sh
43 ../../build-support/setup-hooks/move-sbin.sh
···46 cc
47 ];
4849- # `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 # The stdenv that we are producing.
195- result =
196 derivation (
197 (if isNull allowedRequisites then {} else { allowedRequisites = allowedRequisites ++ defaultNativeBuildInputs; }) //
198 {
199- inherit system name;
0000200201 builder = shell;
202···206207 inherit preHook initialPath shell defaultNativeBuildInputs;
208 }
209- // ifDarwin {
210 __sandboxProfile = stdenvSandboxProfile;
211 __impureHostDeps = __stdenvImpureHostDeps;
212 })
···217 description = "The default build environment for Unix packages in Nixpkgs";
218 platforms = lib.platforms.all;
219 };
0000220221 # Utility flags to test the type of platform.
222 inherit (hostPlatform)
···228 # Whether we should run paxctl to pax-mark binaries.
229 needsPax = isLinux;
230231- inherit mkDerivation;
00232233 # For convenience, bring in the library functions in lib/ so
234 # packages don't have to do that themselves.
···247 # like curl = if stdenv ? curl then stdenv.curl else ...).
248 // extraAttrs;
249250-in result)
···15, stdenvSandboxProfile ? ""
16, extraSandboxProfile ? ""
1718+ ## 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
41}:
4243let
000044 defaultNativeBuildInputs = extraBuildInputs ++
45 [ ../../build-support/setup-hooks/move-docs.sh
46 ../../build-support/setup-hooks/compress-man-pages.sh
···49 ]
50 # FIXME this on Darwin; see
51 # https://github.com/NixOS/nixpkgs/commit/94d164dd7#commitcomment-22030369
52+ ++ lib.optional hostPlatform.isLinux ../../build-support/setup-hooks/audit-tmpdir.sh
53 ++ [
54 ../../build-support/setup-hooks/multiple-outputs.sh
55 ../../build-support/setup-hooks/move-sbin.sh
···58 cc
59 ];
60000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000061 # The stdenv that we are producing.
62+ stdenv =
63 derivation (
64 (if isNull allowedRequisites then {} else { allowedRequisites = allowedRequisites ++ defaultNativeBuildInputs; }) //
65 {
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;
7172 builder = shell;
73···7778 inherit preHook initialPath shell defaultNativeBuildInputs;
79 }
80+ // lib.optionalAttrs buildPlatform.isDarwin {
81 __sandboxProfile = stdenvSandboxProfile;
82 __impureHostDeps = __stdenvImpureHostDeps;
83 })
···88 description = "The default build environment for Unix packages in Nixpkgs";
89 platforms = lib.platforms.all;
90 };
91+92+ inherit buildPlatform hostPlatform targetPlatform;
93+94+ inherit extraBuildInputs __extraImpureHostDeps extraSandboxProfile;
9596 # Utility flags to test the type of platform.
97 inherit (hostPlatform)
···103 # Whether we should run paxctl to pax-mark binaries.
104 needsPax = isLinux;
105106+ inherit (import ./make-derivation.nix {
107+ inherit lib config stdenv;
108+ }) mkDerivation;
109110 # For convenience, bring in the library functions in lib/ so
111 # packages don't have to do that themselves.
···124 # like curl = if stdenv ? curl then stdenv.curl else ...).
125 // extraAttrs;
126127+in stdenv)
···18, # Use to reevaluate Nixpkgs; a dirty hack that should be removed
19 nixpkgsFun
2021- ## 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 ## Other parameters
46 ##
47···69, # Non-GNU/Linux OSes are currently "impure" platforms, with their libc
70 # outside of the store. Thus, GCC, GFortran, & co. must always look for files
71 # 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"
7677, # The configuration attribute set
78 config
···98 // { recurseForDerivations = false; };
99 __targetPackages = (if __targetPackages == null then self else __targetPackages)
100 // { recurseForDerivations = false; };
101- inherit stdenv
102- buildPlatform hostPlatform targetPlatform;
103 };
104105 # The old identifiers for cross-compiling. These should eventually be removed,
106 # and the packages that rely on them refactored accordingly.
107 platformCompat = self: super: let
108- # TODO(@Ericson2314) this causes infinite recursion
109- #inherit (self) buildPlatform hostPlatform targetPlatform;
110 in {
111 stdenv = super.stdenv // {
112- inherit (buildPlatform) platform;
113 };
0114 inherit (buildPlatform) system platform;
115 };
116
···18, # Use to reevaluate Nixpkgs; a dirty hack that should be removed
19 nixpkgsFun
2000000000000000000000000021 ## Other parameters
22 ##
23···45, # Non-GNU/Linux OSes are currently "impure" platforms, with their libc
46 # outside of the store. Thus, GCC, GFortran, & co. must always look for files
47 # in standard system directories (/usr/include, etc.)
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"
5253, # The configuration attribute set
54 config
···74 // { recurseForDerivations = false; };
75 __targetPackages = (if __targetPackages == null then self else __targetPackages)
76 // { recurseForDerivations = false; };
77+ inherit stdenv;
078 };
7980 # The old identifiers for cross-compiling. These should eventually be removed,
81 # and the packages that rely on them refactored accordingly.
82 platformCompat = self: super: let
83+ inherit (super.stdenv) buildPlatform hostPlatform targetPlatform;
084 in {
85 stdenv = super.stdenv // {
86+ inherit (super.stdenv.buildPlatform) platform;
87 };
88+ inherit buildPlatform hostPlatform targetPlatform;
89 inherit (buildPlatform) system platform;
90 };
91