From 233d72e4fb58bb195fd1701202ea9be2d9b20501 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sat, 7 Nov 2009 01:59:45 +0000 Subject: [PATCH] * Add "_args" to all sub-module configurations result. This attribute enable argument introspection outside of the scope of each sub-module. svn path=/nixpkgs/trunk/; revision=18240 --- pkgs/lib/options.nix | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix index b7797cabbb43..7b5351a19607 100644 --- a/pkgs/lib/options.nix +++ b/pkgs/lib/options.nix @@ -83,26 +83,35 @@ rec { if opt ? type && opt.type.hasOptions then let - optionConfig = vals: path: config: - let name = lib.removePrefix (opt.name + ".") path; in - map (f: lib.applyIfFunction f ({inherit name;} // config)) + optionConfig = vals: args: + map (f: lib.applyIfFunction f args) (opt.options ++ toList vals); + + # Evaluate sub-modules. + subModuleMerge = path: vals: + lib.fix (args: + let result = recurseInto path (optionConfig vals args); in { + inherit (result) config options; + name = lib.removePrefix (opt.name + ".") path; + } + ); + + # Add _options in sub-modules to make it viewable from other + # modules. + subModuleMergeConfig = path: vals: + let result = subModuleMerge path vals; in + { _args = result; } // result.config; + in opt // { merge = list: opt.type.iter - (path: vals: - (lib.fix - (fixableMergeFun (recurseInto path) (optionConfig vals path)) - ).config - ) + subModuleMergeConfig opt.name (opt.merge list); options = let path = opt.type.docPath opt.name; in - (lib.fix - (fixableMergeFun (recurseInto path) (optionConfig [] path)) - ).options; + (subModuleMerge path []).options; } else opt;