git.iko.soy/typeable/nixpkgs
on master help sign in
top-level: Allow nixpkgs to take localSystem directly

This is instead of both system and platform, which is kind of ugly.

commit8cd4c31d6b8c6432986edf0ec5d00d2fe1c12854 authorJohn Ericson <Ericson2314@Yahoo.com> dateWed 8 Feb 2017, 16:43 (10 years ago) parentcd10e3c
4 files changed+53−39
doc/cross-compilation.xml+17−3 pkgs/top-level/all-packages.nix+4−2 pkgs/top-level/default.nix+17−30 pkgs/top-level/impure.nix+15−4
doc/cross-compilation.xml+17−3
@@ -25,7 +25,7 @@
2525<!--============================================================-->
2626
2727<section xml:id="sec-cross-packaging">
28− <title>Packing in a cross-friendly manner</title>
28+ <title>Packaging in a cross-friendly manner</title>
2929
3030 <section>
3131 <title>Platform parameters</title>
@@ -132,9 +132,23 @@
132132
133133<section xml:id="sec-cross-usage">
134134 <title>Cross-building packages</title>
135+ <note><para>
136+ More information needs to moved from the old wiki, especially <link xlink:href="https://nixos.org/wiki/CrossCompiling" />, for this section.
137+ </para></note>
138+ <para>
139+ Many sources (manual, wiki, etc) probably mention passing <varname>system</varname>, <varname>platform</varname>, and, optionally, <varname>crossSystem</varname> to nixpkgs:
140+ <literal>import &lt;nixpkgs&gt; { system = ..; platform = ..; crossSystem = ..; }</literal>.
141+ <varname>system</varname> and <varname>platform</varname> together determine the system on which packages are built, and <varname>crossSystem</varname> specifies the platform on which packages are ultimately intended to run, if it is different.
142+ This still works, but with more recent changes, one can alternatively pass <varname>localSystem</varname>, containing <varname>system</varname> and <varname>platform</varname>, for symmetry.
143+ </para>
135144 <para>
136− To be written.
137− This is basically unchanged so see the old wiki for now.
145+ One would think that <varname>localSystem</varname> and <varname>crossSystem</varname> overlap horribly with the three <varname>*Platforms</varname> (<varname>buildPlatform</varname>, <varname>hostPlatform,</varname> and <varname>targetPlatform</varname>; see <varname>stage.nix</varname> or the manual).
146+ Actually, those identifiers are purposefully not used here to draw a subtle but important distinction:
147+ While the granularity of having 3 platforms is necessary to properly *build* packages, it is overkill for specifying the user's *intent* when making a build plan or package set.
148+ A simple "build vs deploy" dichotomy is adequate: the sliding window principle described in the previous section shows how to interpolate between the these two "end points" to get the 3 platform triple for each bootstrapping stage.
149+ That means for any package a given package set, even those not bound on the top level but only reachable via dependencies or <varname>buildPackages</varname>, the three platforms will be defined as one of <varname>localSystem</varname> or <varname>crossSystem</varname>, with the former replacing the latter as one traverses build-time dependencies.
150+ A last simple difference then is <varname>crossSystem</varname> should be null when one doesn't want to cross-compile, while the <varname>*Platform</varname>s are always non-null.
151+ <varname>localSystem</varname> is always non-null.
138152 </para>
139153</section>
140154
pkgs/top-level/all-packages.nix+4−2
@@ -18,8 +18,10 @@ with pkgs;
1818
1919 # Override system. This is useful to build i686 packages on x86_64-linux.
2020 forceSystem = system: kernel: nixpkgsFun {
21− inherit system;
22− platform = platform // { kernelArch = kernel; };
21+ localSystem = {
22+ inherit system;
23+ platform = platform // { kernelArch = kernel; };
24+ };
2325 };
2426
2527 # Used by wine, firefox with debugging version of Flash, ...
pkgs/top-level/default.nix+17−30
@@ -17,8 +17,14 @@
1717 evaluation is taking place, and the configuration from environment variables
1818 or dot-files. */
1919
20−{ # The system (e.g., `i686-linux') for which to build the packages.
21− system
20+{ # The system packages will be built on. See the manual for the
21+ # subtle division of labor between these two `*System`s and the three
22+ # `*Platform`s.
23+ localSystem
24+
25+ # The system packages will ultimately be run on. Null if the two should be the
26+ # same.
27+, crossSystem ? null
2228
2329, # Allow a configuration attribute set to be passed in as an argument.
2430 config ? {}
@@ -27,12 +33,9 @@
2733 overlays ? []
2834
2935, # A function booting the final package set for a specific standard
30− # environment. See below for the arguments given to that function,
31− # the type of list it returns.
36+ # environment. See below for the arguments given to that function, the type of
37+ # list it returns.
3238 stdenvStages ? import ../stdenv
33−
34−, crossSystem ? null
35−, platform ? assert false; null
3639} @ args:
3740
3841let # Rename the function arguments
@@ -51,10 +54,10 @@ in let
5154
5255 # Allow setting the platform in the config file. Otherwise, let's use a
5356 # reasonable default.
54− platform =
55− args.platform
56− or ( config.platform
57− or ((import ./platforms.nix).selectPlatformBySystem system) );
57+ localSystem =
58+ { platform = (import ./platforms.nix).selectPlatformBySystem args.localSystem.system; }
59+ // builtins.intersectAttrs { platform = null; } config
60+ // args.localSystem;
5861
5962 # A few packages make a new package set to draw their dependencies from.
6063 # (Currently to get a cross tool chain, or forced-i686 package.) Rather than
@@ -71,7 +74,8 @@ in let
7174 # To put this in concrete terms, this function is basically just used today to
7275 # use package for a different platform for the current platform (namely cross
7376 # compiling toolchains and 32-bit packages on x86_64). In both those cases we
74− # want the provided non-native `system` argument to affect the stdenv chosen.
77+ # want the provided non-native `localSystem` argument to affect the stdenv
78+ # chosen.
7579 nixpkgsFun = newArgs: import ./. (args // newArgs);
7680
7781 # Partially apply some arguments for building bootstraping stage pkgs
@@ -83,24 +87,7 @@ in let
8387 boot = import ../stdenv/booter.nix { inherit lib allPackages; };
8488
8589 stages = stdenvStages {
86− # One would think that `localSystem` and `crossSystem` overlap horribly with
87− # the three `*Platforms` (`buildPlatform`, `hostPlatform,` and
88− # `targetPlatform`; see `stage.nix` or the manual). Actually, those
89− # identifiers I, @Ericson2314, purposefully not used here to draw a subtle
90− # but important distinction:
91− #
92− # While the granularity of having 3 platforms is necessary to properly
93− # *build* packages, it is overkill for specifying the user's *intent* when
94− # making a build plan or package set. A simple "build vs deploy" dichotomy
95− # is adequate: the "sliding window" principle described in the manual shows
96− # how to interpolate between the these two "end points" to get the 3
97− # platform triple for each bootstrapping stage.
98− #
99− # Also, less philosophically but quite practically, `crossSystem` should be
100− # null when one doesn't want to cross-compile, while the `*Platform`s are
101− # always non-null. `localSystem` is always non-null.
102− localSystem = { inherit system platform; };
103− inherit lib crossSystem config overlays;
90+ inherit lib localSystem crossSystem config overlays;
10491 };
10592
10693 pkgs = boot stages;
pkgs/top-level/impure.nix+15−4
@@ -12,9 +12,11 @@ let
1212
1313in
1414
15−{ # Fallback: Assume we are building packages for the current (host, in GNU
16− # Autotools parlance) system.
17− system ? builtins.currentSystem
15+{ # We combine legacy `system` and `platform` into `localSystem`, if
16+ # `localSystem` was not passed. Strictly speaking, this is pure desugar, but
17+ # it is most convient to do so before the impure `localSystem.system` default,
18+ # so we do it now.
19+ localSystem ? builtins.intersectAttrs { system = null; platform = null; } args
1820
1921, # Fallback: The contents of the configuration file found at $NIXPKGS_CONFIG or
2022 # $HOME/.config/nixpkgs/config.nix.
@@ -49,4 +51,13 @@ in
4951, ...
5052} @ args:
5153
52−import ./. (args // { inherit system config overlays; })
54+# If `localSystem` was explicitly passed, legacy `system` and `platform` should
55+# not be passed.
56+assert args ? localSystem -> !(args ? system || args ? platform);
57+
58+import ./. (builtins.removeAttrs args [ "system" "platform" ] // {
59+ inherit config overlays;
60+ # Fallback: Assume we are building packages on the current (build, in GNU
61+ # Autotools parlance) system.
62+ localSystem = { system = builtins.currentSystem; } // localSystem;
63+})