add lib.strings.conditionalString

main
Felix Stupp 1 month ago
parent b80ebe6811
commit 79fd0353cb
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -13,6 +13,7 @@ nixpkgs.lib
math = ./math.nix; math = ./math.nix;
modules = ./modules.nix; modules = ./modules.nix;
network = ./network.nix; network = ./network.nix;
strings = ./strings.nix;
types = ./types.nix; types = ./types.nix;
x-banananetwork-unused = ./unused.nix; x-banananetwork-unused = ./unused.nix;
} }

@ -0,0 +1,32 @@
{ lib, ... }@flakeArg:
let
inherit (builtins)
isAttrs
isBool
isList
isNull
isString
typeOf
;
inherit (lib.strings) optionalString;
in
{
conditionalString =
cond:
optionalString (
if isNull cond then
false
else if isBool cond then
cond
else if isString cond then
cond != ""
else if isList cond then
cond != [ ]
else if isAttrs cond then
cond.enable or (cond != { })
else
throw "unexpected type of condition ${typeOf cond}"
);
}
Loading…
Cancel
Save