Skip to content

Commit

Permalink
lib/helpers: factor out nixvimUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Jan 25, 2024
1 parent 98dbe8a commit 7164a89
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 45 deletions.
45 changes: 4 additions & 41 deletions lib/helpers.nix
Original file line number Diff line number Diff line change
@@ -1,44 +1,7 @@
{lib, ...}:
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
'';
};

{lib, ...}: let
nixvimTypes = import ./types.nix {inherit lib nixvimOptions;};
nixvimOptions = import ./options.nix {
inherit lib;
inherit
(misc)
mkIf
mkIfNonNull
mkRaw
;
inherit nixvimTypes;
};
nixvimUtils = import ./utils.nix {inherit lib;};
nixvimOptions = import ./options.nix {inherit lib nixvimTypes nixvimUtils;};
in
{
maintainers = import ./maintainers.nix;
Expand All @@ -48,5 +11,5 @@ in
inherit (import ./to-lua.nix {inherit lib;}) toLuaObject;
inherit nixvimTypes;
}
// misc
// nixvimUtils
// nixvimOptions
7 changes: 3 additions & 4 deletions lib/options.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
lib,
mkIf,
mkIfNonNull,
mkRaw,
nixvimTypes,
nixvimUtils,
}:
with lib; rec {
with lib;
with nixvimUtils; rec {
# Creates an option with a nullable type that defaults to null.
mkNullOrOption = type: desc:
lib.mkOption {
Expand Down
28 changes: 28 additions & 0 deletions lib/utils.nix
Original file line number Diff line number Diff line change
@@ -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
'';
}

0 comments on commit 7164a89

Please sign in to comment.