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

View file

@ -1,44 +1,7 @@
{lib, ...}: {lib, ...}: let
with lib; let
misc = {
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
'';
};
nixvimTypes = import ./types.nix {inherit lib nixvimOptions;}; nixvimTypes = import ./types.nix {inherit lib nixvimOptions;};
nixvimOptions = import ./options.nix { nixvimUtils = import ./utils.nix {inherit lib;};
inherit lib; nixvimOptions = import ./options.nix {inherit lib nixvimTypes nixvimUtils;};
inherit
(misc)
mkIf
mkIfNonNull
mkRaw
;
inherit nixvimTypes;
};
in in
{ {
maintainers = import ./maintainers.nix; maintainers = import ./maintainers.nix;
@ -48,5 +11,5 @@ in
inherit (import ./to-lua.nix {inherit lib;}) toLuaObject; inherit (import ./to-lua.nix {inherit lib;}) toLuaObject;
inherit nixvimTypes; inherit nixvimTypes;
} }
// misc // nixvimUtils
// nixvimOptions // nixvimOptions

View file

@ -1,11 +1,10 @@
{ {
lib, lib,
mkIf,
mkIfNonNull,
mkRaw,
nixvimTypes, nixvimTypes,
nixvimUtils,
}: }:
with lib; rec { with lib;
with nixvimUtils; rec {
# Creates an option with a nullable type that defaults to null. # Creates an option with a nullable type that defaults to null.
mkNullOrOption = type: desc: mkNullOrOption = type: desc:
lib.mkOption { lib.mkOption {

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
'';
}