Clean-up option-usages.nix by using recent library functions.

svn path=/nixos/trunk/; revision=17516
This commit is contained in:
Nicolas Pierron 2009-09-29 16:42:22 +00:00
parent fdab662659
commit 2dce393e6e

View file

@ -47,63 +47,31 @@ let
); );
mkProtect = name: value: { _type = "protect"; inherit name value; };
isProtected = attr: (pkgs.lib.typeOf attr) == "protect";
getName = set: with pkgs.lib;
if isProtected set then
set.name
else
getName (head (attrValues set));
rmProtect = set: with pkgs.lib;
if isProtected set then
set.value
else
mapAttrs (n: rmProtect) set;
# Create a list of modules where each module contains only one failling # Create a list of modules where each module contains only one failling
# options. # options.
introspectionModules = with pkgs.lib; introspectionModules = with pkgs.lib;
let let
genericFun = f: set: setIntrospection = opt: rec {
fold (name: rest: name = opt.name;
(map (v: path = splitString "." opt.name;
listToAttrs [(nameValuePair name v)] config = setAttrByPath path
) (f (getAttr name set))) (throw "Usage introspection of '${name}' by forced failure.");
++ rest };
) [] (attrNames set);
addIntrospection = opt: mkProtect opt.name (
throw "Usage introspection of '${opt.name}' by forced failure."
);
f = v:
if isOption v then
[(addIntrospection v)]
else
genericFun f v;
in in
genericFun f eval.options; map setIntrospection (collect isOption eval.options);
overrideConfig = override: with pkgs.lib; overrideConfig = thrower:
let f = configs: pkgs.lib.recursiveUpdateUntil (path: old: new:
zip (n: v: path == thrower.path
if tail v == [] || isProtected (head v) then ) eval.config thrower.config;
head v
else
f v
) configs;
in
f [ override eval.config ];
graph = with pkgs.lib; graph = with pkgs.lib;
map (thrower: { map (thrower: {
option = getName thrower; option = thrower.name;
usedBy = reportNewFailures eval.options (evalFun { usedBy = reportNewFailures eval.options (evalFun {
extraArgs = { extraArgs = {
config = overrideConfig (rmProtect thrower); config = overrideConfig thrower;
}; };
}).options; }).options;
}) introspectionModules; }) introspectionModules;