nixpkgs: make config.nixpkgs.{buildPlatform,hostPlatform} write only
The description for options.nixpkgs.system already hints at this:
Neither ${opt.system} nor any other option in nixpkgs.* is meant
to be read by modules and configurations.
Use pkgs.stdenv.hostPlatform instead.
We can support this goal by not elaborating the systems anymore, forcing
users to go via pkgs.stdenv.
This will prevent problems when making the top-level package sets
composable in the next commit. For this to work, you should pass a fully
elaborated system to nixpkgs' localSystem or crossSystem options.
Backport of Nixpkgs commit 0a19371146130c0e2a402fd0c35f8283b0e81910.
Co-authored-by: Wolfgang Walther <walther@technowledgy.de>
This commit is contained in:
parent
5084b33265
commit
7c72c013b1
1 changed files with 16 additions and 17 deletions
|
|
@ -73,7 +73,10 @@ let
|
|||
defaultPkgs =
|
||||
if opt.hostPlatform.isDefined then
|
||||
let
|
||||
isCross = cfg.buildPlatform != cfg.hostPlatform;
|
||||
isCross =
|
||||
!(lib.systems.equals (lib.systems.elaborate cfg.buildPlatform) (
|
||||
lib.systems.elaborate cfg.hostPlatform
|
||||
));
|
||||
systemArgs =
|
||||
if isCross then
|
||||
{
|
||||
|
|
@ -165,13 +168,10 @@ in
|
|||
};
|
||||
|
||||
hostPlatform = lib.mkOption {
|
||||
type = lib.types.either lib.types.str lib.types.attrs; # TODO utilize lib.systems.parsedPlatform
|
||||
type = lib.types.either lib.types.str lib.types.attrs;
|
||||
example = {
|
||||
system = "aarch64-darwin";
|
||||
};
|
||||
# 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;
|
||||
description = ''
|
||||
Specifies the platform where the nix-darwin configuration will run.
|
||||
|
||||
|
|
@ -182,24 +182,13 @@ in
|
|||
};
|
||||
|
||||
buildPlatform = lib.mkOption {
|
||||
type = lib.types.either lib.types.str lib.types.attrs; # TODO utilize lib.systems.parsedPlatform
|
||||
type = lib.types.either lib.types.str lib.types.attrs;
|
||||
default = cfg.hostPlatform;
|
||||
example = {
|
||||
system = "x86_64-darwin";
|
||||
};
|
||||
# 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 nix-darwin should be built.
|
||||
|
|
@ -323,6 +312,16 @@ 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));
|
||||
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.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue