From b62298f7c777fb966b05cbc327615fdfe53d57c2 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 23 Nov 2008 00:19:06 +0000 Subject: [PATCH] Add a common pattern used in jobs definition. svn path=/nixpkgs/trunk/; revision=13370 --- pkgs/lib/default.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix index e5247c57267..95fe7ae9c46 100644 --- a/pkgs/lib/default.nix +++ b/pkgs/lib/default.nix @@ -233,6 +233,16 @@ rec { optionalString = cond: string: if cond then string else ""; + # Return the second argument if the first one is true or the empty version + # of the second argument. + ifEnable = cond: val: + if cond then val + else if builtins.isList val then [] + else if builtins.isAttrs val then {} + # else if builtins.isString val then "" + # else if builtins.isBoolean val then false + else null; + # Return a list of integers from `first' up to and including `last'. range = first: last: if builtins.lessThan last first