Merge pull request #196904 from hercules-ci/nixos-nixpkgs-only-error-when-used

main
Bernardo Meurer 2 years ago committed by GitHub
commit d473597e33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      nixos/modules/misc/nixpkgs.nix
  2. 6
      nixos/modules/misc/nixpkgs/test.nix

@ -55,6 +55,11 @@ let
check = builtins.isAttrs; check = builtins.isAttrs;
}; };
# Whether `pkgs` was constructed by this module - not if nixpkgs.pkgs or
# _module.args.pkgs is set. However, determining whether _module.args.pkgs
# is defined elsewhere does not seem feasible.
constructedByMe = !opt.pkgs.isDefined;
hasBuildPlatform = opt.buildPlatform.highestPrio < (mkOptionDefault {}).priority; hasBuildPlatform = opt.buildPlatform.highestPrio < (mkOptionDefault {}).priority;
hasHostPlatform = opt.hostPlatform.isDefined; hasHostPlatform = opt.hostPlatform.isDefined;
hasPlatform = hasHostPlatform || hasBuildPlatform; hasPlatform = hasHostPlatform || hasBuildPlatform;
@ -358,7 +363,7 @@ in
} }
) )
{ {
assertion = hasPlatform -> legacyOptionsDefined == []; assertion = constructedByMe -> hasPlatform -> legacyOptionsDefined == [];
message = '' message = ''
Your system configures nixpkgs with the platform parameter${optionalString hasBuildPlatform "s"}: Your system configures nixpkgs with the platform parameter${optionalString hasBuildPlatform "s"}:
${hostPlatformLine ${hostPlatformLine

@ -59,5 +59,11 @@ lib.recurseIntoAttrs {
For a future proof system configuration, we recommend to remove For a future proof system configuration, we recommend to remove
the legacy definitions. the legacy definitions.
'']; ''];
assert getErrors {
nixpkgs.localSystem = pkgs.stdenv.hostPlatform;
nixpkgs.hostPlatform = pkgs.stdenv.hostPlatform;
nixpkgs.pkgs = pkgs;
} == [];
pkgs.emptyFile; pkgs.emptyFile;
} }

Loading…
Cancel
Save