Rewrite uniqFlattenAttr to handle any type of elements with associated keys.

Keys are introduced because manipulated sets cannot be compared safely.

svn path=/nixpkgs/trunk/; revision=13574
This commit is contained in:
Nicolas Pierron 2008-12-03 18:56:00 +00:00
parent a5d3e865ea
commit 071c62a942

View File

@ -372,27 +372,30 @@ rec {
fix = f: fix = f:
(rec { result = f result; }).result; (rec { result = f result; }).result;
# flatten a list of sets returned by 'f'. # flatten a list of elements by following the properties of the elements.
# f : function to evaluate each set. # key : return the key which correspond to the value.
# attr : name of the attribute which contains more values. # value : return the value inserted in the returned list.
# next : return the list of following elements.
# keys : lists of keys already seen.
# default: result if 'x' is empty. # default: result if 'x' is empty.
# x : list of values that have to be processed. # x : list of values that have to be processed.
uniqFlattenAttr = f: attr: default: x: uniqFlatten = prop@{key, value, next, ...}: keys: default: x:
if x == [] if x == []
then default then default
else else
let h = f (head x); t = tail x; let h = head x; t = tail x;
v = removeAttrs h [attr]; n = getAttr [attr] [] h; k = key h; v = value h; n = next h;
in in
if elem v default if elem k keys
then uniqFlattenAttr f attr default t then uniqFlatten prop keys default t
else uniqFlattenAttr f attr (default ++ [v]) (toList n ++ t) else uniqFlatten prop (keys ++ [k]) (default ++ [v]) (n ++ t)
; ;
/* If. ThenElse. Always. */ /* If. ThenElse. Always. */
# create "if" statement that can be dealyed on sets until a "then-else" or # create "if" statement that can be dealyed on sets until a "then-else" or
# "always" set is reached. When an always set is reached by # "always" set is reached. When an always set is reached the condition
# is ignore.
isIf = attrs: (typeOf attrs) == "if"; isIf = attrs: (typeOf attrs) == "if";
mkIf = condition: thenelse: mkIf = condition: thenelse:
@ -556,10 +559,15 @@ rec {
processConfig = config: configFun: processConfig = config: configFun:
rmRequireIf (optionSet config configFun); rmRequireIf (optionSet config configFun);
in
config: merge "" ( prop = config: rec {
uniqFlattenAttr (processConfig config) "require" [] (toList opts) key = id;
); prepare = x: processConfig config x;
value = x: removeAttrs (prepare x) ["require"];
next = x: toList (getAttr ["require"] [] (prepare x));
};
in config:
merge "" (uniqFlatten (prop config) [] [] (toList opts));
fixOptionSets = merge: pkgs: opts: fixOptionSets = merge: pkgs: opts:
fix (fixOptionSetsFun merge pkgs opts); fix (fixOptionSetsFun merge pkgs opts);