Merge pull request #171014 from hercules-ci/nixpkgs-warn-undeclared-options

pkgs/top-level/config.nix: Add warnUndeclaredOptions
This commit is contained in:
Robert Hensing 2022-05-25 08:37:15 +02:00 committed by GitHub
commit 40b6089f21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 6 deletions

View File

@ -248,7 +248,7 @@ rec {
/* Apply fold functions to values grouped by key.
Example:
foldAttrs (n: a: [n] ++ a) [] [{ a = 2; } { a = 3; }]
foldAttrs (item: acc: [item] ++ acc) [] [{ a = 2; } { a = 3; }]
=> { a = [ 2 3 ]; }
*/
foldAttrs = op: nul:

View File

@ -1,6 +1,6 @@
# This file defines the structure of the `config` nixpkgs option.
{ lib, ... }:
{ config, lib, ... }:
with lib;
@ -33,6 +33,11 @@ let
/* Config options */
warnUndeclaredOptions = mkOption {
description = "Whether to warn when <literal>config</literal> contains an unrecognized attribute.";
default = false;
};
doCheckByDefault = mkMassRebuild {
feature = "run <literal>checkPhase</literal> by default";
};
@ -122,6 +127,20 @@ let
in {
freeformType =
let t = lib.types.attrsOf lib.types.raw;
in t // {
merge = loc: defs:
let r = t.merge loc defs;
in r // { _undeclared = r; };
};
inherit options;
config = {
warnings = lib.optionals config.warnUndeclaredOptions (
lib.mapAttrsToList (k: v: "undeclared Nixpkgs option set: config.${k}") config._undeclared
);
};
}

View File

@ -79,15 +79,13 @@ in let
./config.nix
({ options, ... }: {
_file = "nixpkgs.config";
# filter-out known options, FIXME: remove this eventually
config = builtins.intersectAttrs options config1;
config = config1;
})
];
};
# take all the rest as-is
config = lib.showWarnings configEval.config.warnings
(config1 // builtins.removeAttrs configEval.config [ "_module" ]);
config = lib.showWarnings configEval.config.warnings configEval.config;
# A few packages make a new package set to draw their dependencies from.
# (Currently to get a cross tool chain, or forced-i686 package.) Rather than