diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index caf57d7d6371..e1c705eef3b5 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -73,10 +73,7 @@ let defaultPkgs = if opt.hostPlatform.isDefined then let - isCross = - !(lib.systems.equals (lib.systems.elaborate cfg.buildPlatform) ( - lib.systems.elaborate cfg.hostPlatform - )); + isCross = cfg.buildPlatform != cfg.hostPlatform; systemArgs = if isCross then { @@ -198,10 +195,13 @@ in }; hostPlatform = lib.mkOption { - type = lib.types.either lib.types.str lib.types.attrs; + 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. @@ -213,13 +213,22 @@ in }; buildPlatform = lib.mkOption { - type = lib.types.either lib.types.str lib.types.attrs; + 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. @@ -236,11 +245,14 @@ in }; localSystem = lib.mkOption { - type = lib.types.attrs; + 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` @@ -268,7 +280,7 @@ in # 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; + type = lib.types.nullOr lib.types.attrs; # TODO utilize lib.systems.parsedPlatform default = null; example = { system = "aarch64-linux"; @@ -404,18 +416,6 @@ 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. - ''; - } ]; }; diff --git a/nixos/modules/misc/nixpkgs/read-only.nix b/nixos/modules/misc/nixpkgs/read-only.nix index 9d0d452ba52d..fa372d13e545 100644 --- a/nixos/modules/misc/nixpkgs/read-only.nix +++ b/nixos/modules/misc/nixpkgs/read-only.nix @@ -40,11 +40,20 @@ in 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. - # + 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. }; @@ -52,8 +61,12 @@ in config = { _module.args.pkgs = # find mistaken definitions - builtins.seq cfg.config builtins.seq cfg.overlays cfg.pkgs; + 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; }; } diff --git a/nixos/modules/virtualisation/nixos-containers.nix b/nixos/modules/virtualisation/nixos-containers.nix index 036f5129b1b3..5f43e3322340 100644 --- a/nixos/modules/virtualisation/nixos-containers.nix +++ b/nixos/modules/virtualisation/nixos-containers.nix @@ -506,12 +506,8 @@ in 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; } + then { inherit (host.pkgs.stdenv) hostPlatform; } + else { localSystem = host.pkgs.stdenv.hostPlatform; } ; boot.isContainer = true; networking.hostName = mkDefault name; diff --git a/nixos/tests/appliance-repart-image-verity-store.nix b/nixos/tests/appliance-repart-image-verity-store.nix index 4769dd052e87..ef0fda4f780d 100644 --- a/nixos/tests/appliance-repart-image-verity-store.nix +++ b/nixos/tests/appliance-repart-image-verity-store.nix @@ -40,7 +40,7 @@ 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"; + ukiPath = "/EFI/BOOT/BOOT${lib.toUpper config.nixpkgs.hostPlatform.efiArch}.EFI"; }; name = "appliance-verity-store-image"; @@ -51,7 +51,7 @@ repartConfig = { Type = "esp"; Format = "vfat"; - SizeMinBytes = if pkgs.stdenv.hostPlatform.isx86_64 then "64M" else "96M"; + SizeMinBytes = if config.nixpkgs.hostPlatform.isx86_64 then "64M" else "96M"; }; }; ${partitionIds.store-verity}.repartConfig = { diff --git a/nixos/tests/appliance-repart-image.nix b/nixos/tests/appliance-repart-image.nix index b916875bfcea..11447cf8fa03 100644 --- a/nixos/tests/appliance-repart-image.nix +++ b/nixos/tests/appliance-repart-image.nix @@ -53,7 +53,7 @@ in "esp" = { contents = let - efiArch = pkgs.stdenv.hostPlatform.efiArch; + efiArch = config.nixpkgs.hostPlatform.efiArch; in { "/EFI/BOOT/BOOT${lib.toUpper efiArch}.EFI".source = @@ -70,7 +70,7 @@ in # 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"; + SizeMinBytes = if config.nixpkgs.hostPlatform.isx86_64 then "64M" else "96M"; }; }; "swap" = { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 9b1537d6bdd0..2984ac2075d4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17721,7 +17721,7 @@ with pkgs; [( { lib, ... }: { config.nixpkgs.pkgs = lib.mkDefault pkgs; - config.nixpkgs.localSystem = lib.mkDefault ({ config = lib.systems.parse.tripleFromSystem stdenv.hostPlatform; }); + config.nixpkgs.localSystem = lib.mkDefault stdenv.hostPlatform; } )] ++ ( if builtins.isList configuration