3
0
Fork 0
forked from mirrors/nixpkgs

lib: modules: propagate highestPrio

Yeah, it's ugly. But it's the minimal change that doesn't break anything
else.
This commit is contained in:
Jan Malakhovski 2018-02-22 21:31:38 +00:00
parent 095fe5b43d
commit 4017fdcafd

View file

@ -310,6 +310,7 @@ rec {
in opt // in opt //
{ value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value; { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
inherit (res.defsFinal') highestPrio;
definitions = map (def: def.value) res.defsFinal; definitions = map (def: def.value) res.defsFinal;
files = map (def: def.file) res.defsFinal; files = map (def: def.file) res.defsFinal;
inherit (res) isDefined; inherit (res) isDefined;
@ -317,7 +318,7 @@ rec {
# Merge definitions of a value of a given type. # Merge definitions of a value of a given type.
mergeDefinitions = loc: type: defs: rec { mergeDefinitions = loc: type: defs: rec {
defsFinal = defsFinal' =
let let
# Process mkMerge and mkIf properties. # Process mkMerge and mkIf properties.
defs' = concatMap (m: defs' = concatMap (m:
@ -325,15 +326,20 @@ rec {
) defs; ) defs;
# Process mkOverride properties. # Process mkOverride properties.
defs'' = filterOverrides defs'; defs'' = filterOverrides' defs';
# Sort mkOrder properties. # Sort mkOrder properties.
defs''' = defs''' =
# Avoid sorting if we don't have to. # Avoid sorting if we don't have to.
if any (def: def.value._type or "" == "order") defs'' if any (def: def.value._type or "" == "order") defs''.values
then sortProperties defs'' then sortProperties defs''.values
else defs''; else defs''.values;
in defs'''; in {
values = defs''';
inherit (defs'') highestPrio;
};
defsFinal = defsFinal'.values;
# Type-check the remaining definitions, and merge them. # Type-check the remaining definitions, and merge them.
mergedValue = foldl' (res: def: mergedValue = foldl' (res: def:
@ -416,13 +422,18 @@ rec {
Note that "z" has the default priority 100. Note that "z" has the default priority 100.
*/ */
filterOverrides = defs: filterOverrides = defs: (filterOverrides' defs).values;
filterOverrides' = defs:
let let
defaultPrio = 100; defaultPrio = 100;
getPrio = def: if def.value._type or "" == "override" then def.value.priority else defaultPrio; getPrio = def: if def.value._type or "" == "override" then def.value.priority else defaultPrio;
highestPrio = foldl' (prio: def: min (getPrio def) prio) 9999 defs; highestPrio = foldl' (prio: def: min (getPrio def) prio) 9999 defs;
strip = def: if def.value._type or "" == "override" then def // { value = def.value.content; } else def; strip = def: if def.value._type or "" == "override" then def // { value = def.value.content; } else def;
in concatMap (def: if getPrio def == highestPrio then [(strip def)] else []) defs; in {
values = concatMap (def: if getPrio def == highestPrio then [(strip def)] else []) defs;
inherit highestPrio;
};
/* Sort a list of properties. The sort priority of a property is /* Sort a list of properties. The sort priority of a property is
1000 by default, but can be overridden by wrapping the property 1000 by default, but can be overridden by wrapping the property