···3333 </listitem>
3434 <listitem>
3535 <para>
3636+ The <literal>nixpkgs.hostPlatform</literal> and
3737+ <literal>nixpkgs.buildPlatform</literal> options have been
3838+ added. These cover and override the
3939+ <literal>nixpkgs.{system,localSystem,crossSystem}</literal>
4040+ options.
4141+ </para>
4242+ <itemizedlist spacing="compact">
4343+ <listitem>
4444+ <para>
4545+ <literal>hostPlatform</literal> is the platform or
4646+ <quote><literal>system</literal></quote> string of the
4747+ NixOS system described by the configuration.
4848+ </para>
4949+ </listitem>
5050+ <listitem>
5151+ <para>
5252+ <literal>buildPlatform</literal> is the platform that is
5353+ responsible for building the NixOS configuration. It
5454+ defaults to the <literal>hostPlatform</literal>, for a
5555+ non-cross build configuration. To cross compile, set
5656+ <literal>buildPlatform</literal> to a different value.
5757+ </para>
5858+ </listitem>
5959+ </itemizedlist>
6060+ <para>
6161+ The new options convey the same information, but with fewer
6262+ options, and following the Nixpkgs terminology.
6363+ </para>
6464+ <para>
6565+ The existing options
6666+ <literal>nixpkgs.{system,localSystem,crossSystem}</literal>
6767+ have not been formally deprecated, to allow for evaluation of
6868+ the change and to allow for a transition period so that in
6969+ time the ecosystem can switch without breaking compatibility
7070+ with any supported NixOS release.
7171+ </para>
7272+ </listitem>
7373+ <listitem>
7474+ <para>
7575+ <literal>nixos-generate-config</literal> now generates
7676+ configurations that can be built in pure mode. This is
7777+ achieved by setting the new
7878+ <literal>nixpkgs.hostPlatform</literal> option.
7979+ </para>
8080+ <para>
8181+ You may have to unset the <literal>system</literal> parameter
8282+ in <literal>lib.nixosSystem</literal>, or similarly remove
8383+ definitions of the
8484+ <literal>nixpkgs.{system,localSystem,crossSystem}</literal>
8585+ options.
8686+ </para>
8787+ <para>
8888+ Alternatively, you can remove the
8989+ <literal>hostPlatform</literal> line and use NixOS like you
9090+ would in NixOS 22.05 and earlier.
9191+ </para>
9292+ </listitem>
9393+ <listitem>
9494+ <para>
3695 PHP now defaults to PHP 8.1, updated from 8.0.
3796 </para>
3897 </listitem>
+27
nixos/doc/manual/release-notes/rl-2211.section.md
···1717 built for `stdenv.hostPlatform` (i.e. produced by `stdenv.cc`) by evaluating
1818 `stdenv.buildPlatform.canExecute stdenv.hostPlatform`.
19192020+- The `nixpkgs.hostPlatform` and `nixpkgs.buildPlatform` options have been added.
2121+ These cover and override the `nixpkgs.{system,localSystem,crossSystem}` options.
2222+2323+ - `hostPlatform` is the platform or "`system`" string of the NixOS system
2424+ described by the configuration.
2525+ - `buildPlatform` is the platform that is responsible for building the NixOS
2626+ configuration. It defaults to the `hostPlatform`, for a non-cross
2727+ build configuration. To cross compile, set `buildPlatform` to a different
2828+ value.
2929+3030+ The new options convey the same information, but with fewer options, and
3131+ following the Nixpkgs terminology.
3232+3333+ The existing options `nixpkgs.{system,localSystem,crossSystem}` have not
3434+ been formally deprecated, to allow for evaluation of the change and to allow
3535+ for a transition period so that in time the ecosystem can switch without
3636+ breaking compatibility with any supported NixOS release.
3737+3838+- `nixos-generate-config` now generates configurations that can be built in pure
3939+ mode. This is achieved by setting the new `nixpkgs.hostPlatform` option.
4040+4141+ You may have to unset the `system` parameter in `lib.nixosSystem`, or similarly
4242+ remove definitions of the `nixpkgs.{system,localSystem,crossSystem}` options.
4343+4444+ Alternatively, you can remove the `hostPlatform` line and use NixOS like you
4545+ would in NixOS 22.05 and earlier.
4646+2047- PHP now defaults to PHP 8.1, updated from 8.0.
21482249- `hardware.nvidia` has a new option `open` that can be used to opt in the opensource version of NVIDIA kernel driver. Note that the driver's support for GeForce and Workstation GPUs is still alpha quality, see [NVIDIA Releases Open-Source GPU Kernel Modules](https://developer.nvidia.com/blog/nvidia-releases-open-source-gpu-kernel-modules/) for the official announcement.
···8484}
858586868787+# nixpkgs.system
8888+my ($status, @systemLines) = runCommand("nix-instantiate --impure --eval --expr builtins.currentSystem");
8989+if ($status != 0 || join("", @systemLines) =~ /error/) {
9090+ die "Failed to retrieve current system type from nix.\n";
9191+}
9292+chomp(my $system = @systemLines[0]);
9393+push @attrs, "nixpkgs.hostPlatform = lib.mkDefault $system;";
9494+9595+8796my $cpuinfo = read_file "/proc/cpuinfo";
88978998
+100-8
nixos/modules/misc/nixpkgs.nix
···5555 check = builtins.isAttrs;
5656 };
57575858- defaultPkgs = import ../../.. {
5959- inherit (cfg) config overlays localSystem crossSystem;
6060- };
5858+ hasBuildPlatform = opt.buildPlatform.highestPrio < (mkOptionDefault {}).priority;
5959+ hasHostPlatform = opt.hostPlatform.isDefined;
6060+ hasPlatform = hasHostPlatform || hasBuildPlatform;
6161+6262+ # Context for messages
6363+ hostPlatformLine = optionalString hasHostPlatform "${showOptionWithDefLocs opt.hostPlatform}";
6464+ buildPlatformLine = optionalString hasBuildPlatform "${showOptionWithDefLocs opt.buildPlatform}";
6565+ platformLines = optionalString hasPlatform ''
6666+ Your system configuration configures nixpkgs with platform parameters:
6767+ ${hostPlatformLine
6868+ }${buildPlatformLine
6969+ }'';
7070+7171+ legacyOptionsDefined =
7272+ optional opt.system.isDefined opt.system
7373+ ++ (optional (opt.localSystem.highestPrio < (mkOptionDefault {}).priority) opt.localSystem)
7474+ ++ (optional (opt.crossSystem.highestPrio < (mkOptionDefault {}).priority) opt.crossSystem)
7575+ ;
7676+7777+ defaultPkgs =
7878+ if opt.hostPlatform.isDefined
7979+ then
8080+ let isCross = cfg.buildPlatform != cfg.hostPlatform;
8181+ systemArgs =
8282+ if isCross
8383+ then {
8484+ localSystem = cfg.buildPlatform;
8585+ crossSystem = cfg.hostPlatform;
8686+ }
8787+ else {
8888+ localSystem = cfg.hostPlatform;
8989+ };
9090+ in
9191+ import ../../.. ({
9292+ inherit (cfg) config overlays;
9393+ } // systemArgs)
9494+ else
9595+ import ../../.. {
9696+ inherit (cfg) config overlays localSystem crossSystem;
9797+ };
61986299 finalPkgs = if opt.pkgs.isDefined then cfg.pkgs.appendOverlays cfg.overlays else defaultPkgs;
63100···157194 '';
158195 };
159196197197+ hostPlatform = mkOption {
198198+ type = types.either types.str types.attrs; # TODO utilize lib.systems.parsedPlatform
199199+ example = { system = "aarch64-linux"; config = "aarch64-unknown-linux-gnu"; };
200200+ # Make sure that the final value has all fields for sake of other modules
201201+ # referring to this. TODO make `lib.systems` itself use the module system.
202202+ apply = lib.systems.elaborate;
203203+ defaultText = literalExpression
204204+ ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
205205+ description = ''
206206+ Specifies the platform where the NixOS configuration will run.
207207+208208+ To cross-compile, set also <code>nixpkgs.buildPlatform</code>.
209209+210210+ Ignored when <code>nixpkgs.pkgs</code> is set.
211211+ '';
212212+ };
213213+214214+ buildPlatform = mkOption {
215215+ type = types.either types.str types.attrs; # TODO utilize lib.systems.parsedPlatform
216216+ default = cfg.hostPlatform;
217217+ example = { system = "x86_64-linux"; config = "x86_64-unknown-linux-gnu"; };
218218+ # Make sure that the final value has all fields for sake of other modules
219219+ # referring to this.
220220+ apply = lib.systems.elaborate;
221221+ defaultText = literalExpression
222222+ ''config.nixpkgs.hostPlatform'';
223223+ description = ''
224224+ Specifies the platform on which NixOS should be built.
225225+ By default, NixOS is built on the system where it runs, but you can
226226+ change where it's built. Setting this option will cause NixOS to be
227227+ cross-compiled.
228228+229229+ For instance, if you're doing distributed multi-platform deployment,
230230+ or if you're building machines, you can set this to match your
231231+ development system and/or build farm.
232232+233233+ Ignored when <code>nixpkgs.pkgs</code> is set.
234234+ '';
235235+ };
236236+160237 localSystem = mkOption {
161238 type = types.attrs; # TODO utilize lib.systems.parsedPlatform
162239 default = { inherit (cfg) system; };
···176253 deployment, or when building virtual machines. See its
177254 description in the Nixpkgs manual for more details.
178255179179- Ignored when <code>nixpkgs.pkgs</code> is set.
256256+ Ignored when <code>nixpkgs.pkgs</code> or <code>hostPlatform</code> is set.
180257 '';
181258 };
182259260260+ # TODO deprecate. "crossSystem" is a nonsense identifier, because "cross"
261261+ # is a relation between at least 2 systems in the context of a
262262+ # specific build step, not a single system.
183263 crossSystem = mkOption {
184264 type = types.nullOr types.attrs; # TODO utilize lib.systems.parsedPlatform
185265 default = null;
···193273 should be set as null, the default. See its description in the
194274 Nixpkgs manual for more details.
195275196196- Ignored when <code>nixpkgs.pkgs</code> is set.
276276+ Ignored when <code>nixpkgs.pkgs</code> or <code>hostPlatform</code> is set.
197277 '';
198278 };
199279···216296 </programlisting>
217297 See <code>nixpkgs.localSystem</code> for more information.
218298219219- Ignored when <code>nixpkgs.localSystem</code> is set.
220220- Ignored when <code>nixpkgs.pkgs</code> is set.
299299+ Ignored when <code>nixpkgs.pkgs</code>, <code>nixpkgs.localSystem</code> or <code>nixpkgs.hostPlatform</code> is set.
221300 '';
222301 };
223302 };
···240319 else "nixpkgs.localSystem";
241320 pkgsSystem = finalPkgs.stdenv.targetPlatform.system;
242321 in {
243243- assertion = nixosExpectedSystem == pkgsSystem;
322322+ assertion = !hasPlatform -> nixosExpectedSystem == pkgsSystem;
244323 message = "The NixOS nixpkgs.pkgs option was set to a Nixpkgs invocation that compiles to target system ${pkgsSystem} but NixOS was configured for system ${nixosExpectedSystem} via NixOS option ${nixosOption}. The NixOS system settings must match the Nixpkgs target system.";
245324 }
246325 )
326326+ {
327327+ assertion = hasPlatform -> legacyOptionsDefined == [];
328328+ message = ''
329329+ Your system configures nixpkgs with the platform parameter${optionalString hasBuildPlatform "s"}:
330330+ ${hostPlatformLine
331331+ }${buildPlatformLine
332332+ }
333333+ However, it also defines the legacy options:
334334+ ${concatMapStrings showOptionWithDefLocs legacyOptionsDefined}
335335+ For a future proof system configuration, we recommend to remove
336336+ the legacy definitions.
337337+ '';
338338+ }
247339 ];
248340 };
249341