lib/helpers: factor out nixvimUtils

This commit is contained in:
Gaetan Lepage 2024-01-25 16:58:58 +01:00 committed by Gaétan Lepage
parent 98dbe8a89b
commit 7164a89f72
3 changed files with 35 additions and 45 deletions

28
lib/utils.nix Normal file
View file

@ -0,0 +1,28 @@
{lib}:
with lib; {
listToUnkeyedAttrs = list:
builtins.listToAttrs
(lib.lists.imap0 (idx: lib.nameValuePair "__unkeyed-${toString idx}") list);
emptyTable = {"__empty" = null;};
mkIfNonNull' = x: y: (mkIf (x != null) y);
mkIfNonNull = x: (mkIfNonNull' x x);
ifNonNull' = x: y:
if (x == null)
then null
else y;
mkRaw = r:
if (isString r && (r != ""))
then {__raw = r;}
else null;
wrapDo = string: ''
do
${string}
end
'';
}