diff options
author | Nicolas Pierron <nicolas.b.pierron@gmail.com> | 2009-11-07 01:59:50 +0000 |
---|---|---|
committer | Nicolas Pierron <nicolas.b.pierron@gmail.com> | 2009-11-07 01:59:50 +0000 |
commit | 88f113d032c1908fca2ebfbf429d161fc738bdc1 (patch) | |
tree | e21a909a11855582d46145364c35e6164c97b394 | |
parent | 233d72e4fb58bb195fd1701202ea9be2d9b20501 (diff) | |
download | nixpkgs-88f113d032c1908fca2ebfbf429d161fc738bdc1.tar nixpkgs-88f113d032c1908fca2ebfbf429d161fc738bdc1.tar.gz nixpkgs-88f113d032c1908fca2ebfbf429d161fc738bdc1.tar.bz2 nixpkgs-88f113d032c1908fca2ebfbf429d161fc738bdc1.tar.lz nixpkgs-88f113d032c1908fca2ebfbf429d161fc738bdc1.tar.xz nixpkgs-88f113d032c1908fca2ebfbf429d161fc738bdc1.tar.zst nixpkgs-88f113d032c1908fca2ebfbf429d161fc738bdc1.zip |
* 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
-rw-r--r-- | pkgs/lib/modules.nix | 25 |
1 files changed, 25 insertions, 0 deletions
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; + } |