forked from mirrors/nixpkgs
* Get rid of __primop.
* newMergeOptionSets -> mergeOptionSets. svn path=/nixpkgs/trunk/; revision=15652
This commit is contained in:
parent
4b7fc6f5d6
commit
b9d560d30e
|
@ -13,7 +13,7 @@ rec {
|
||||||
|
|
||||||
mkOption = attrs: attrs // {_type = "option";};
|
mkOption = attrs: attrs // {_type = "option";};
|
||||||
|
|
||||||
hasType = x: __isAttrs x && x ? _type;
|
hasType = x: isAttrs x && x ? _type;
|
||||||
typeOf = x: if hasType x then x._type else "";
|
typeOf = x: if hasType x then x._type else "";
|
||||||
|
|
||||||
isOption = attrs: (typeOf attrs) == "option";
|
isOption = attrs: (typeOf attrs) == "option";
|
||||||
|
@ -29,23 +29,23 @@ rec {
|
||||||
if typeOf defValue == "option"
|
if typeOf defValue == "option"
|
||||||
then
|
then
|
||||||
# `defValue' is an option.
|
# `defValue' is an option.
|
||||||
if builtins.hasAttr defName opts
|
if hasAttr defName opts
|
||||||
then builtins.getAttr defName opts
|
then builtins.getAttr defName opts
|
||||||
else defValue.default
|
else defValue.default
|
||||||
else
|
else
|
||||||
# `defValue' is an attribute set containing options.
|
# `defValue' is an attribute set containing options.
|
||||||
# So recurse.
|
# So recurse.
|
||||||
if builtins.hasAttr defName opts && builtins.isAttrs optValue
|
if hasAttr defName opts && isAttrs optValue
|
||||||
then addDefaultOptionValues defValue optValue
|
then addDefaultOptionValues defValue optValue
|
||||||
else addDefaultOptionValues defValue {};
|
else addDefaultOptionValues defValue {};
|
||||||
}
|
}
|
||||||
) (builtins.attrNames defs));
|
) (attrNames defs));
|
||||||
|
|
||||||
mergeDefaultOption = list:
|
mergeDefaultOption = list:
|
||||||
if list != [] && tail list == [] then head list
|
if list != [] && tail list == [] then head list
|
||||||
else if all __isFunction list then x: mergeDefaultOption (map (f: f x) list)
|
else if all builtins.isFunction list then x: mergeDefaultOption (map (f: f x) list)
|
||||||
else if all __isList list then concatLists list
|
else if all isList list then concatLists list
|
||||||
else if all __isAttrs list then fold lib.mergeAttrs {} list
|
else if all isAttrs list then fold lib.mergeAttrs {} list
|
||||||
else if all (x: true == x || false == x) list then fold lib.or false list
|
else if all (x: true == x || false == x) list then fold lib.or false list
|
||||||
else if all (x: x == toString x) list then lib.concatStrings list
|
else if all (x: x == toString x) list then lib.concatStrings list
|
||||||
else throw "Cannot merge values.";
|
else throw "Cannot merge values.";
|
||||||
|
@ -57,15 +57,14 @@ rec {
|
||||||
mergeEnableOption = mergeTypedOption "boolean"
|
mergeEnableOption = mergeTypedOption "boolean"
|
||||||
(x: true == x || false == x) (fold lib.or false);
|
(x: true == x || false == x) (fold lib.or false);
|
||||||
|
|
||||||
mergeListOption = mergeTypedOption "list"
|
mergeListOption = mergeTypedOption "list" isList concatLists;
|
||||||
__isList concatLists;
|
|
||||||
|
|
||||||
mergeStringOption = mergeTypedOption "string"
|
mergeStringOption = mergeTypedOption "string"
|
||||||
(x: if builtins ? isString then builtins.isString x else x + "")
|
(x: if builtins ? isString then builtins.isString x else x + "")
|
||||||
lib.concatStrings;
|
lib.concatStrings;
|
||||||
|
|
||||||
mergeOneOption = list:
|
mergeOneOption = list:
|
||||||
if list == [] then abort "This case should never happens."
|
if list == [] then abort "This case should never happen."
|
||||||
else if tail list != [] then throw "Multiple definitions. Only one is allowed for this option."
|
else if tail list != [] then throw "Multiple definitions. Only one is allowed for this option."
|
||||||
else head list;
|
else head list;
|
||||||
|
|
||||||
|
@ -80,7 +79,7 @@ rec {
|
||||||
# - notHandle is a function which takes the list of values are not handle
|
# - notHandle is a function which takes the list of values are not handle
|
||||||
# by this function.
|
# by this function.
|
||||||
handleOptionSets = optionHandler@{export, notHandle, ...}: path: opts:
|
handleOptionSets = optionHandler@{export, notHandle, ...}: path: opts:
|
||||||
if all __isAttrs opts then
|
if all isAttrs opts then
|
||||||
lib.zip (attr: opts:
|
lib.zip (attr: opts:
|
||||||
let
|
let
|
||||||
# Compute the path to reach the attribute.
|
# Compute the path to reach the attribute.
|
||||||
|
@ -118,8 +117,7 @@ rec {
|
||||||
# all options declare and defined. If no values are defined for an
|
# all options declare and defined. If no values are defined for an
|
||||||
# option, then the default value is used otherwise it use the merge
|
# option, then the default value is used otherwise it use the merge
|
||||||
# function of each option to get the result.
|
# function of each option to get the result.
|
||||||
mergeOptionSets = noOption: newMergeOptionSets; # ignore argument
|
mergeOptionSets =
|
||||||
newMergeOptionSets =
|
|
||||||
handleOptionSets {
|
handleOptionSets {
|
||||||
export = opt: values:
|
export = opt: values:
|
||||||
opt.apply (
|
opt.apply (
|
||||||
|
@ -169,8 +167,8 @@ rec {
|
||||||
# pkgs: config: {..}
|
# pkgs: config: {..}
|
||||||
cfg2 = cfg {} {};
|
cfg2 = cfg {} {};
|
||||||
in
|
in
|
||||||
if __isFunction cfg0 then
|
if builtins.isFunction cfg0 then
|
||||||
if builtins.isAttrs cfg1 then cfg1
|
if isAttrs cfg1 then cfg1
|
||||||
else builtins.trace "Use '{pkgs, config, ...}:'." cfg2
|
else builtins.trace "Use '{pkgs, config, ...}:'." cfg2
|
||||||
else cfg0;
|
else cfg0;
|
||||||
|
|
||||||
|
@ -231,7 +229,7 @@ rec {
|
||||||
)]
|
)]
|
||||||
else (concatLists (map (s: (optionAttrSetToDocList
|
else (concatLists (map (s: (optionAttrSetToDocList
|
||||||
(l + (if l=="" then "" else ".") + s) (builtins.getAttr s attrs)))
|
(l + (if l=="" then "" else ".") + s) (builtins.getAttr s attrs)))
|
||||||
(builtins.attrNames attrs)));
|
(attrNames attrs)));
|
||||||
|
|
||||||
/* Option Properties */
|
/* Option Properties */
|
||||||
# Generalize the problem of delayable properties. Any property can be created
|
# Generalize the problem of delayable properties. Any property can be created
|
||||||
|
@ -396,7 +394,7 @@ rec {
|
||||||
|
|
||||||
/* 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 delayed on sets until a "then-else" or
|
||||||
# "always" set is reached. When an always set is reached the condition
|
# "always" set is reached. When an always set is reached the condition
|
||||||
# is ignore.
|
# is ignore.
|
||||||
|
|
||||||
|
@ -525,8 +523,8 @@ rec {
|
||||||
# Otherwise, the property is kept on all sub-attribute definitions.
|
# Otherwise, the property is kept on all sub-attribute definitions.
|
||||||
onOverrideDelay = name: p@{property, content, ...}:
|
onOverrideDelay = name: p@{property, content, ...}:
|
||||||
let inherit (property) template; in
|
let inherit (property) template; in
|
||||||
if builtins.isAttrs template && template != {} then
|
if isAttrs template && template != {} then
|
||||||
if builtins.hasAttr name template then
|
if hasAttr name template then
|
||||||
p // {
|
p // {
|
||||||
property = p.property // {
|
property = p.property // {
|
||||||
template = builtins.getAttr name template;
|
template = builtins.getAttr name template;
|
||||||
|
|
Loading…
Reference in a new issue