mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-27 05:43:50 +03:00
Remove mkThenElse and mkAlways
This commit is contained in:
parent
2b4fba3d03
commit
9a92f3fc35
@ -25,7 +25,7 @@ rec {
|
|||||||
# contains a _type attribute and a list of functions which are used to
|
# contains a _type attribute and a list of functions which are used to
|
||||||
# evaluate this property. The content attribute is used to stack properties
|
# evaluate this property. The content attribute is used to stack properties
|
||||||
# on top of each other.
|
# on top of each other.
|
||||||
#
|
#
|
||||||
# The optional functions which may be contained in the property attribute
|
# The optional functions which may be contained in the property attribute
|
||||||
# are:
|
# are:
|
||||||
# - onDelay: run on a copied property.
|
# - onDelay: run on a copied property.
|
||||||
@ -41,7 +41,7 @@ rec {
|
|||||||
# property and call the function `nul' on the final value which is not a
|
# property and call the function `nul' on the final value which is not a
|
||||||
# property. The stack is traversed in reversed order. The `op' function
|
# property. The stack is traversed in reversed order. The `op' function
|
||||||
# should expect a property with a content which have been modified.
|
# should expect a property with a content which have been modified.
|
||||||
#
|
#
|
||||||
# Warning: The `op' function expects only one argument in order to avoid
|
# Warning: The `op' function expects only one argument in order to avoid
|
||||||
# calls to mkProperties as the argument is already a valid property which
|
# calls to mkProperties as the argument is already a valid property which
|
||||||
# contains the result of the folding inside the content attribute.
|
# contains the result of the folding inside the content attribute.
|
||||||
@ -225,45 +225,11 @@ rec {
|
|||||||
inherit content;
|
inherit content;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Create a "ThenElse" property which contains choices being chosen by
|
|
||||||
# the evaluation of an "If" statement.
|
|
||||||
isThenElse = attrs: (typeOf attrs) == "then-else";
|
|
||||||
mkThenElse = attrs:
|
|
||||||
assert attrs ? thenPart && attrs ? elsePart;
|
|
||||||
__trace "Obsolete usage of mkThenElse, replace it by mkMerge."
|
|
||||||
mkProperty {
|
|
||||||
property = {
|
|
||||||
_type = "then-else";
|
|
||||||
onEval = val: throw "Missing mkIf statement.";
|
|
||||||
inherit (attrs) thenPart elsePart;
|
|
||||||
};
|
|
||||||
content = mkNotdef;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Create an "Always" property removing/ ignoring all "If" statement.
|
|
||||||
isAlways = attrs: (typeOf attrs) == "always";
|
|
||||||
mkAlways = value:
|
|
||||||
mkProperty {
|
|
||||||
property = {
|
|
||||||
_type = "always";
|
|
||||||
onEval = p@{content, ...}: content;
|
|
||||||
inherit value;
|
|
||||||
};
|
|
||||||
content = mkNotdef;
|
|
||||||
};
|
|
||||||
|
|
||||||
mkAssert = assertion: message: content:
|
mkAssert = assertion: message: content:
|
||||||
mkIf
|
mkIf
|
||||||
(if assertion then true else throw "\nFailed assertion: ${message}")
|
(if assertion then true else throw "\nFailed assertion: ${message}")
|
||||||
content;
|
content;
|
||||||
|
|
||||||
# Remove all "If" statement defined on a value.
|
|
||||||
rmIf = foldProperty (
|
|
||||||
foldFilter isIf
|
|
||||||
({content, ...}: content)
|
|
||||||
id
|
|
||||||
) id;
|
|
||||||
|
|
||||||
# Evaluate the "If" statements when either "ThenElse" or "Always"
|
# Evaluate the "If" statements when either "ThenElse" or "Always"
|
||||||
# statement is encountered. Otherwise it removes multiple If statements and
|
# statement is encountered. Otherwise it removes multiple If statements and
|
||||||
# replaces them by one "If" statement where the condition is the list of all
|
# replaces them by one "If" statement where the condition is the list of all
|
||||||
@ -274,8 +240,8 @@ rec {
|
|||||||
# in the attribute list and attrs.
|
# in the attribute list and attrs.
|
||||||
ifProps =
|
ifProps =
|
||||||
foldProperty
|
foldProperty
|
||||||
(foldFilter (p: isIf p || isThenElse p || isAlways p)
|
(foldFilter (p: isIf p)
|
||||||
# then, push the codition inside the list list
|
# then, push the condition inside the list list
|
||||||
(p@{property, content, ...}:
|
(p@{property, content, ...}:
|
||||||
{ inherit (content) attrs;
|
{ inherit (content) attrs;
|
||||||
list = [property] ++ content.list;
|
list = [property] ++ content.list;
|
||||||
@ -297,19 +263,7 @@ rec {
|
|||||||
mkIf condition content
|
mkIf condition content
|
||||||
else
|
else
|
||||||
let p = head list; in
|
let p = head list; in
|
||||||
|
evalIf content (condition && p.condition) (tail list);
|
||||||
# evaluate the condition.
|
|
||||||
if isThenElse p then
|
|
||||||
if condition then
|
|
||||||
copyProperties content p.thenPart
|
|
||||||
else
|
|
||||||
copyProperties content p.elsePart
|
|
||||||
# ignore the condition.
|
|
||||||
else if isAlways p then
|
|
||||||
copyProperties content p.value
|
|
||||||
# otherwise (isIf)
|
|
||||||
else
|
|
||||||
evalIf content (condition && p.condition) (tail list);
|
|
||||||
in
|
in
|
||||||
evalIf ifProps.attrs true ifProps.list;
|
evalIf ifProps.attrs true ifProps.list;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user