From 596b3663a53de13a7f56d0b052c094214fbad49d Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 30 Apr 2022 12:57:50 +0200 Subject: [PATCH] pkgs/top-level/config.nix: Add warnUndeclaredOptions --- pkgs/top-level/config.nix | 16 +++++++++++++++- pkgs/top-level/default.nix | 6 ++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pkgs/top-level/config.nix b/pkgs/top-level/config.nix index d553b624039e..ae132d69a4e9 100644 --- a/pkgs/top-level/config.nix +++ b/pkgs/top-level/config.nix @@ -1,6 +1,6 @@ # This file defines the structure of the `config` nixpkgs option. -{ lib, ... }: +{ config, lib, ... }: with lib; @@ -28,6 +28,11 @@ let /* Config options */ + warnUndeclaredOptions = mkOption { + description = "Whether to warn when config contains an unrecognized attribute."; + default = false; + }; + doCheckByDefault = mkMassRebuild { feature = "run checkPhase by default"; }; @@ -113,6 +118,15 @@ let in { + freeformType = + let t = lib.types.attrsOf lib.types.raw; + in t // { + merge = loc: defs: + lib.mapAttrs + (k: v: lib.warnIf config.warnUndeclaredOptions "undeclared Nixpkgs option set: config.${k}" v) + (t.merge loc defs); + }; + inherit options; } diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index e95a0db78c3c..b32aabc3a1fd 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -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