Remove extra arguments from uniqFlatten.

Clean-up fixOptionSetsFun.

svn path=/nixpkgs/trunk/; revision=13839
This commit is contained in:
Nicolas Pierron 2009-01-25 00:31:29 +00:00
parent 13d5c8923d
commit 57f66db54c

View file

@ -373,22 +373,18 @@ rec {
(rec { result = f result; }).result; (rec { result = f result; }).result;
# flatten a list of elements by following the properties of the elements. # flatten a list of elements by following the properties of the elements.
# key : return the key which correspond to the value.
# value : return the value inserted in the returned list.
# next : return the list of following elements. # next : return the list of following elements.
# keys : lists of keys already seen. # seen : lists of elements already visited.
# 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.
uniqFlatten = prop@{key, value, next, ...}: keys: default: x: uniqFlatten = next: seen: default: x:
if x == [] if x == []
then default then default
else else
let h = head x; t = tail x; let h = head x; t = tail x; n = next h; in
k = key h; v = value h; n = next h; if elem h seen
in then uniqFlatten next seen default t
if elem k keys else uniqFlatten next (seen ++ [h]) (default ++ [h]) (n ++ t)
then uniqFlatten prop keys default t
else uniqFlatten prop (keys ++ [k]) (default ++ [v]) (n ++ t)
; ;
/* If. ThenElse. Always. */ /* If. ThenElse. Always. */
@ -558,38 +554,52 @@ rec {
# Evaluate a list of option sets that would be merged with the # Evaluate a list of option sets that would be merged with the
# function "merge" which expects two arguments. The attribute named # function "merge" which expects two arguments. The attribute named
# "require" is used to imports option declarations and bindings. # "require" is used to imports option declarations and bindings.
fixOptionSetsFun = merge: pkgs: opts: #
# * cfg[0-9]: configuration
# * cfgSet[0-9]: configuration set
#
# merge: the function used to merge options sets.
# pkgs: is the set of packages available. (nixpkgs)
# opts: list of option sets or option set functions.
# config: result of this evaluation.
fixOptionSetsFun = merge: pkgs: opts: config:
let let
# ignore all conditions that are on require attributes. # remove possible mkIf to access the require attribute.
rmRequireIf = conf: noImportConditions = cfgSet0:
let conf2 = delayIf conf; in let cfgSet1 = delayIf cfgSet0; in
if conf2 ? require then if cfgSet1 ? require then
conf2 // { require = rmIf conf2.require; } cfgSet1 // { require = rmIf cfgSet1.require; }
else else
conf2; cfgSet1;
# call configuration "files" with one of the existing convention. # call configuration "files" with one of the existing convention.
optionSet = config: configFun: argumentHandler = cfg:
if __isFunction configFun then let
let result = configFun { inherit pkgs config merge; }; in # {..}
# {pkgs, config, merge, ...}: {..} cfg0 = cfg;
if builtins.isAttrs result then result # {pkgs, config, ...}: {..}
# pkgs: config: {..} cfg1 = cfg { inherit pkgs config merge; };
else builtins.trace "obsolete:" (configFun {} {}) # pkgs: config: {..}
# {..} cfg2 = cfg {} {};
else configFun; in
if __isFunction cfg0 then
if builtins.isAttrs cfg1 then cfg1
else builtins.trace "Use '{pkgs, config, ...}:'." cfg2
else cfg0;
processConfig = config: configFun: preprocess = cfg0:
rmRequireIf (optionSet config configFun); let cfg1 = argumentHandler cfg0;
cfg2 = noImportConditions cfg1;
in cfg2;
prop = config: rec { getRequire = x: toList (getAttr ["require"] [] (preprocess x));
key = id; rmRequire = x: removeAttrs (preprocess x) ["require"];
prepare = x: processConfig config x; in
value = x: removeAttrs (prepare x) ["require"]; merge "" (
next = x: toList (getAttr ["require"] [] (prepare x)); map rmRequire (
}; uniqFlatten getRequire [] [] (toList opts)
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);