Fix evaluation of environment.variables

This commit is contained in:
Eelco Dolstra 2013-10-28 17:37:28 +01:00
parent 9a8516438e
commit e28ea1239f
2 changed files with 10 additions and 6 deletions

View File

@ -143,7 +143,7 @@ rec {
let let
# Process mkOverride properties, adding in the default # Process mkOverride properties, adding in the default
# value specified in the option declaration (if any). # value specified in the option declaration (if any).
defsFinal = filterOverrides defsFinal = filterOverrides'
((if opt ? default then [{ file = head opt.declarations; value = mkOptionDefault opt.default; }] else []) ++ defs); ((if opt ? default then [{ file = head opt.declarations; value = mkOptionDefault opt.default; }] else []) ++ defs);
# Type-check the remaining definitions, and merge them if # Type-check the remaining definitions, and merge them if
# possible. # possible.
@ -229,7 +229,7 @@ rec {
Note that "z" has the default priority 100. Note that "z" has the default priority 100.
*/ */
filterOverrides = defs: 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;
@ -238,6 +238,9 @@ rec {
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 concatMap (def: if getPrio def == highestPrio then [(strip def)] else []) defs;
/* For use in options like environment.variables. */
filterOverrides = defs: map (def: def.value) (filterOverrides' (map (def: { value = def; }) defs));
/* Hack for backward compatibility: convert options of type /* Hack for backward compatibility: convert options of type
optionSet to configOf. FIXME: remove eventually. */ optionSet to configOf. FIXME: remove eventually. */
fixupOptionType = loc: opt: fixupOptionType = loc: opt:

View File

@ -26,10 +26,11 @@ in
type = types.attrsOf (mkOptionType { type = types.attrsOf (mkOptionType {
name = "a string or a list of strings"; name = "a string or a list of strings";
merge = xs: merge = xs:
if isList (head xs) then concatLists xs let xs' = filterOverrides xs; in
else if builtins.lessThan 1 (length xs) then abort "variable in environment.variables has multiple values" if isList (head xs') then concatLists xs'
else if !builtins.isString (head xs) then abort "variable in environment.variables does not have a string value" else if builtins.lessThan 1 (length xs') then abort "variable in environment.variables has multiple values"
else head xs; else if !builtins.isString (head xs') then abort "variable in environment.variables does not have a string value"
else head xs';
}); });
apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v); apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
}; };