From 88f113d032c1908fca2ebfbf429d161fc738bdc1 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sat, 7 Nov 2009 01:59:50 +0000 Subject: [PATCH] * Add a function to replace "pkgs.checker". The function checkModule does a traversal of all definitions and also check definitions contained inside sub-modules. svn path=/nixpkgs/trunk/; revision=18241 --- pkgs/lib/modules.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pkgs/lib/modules.nix b/pkgs/lib/modules.nix index 8f6ae5666b1..4500d588a02 100644 --- a/pkgs/lib/modules.nix +++ b/pkgs/lib/modules.nix @@ -238,6 +238,7 @@ rec { result = if isOption then value + else if !hasOptions then {} else if all isAttrs values then recurse else throw "${eol @@ -323,4 +324,28 @@ rec { ) ); + # Visit all definitions to raise errors related to undeclared options. + checkModule = path: {config, options, ...}@m: + let + eol = "\n"; + addName = name: + if path == "" then name else path + "." + name; + in + if lib.isOption options then + if options ? options then + options.type.fold + (cfg: res: res && checkModule (options.type.docPath path) cfg._args) + true config + else + true + else if isAttrs options && lib.attrNames m.options != [] then + all (name: + lib.addErrorContext "${eol + }while checking the attribute '${addName name}'.${eol + }" (checkModule (addName name) (selectModule name m)) + ) (lib.attrNames m.config) + else + builtins.trace "try to evaluate config ${lib.showVal config}." + false; + }