mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
lib/helpers: factor out nixvimUtils
This commit is contained in:
parent
98dbe8a89b
commit
7164a89f72
3 changed files with 35 additions and 45 deletions
|
@ -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
|
||||||
|
|
|
@ -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
28
lib/utils.nix
Normal 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
|
||||||
|
'';
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue