Revert "nixos/nixpkgs: make config.nixpkgs.{localSystem,crossSystem,buildPlatform,hostPlatform} write only"

This reverts commit 0a19371146130c0e2a402fd0c35f8283b0e81910.

Changed files
+46 -37
nixos
pkgs
top-level
+20 -20
nixos/modules/misc/nixpkgs.nix
···
defaultPkgs =
if opt.hostPlatform.isDefined then
let
-
isCross =
-
!(lib.systems.equals (lib.systems.elaborate cfg.buildPlatform) (
-
lib.systems.elaborate cfg.hostPlatform
-
));
systemArgs =
if isCross then
{
···
};
hostPlatform = lib.mkOption {
-
type = lib.types.either lib.types.str lib.types.attrs;
example = {
system = "aarch64-linux";
};
defaultText = lib.literalExpression ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
description = ''
Specifies the platform where the NixOS configuration will run.
···
};
buildPlatform = lib.mkOption {
-
type = lib.types.either lib.types.str lib.types.attrs;
default = cfg.hostPlatform;
example = {
system = "x86_64-linux";
};
# Make sure that the final value has all fields for sake of other modules
# referring to this.
defaultText = lib.literalExpression ''config.nixpkgs.hostPlatform'';
description = ''
Specifies the platform on which NixOS should be built.
···
};
localSystem = lib.mkOption {
-
type = lib.types.attrs;
default = { inherit (cfg) system; };
example = {
system = "aarch64-linux";
};
defaultText = lib.literalExpression ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
description = ''
Systems with a recently generated `hardware-configuration.nix`
···
# is a relation between at least 2 systems in the context of a
# specific build step, not a single system.
crossSystem = lib.mkOption {
-
type = lib.types.nullOr lib.types.attrs;
default = null;
example = {
system = "aarch64-linux";
···
Defined in:
${lib.concatMapStringsSep "\n" (file: " - ${file}") opt.config.files}
-
'';
-
}
-
{
-
assertion =
-
(opt.hostPlatform.isDefined -> builtins.isAttrs cfg.buildPlatform -> !(cfg.buildPlatform ? parsed))
-
&& (opt.hostPlatform.isDefined -> builtins.isAttrs cfg.hostPlatform -> !(cfg.hostPlatform ? parsed))
-
&& (builtins.isAttrs cfg.localSystem -> !(cfg.localSystem ? parsed))
-
&& (builtins.isAttrs cfg.crossSystem -> !(cfg.crossSystem ? parsed));
-
message = ''
-
Passing fully elaborated systems to `nixpkgs.localSystem`, `nixpkgs.crossSystem`, `nixpkgs.buildPlatform`
-
or `nixpkgs.hostPlatform` will break composability of package sets in nixpkgs. For example, pkgs.pkgsStatic
-
would not work in modules anymore.
'';
}
];
···
defaultPkgs =
if opt.hostPlatform.isDefined then
let
+
isCross = cfg.buildPlatform != cfg.hostPlatform;
systemArgs =
if isCross then
{
···
};
hostPlatform = lib.mkOption {
+
type = lib.types.either lib.types.str lib.types.attrs; # TODO utilize lib.systems.parsedPlatform
example = {
system = "aarch64-linux";
};
+
# Make sure that the final value has all fields for sake of other modules
+
# referring to this. TODO make `lib.systems` itself use the module system.
+
apply = lib.systems.elaborate;
defaultText = lib.literalExpression ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
description = ''
Specifies the platform where the NixOS configuration will run.
···
};
buildPlatform = lib.mkOption {
+
type = lib.types.either lib.types.str lib.types.attrs; # TODO utilize lib.systems.parsedPlatform
default = cfg.hostPlatform;
example = {
system = "x86_64-linux";
};
# Make sure that the final value has all fields for sake of other modules
# referring to this.
+
apply =
+
inputBuildPlatform:
+
let
+
elaborated = lib.systems.elaborate inputBuildPlatform;
+
in
+
if lib.systems.equals elaborated cfg.hostPlatform then
+
cfg.hostPlatform # make identical, so that `==` equality works; see https://github.com/NixOS/nixpkgs/issues/278001
+
else
+
elaborated;
defaultText = lib.literalExpression ''config.nixpkgs.hostPlatform'';
description = ''
Specifies the platform on which NixOS should be built.
···
};
localSystem = lib.mkOption {
+
type = lib.types.attrs; # TODO utilize lib.systems.parsedPlatform
default = { inherit (cfg) system; };
example = {
system = "aarch64-linux";
};
+
# Make sure that the final value has all fields for sake of other modules
+
# referring to this. TODO make `lib.systems` itself use the module system.
+
apply = lib.systems.elaborate;
defaultText = lib.literalExpression ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
description = ''
Systems with a recently generated `hardware-configuration.nix`
···
# is a relation between at least 2 systems in the context of a
# specific build step, not a single system.
crossSystem = lib.mkOption {
+
type = lib.types.nullOr lib.types.attrs; # TODO utilize lib.systems.parsedPlatform
default = null;
example = {
system = "aarch64-linux";
···
Defined in:
${lib.concatMapStringsSep "\n" (file: " - ${file}") opt.config.files}
'';
}
];
+19 -6
nixos/modules/misc/nixpkgs/read-only.nix
···
The Nixpkgs overlays that `pkgs` was initialized with.
'';
};
-
# buildPlatform and hostPlatform left out on purpose:
-
# - They are not supposed to be changed with this read-only module.
-
# - They are not supposed to be read either, according to the description
-
# of "system" in the traditional nixpkgs module.
-
#
# NOTE: do not add the legacy options such as localSystem here. Let's keep
# this module simple and let module authors upgrade their code instead.
};
···
config = {
_module.args.pkgs =
# find mistaken definitions
-
builtins.seq cfg.config builtins.seq cfg.overlays cfg.pkgs;
nixpkgs.config = cfg.pkgs.config;
nixpkgs.overlays = cfg.pkgs.overlays;
};
}
···
The Nixpkgs overlays that `pkgs` was initialized with.
'';
};
+
hostPlatform = mkOption {
+
internal = true;
+
readOnly = true;
+
description = ''
+
The platform of the machine that is running the NixOS configuration.
+
'';
+
};
+
buildPlatform = mkOption {
+
internal = true;
+
readOnly = true;
+
description = ''
+
The platform of the machine that built the NixOS configuration.
+
'';
+
};
# NOTE: do not add the legacy options such as localSystem here. Let's keep
# this module simple and let module authors upgrade their code instead.
};
···
config = {
_module.args.pkgs =
# find mistaken definitions
+
builtins.seq cfg.config builtins.seq cfg.overlays builtins.seq cfg.hostPlatform builtins.seq
+
cfg.buildPlatform
+
cfg.pkgs;
nixpkgs.config = cfg.pkgs.config;
nixpkgs.overlays = cfg.pkgs.overlays;
+
nixpkgs.hostPlatform = cfg.pkgs.stdenv.hostPlatform;
+
nixpkgs.buildPlatform = cfg.pkgs.stdenv.buildPlatform;
};
}
+2 -6
nixos/modules/virtualisation/nixos-containers.nix
···
config = {
nixpkgs =
if options.nixpkgs?hostPlatform
-
then {
-
hostPlatform =
-
if host.options.nixpkgs.hostPlatform.isDefined
-
then host.config.nixpkgs.hostPlatform
-
else lib.defaultTo host.config.nixpkgs.localSystem host.config.nixpkgs.crossSystem;
-
} else { localSystem = lib.defaultTo host.config.nixpkgs.localSystem host.config.nixpkgs.crossSystem; }
;
boot.isContainer = true;
networking.hostName = mkDefault name;
···
config = {
nixpkgs =
if options.nixpkgs?hostPlatform
+
then { inherit (host.pkgs.stdenv) hostPlatform; }
+
else { localSystem = host.pkgs.stdenv.hostPlatform; }
;
boot.isContainer = true;
networking.hostName = mkDefault name;
+2 -2
nixos/tests/appliance-repart-image-verity-store.nix
···
verityStore = {
enable = true;
# by default the module works with systemd-boot, for simplicity this test directly boots the UKI
-
ukiPath = "/EFI/BOOT/BOOT${lib.toUpper pkgs.stdenv.hostPlatform.efiArch}.EFI";
};
name = "appliance-verity-store-image";
···
repartConfig = {
Type = "esp";
Format = "vfat";
-
SizeMinBytes = if pkgs.stdenv.hostPlatform.isx86_64 then "64M" else "96M";
};
};
${partitionIds.store-verity}.repartConfig = {
···
verityStore = {
enable = true;
# by default the module works with systemd-boot, for simplicity this test directly boots the UKI
+
ukiPath = "/EFI/BOOT/BOOT${lib.toUpper config.nixpkgs.hostPlatform.efiArch}.EFI";
};
name = "appliance-verity-store-image";
···
repartConfig = {
Type = "esp";
Format = "vfat";
+
SizeMinBytes = if config.nixpkgs.hostPlatform.isx86_64 then "64M" else "96M";
};
};
${partitionIds.store-verity}.repartConfig = {
+2 -2
nixos/tests/appliance-repart-image.nix
···
"esp" = {
contents =
let
-
efiArch = pkgs.stdenv.hostPlatform.efiArch;
in
{
"/EFI/BOOT/BOOT${lib.toUpper efiArch}.EFI".source =
···
# aarch64 kernel seems to generally be a little bigger than the
# x86_64 kernel. To stay on the safe side, leave some more slack
# for every platform other than x86_64.
-
SizeMinBytes = if pkgs.stdenv.hostPlatform.isx86_64 then "64M" else "96M";
};
};
"swap" = {
···
"esp" = {
contents =
let
+
efiArch = config.nixpkgs.hostPlatform.efiArch;
in
{
"/EFI/BOOT/BOOT${lib.toUpper efiArch}.EFI".source =
···
# aarch64 kernel seems to generally be a little bigger than the
# x86_64 kernel. To stay on the safe side, leave some more slack
# for every platform other than x86_64.
+
SizeMinBytes = if config.nixpkgs.hostPlatform.isx86_64 then "64M" else "96M";
};
};
"swap" = {
+1 -1
pkgs/top-level/all-packages.nix
···
[(
{ lib, ... }: {
config.nixpkgs.pkgs = lib.mkDefault pkgs;
-
config.nixpkgs.localSystem = lib.mkDefault ({ config = lib.systems.parse.tripleFromSystem stdenv.hostPlatform; });
}
)] ++ (
if builtins.isList configuration
···
[(
{ lib, ... }: {
config.nixpkgs.pkgs = lib.mkDefault pkgs;
+
config.nixpkgs.localSystem = lib.mkDefault stdenv.hostPlatform;
}
)] ++ (
if builtins.isList configuration