2023-02-20 11:42:13 +01:00
|
|
|
{lib, ...}:
|
2023-10-02 15:44:06 +02:00
|
|
|
with lib; rec {
|
2023-12-22 15:59:41 +01:00
|
|
|
maintainers = import ./maintainers.nix;
|
2023-10-02 15:44:06 +02:00
|
|
|
keymaps = import ./keymap-helpers.nix {inherit lib;};
|
2023-11-14 19:24:54 +01:00
|
|
|
autocmd = import ./autocmd-helpers.nix {inherit lib;};
|
2024-01-24 22:49:29 +01:00
|
|
|
vim-plugin = import ./vim-plugin.nix {inherit lib mkPackageOption;};
|
2023-01-24 01:28:01 +00:00
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
# Black functional magic that converts a bunch of different Nix types to their
|
|
|
|
# lua equivalents!
|
|
|
|
toLuaObject = args:
|
|
|
|
if builtins.isAttrs args
|
|
|
|
then
|
|
|
|
if hasAttr "__raw" args
|
|
|
|
then args.__raw
|
|
|
|
else if hasAttr "__empty" args
|
|
|
|
then "{ }"
|
|
|
|
else
|
|
|
|
"{"
|
|
|
|
+ (concatStringsSep ","
|
|
|
|
(mapAttrsToList
|
|
|
|
(n: v:
|
2023-10-09 08:50:21 -05:00
|
|
|
if (builtins.match "__unkeyed.*" n) != null
|
2023-10-02 15:44:06 +02:00
|
|
|
then toLuaObject v
|
|
|
|
else if n == "__emptyString"
|
|
|
|
then "[''] = " + (toLuaObject v)
|
|
|
|
else "[${toLuaObject n}] = " + (toLuaObject v))
|
|
|
|
(filterAttrs
|
|
|
|
(
|
|
|
|
n: v:
|
|
|
|
v != null && (toLuaObject v != "{}")
|
|
|
|
)
|
|
|
|
args)))
|
|
|
|
+ "}"
|
|
|
|
else if builtins.isList args
|
|
|
|
then "{" + concatMapStringsSep "," toLuaObject args + "}"
|
|
|
|
else if builtins.isString args
|
|
|
|
then
|
|
|
|
# This should be enough!
|
|
|
|
builtins.toJSON args
|
|
|
|
else if builtins.isPath args
|
|
|
|
then builtins.toJSON (toString args)
|
|
|
|
else if builtins.isBool args
|
|
|
|
then "${boolToString args}"
|
|
|
|
else if builtins.isFloat args
|
|
|
|
then "${toString args}"
|
|
|
|
else if builtins.isInt args
|
|
|
|
then "${toString args}"
|
|
|
|
else if (args == null)
|
|
|
|
then "nil"
|
|
|
|
else "";
|
2023-04-03 11:25:37 +02:00
|
|
|
|
2023-10-15 17:31:03 +02:00
|
|
|
listToUnkeyedAttrs = list:
|
|
|
|
builtins.listToAttrs
|
|
|
|
(lib.lists.imap0 (idx: lib.nameValuePair "__unkeyed-${toString idx}") list);
|
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
emptyTable = {"__empty" = null;};
|
2023-08-10 14:44:45 +02:00
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
# Creates an option with a nullable type that defaults to null.
|
|
|
|
mkNullOrOption = type: desc:
|
|
|
|
lib.mkOption {
|
|
|
|
type = lib.types.nullOr type;
|
|
|
|
default = null;
|
|
|
|
description = desc;
|
|
|
|
};
|
2023-01-24 01:28:01 +00:00
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
mkIfNonNull' = x: y: (mkIf (x != null) y);
|
2023-03-10 12:06:32 +01:00
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
mkIfNonNull = x: (mkIfNonNull' x x);
|
2023-03-10 12:06:32 +01:00
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
ifNonNull' = x: y:
|
|
|
|
if (x == null)
|
|
|
|
then null
|
|
|
|
else y;
|
2023-03-10 12:06:32 +01:00
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
mkCompositeOption = desc: options:
|
|
|
|
mkNullOrOption (types.submodule {inherit options;}) desc;
|
2023-03-06 23:45:38 +01:00
|
|
|
|
2024-01-06 18:26:34 +01:00
|
|
|
mkNullOrStr = mkNullOrOption (with nixvimTypes; maybeRaw str);
|
|
|
|
|
2024-01-01 20:28:55 +01:00
|
|
|
mkNullOrLua = desc:
|
|
|
|
lib.mkOption {
|
2024-01-01 23:32:55 +01:00
|
|
|
type = lib.types.nullOr nixvimTypes.strLua;
|
2024-01-01 20:28:55 +01:00
|
|
|
default = null;
|
|
|
|
description = desc;
|
|
|
|
apply = mkRaw;
|
|
|
|
};
|
|
|
|
|
2024-01-01 23:32:55 +01:00
|
|
|
mkNullOrLuaFn = desc:
|
|
|
|
lib.mkOption {
|
|
|
|
type = lib.types.nullOr nixvimTypes.strLuaFn;
|
|
|
|
default = null;
|
|
|
|
description = desc;
|
|
|
|
apply = mkRaw;
|
|
|
|
};
|
2024-01-01 20:28:55 +01:00
|
|
|
|
2024-01-02 00:30:10 +01:00
|
|
|
mkNullOrStrLuaOr = ty: desc:
|
|
|
|
lib.mkOption {
|
|
|
|
type = lib.types.nullOr (types.either nixvimTypes.strLua ty);
|
|
|
|
default = null;
|
|
|
|
description = desc;
|
|
|
|
apply = v:
|
|
|
|
if builtins.isString v
|
|
|
|
then mkRaw v
|
|
|
|
else v;
|
|
|
|
};
|
|
|
|
|
|
|
|
mkNullOrStrLuaFnOr = ty: desc:
|
|
|
|
lib.mkOption {
|
|
|
|
type = lib.types.nullOr (types.either nixvimTypes.strLuaFn ty);
|
|
|
|
default = null;
|
|
|
|
description = desc;
|
|
|
|
apply = v:
|
|
|
|
if builtins.isString v
|
|
|
|
then mkRaw v
|
|
|
|
else v;
|
|
|
|
};
|
|
|
|
|
2024-01-01 23:15:15 +01:00
|
|
|
defaultNullOpts = rec {
|
2023-10-02 15:44:06 +02:00
|
|
|
mkNullable = type: default: desc:
|
|
|
|
mkNullOrOption type (
|
|
|
|
let
|
|
|
|
defaultDesc = "default: `${default}`";
|
2023-02-20 11:42:13 +01:00
|
|
|
in
|
|
|
|
if desc == ""
|
|
|
|
then defaultDesc
|
|
|
|
else ''
|
|
|
|
${desc}
|
2023-10-02 15:44:06 +02:00
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
${defaultDesc}
|
2023-10-02 15:44:06 +02:00
|
|
|
''
|
|
|
|
);
|
2023-01-24 01:28:01 +00:00
|
|
|
|
2023-12-22 16:55:50 +01:00
|
|
|
mkNullableWithRaw = type: mkNullable (maybeRaw type);
|
|
|
|
|
2024-01-02 00:30:10 +01:00
|
|
|
mkStrLuaOr = type: default: desc:
|
|
|
|
mkNullOrStrLuaOr type (let
|
|
|
|
defaultDesc = "default: `${default}`";
|
|
|
|
in
|
|
|
|
if desc == ""
|
|
|
|
then defaultDesc
|
|
|
|
else ''
|
|
|
|
${desc}
|
|
|
|
|
|
|
|
${defaultDesc}
|
|
|
|
'');
|
|
|
|
|
|
|
|
mkStrLuaFnOr = type: default: desc:
|
|
|
|
mkNullOrStrLuaFnOr type (let
|
|
|
|
defaultDesc = "default: `${default}`";
|
|
|
|
in
|
|
|
|
if desc == ""
|
|
|
|
then defaultDesc
|
|
|
|
else ''
|
|
|
|
${desc}
|
|
|
|
|
|
|
|
${defaultDesc}
|
|
|
|
'');
|
|
|
|
|
2024-01-01 20:44:50 +01:00
|
|
|
mkLua = default: desc:
|
2024-01-01 20:28:55 +01:00
|
|
|
mkNullOrLua
|
|
|
|
(
|
|
|
|
(optionalString (desc != "") ''
|
|
|
|
${desc}
|
2024-01-01 20:44:50 +01:00
|
|
|
|
2024-01-01 20:28:55 +01:00
|
|
|
'')
|
|
|
|
+ ''
|
|
|
|
default: `${default}`
|
|
|
|
''
|
|
|
|
);
|
2023-12-29 15:24:42 +01:00
|
|
|
|
2024-01-01 20:28:55 +01:00
|
|
|
mkLuaFn = default: desc: let
|
|
|
|
defaultDesc = "default: `${default}`";
|
|
|
|
in
|
|
|
|
mkNullOrLuaFn
|
|
|
|
(
|
|
|
|
if desc == ""
|
|
|
|
then defaultDesc
|
|
|
|
else ''
|
|
|
|
${desc}
|
2023-12-29 15:24:42 +01:00
|
|
|
|
2024-01-01 20:28:55 +01:00
|
|
|
${defaultDesc}
|
|
|
|
''
|
|
|
|
);
|
2023-12-29 15:24:42 +01:00
|
|
|
|
2024-01-01 23:15:15 +01:00
|
|
|
mkNum = default: mkNullable (with nixvimTypes; maybeRaw number) (toString default);
|
|
|
|
mkInt = default: mkNullable (with nixvimTypes; maybeRaw int) (toString default);
|
2023-10-02 15:44:06 +02:00
|
|
|
# Positive: >0
|
2024-01-01 23:15:15 +01:00
|
|
|
mkPositiveInt = default: mkNullable (with nixvimTypes; maybeRaw ints.positive) (toString default);
|
2023-10-02 15:44:06 +02:00
|
|
|
# Unsigned: >=0
|
2024-01-01 23:15:15 +01:00
|
|
|
mkUnsignedInt = default: mkNullable (with nixvimTypes; maybeRaw ints.unsigned) (toString default);
|
2023-10-02 15:44:06 +02:00
|
|
|
mkBool = default:
|
2024-01-01 23:15:15 +01:00
|
|
|
mkNullable (with nixvimTypes; maybeRaw bool) (
|
2023-10-02 15:44:06 +02:00
|
|
|
if default
|
|
|
|
then "true"
|
|
|
|
else "false"
|
|
|
|
);
|
2024-01-01 23:15:15 +01:00
|
|
|
mkStr = default: mkNullable (with nixvimTypes; maybeRaw str) ''${builtins.toString default}'';
|
|
|
|
mkAttributeSet = default: mkNullable nixvimTypes.attrs ''${default}'';
|
|
|
|
mkListOf = ty: default: mkNullable (with nixvimTypes; listOf (maybeRaw ty)) default;
|
|
|
|
mkAttrsOf = ty: default: mkNullable (with nixvimTypes; attrsOf (maybeRaw ty)) default;
|
|
|
|
mkEnum = enumValues: default: mkNullable (with nixvimTypes; maybeRaw (enum enumValues)) ''"${default}"'';
|
|
|
|
mkEnumFirstDefault = enumValues: mkEnum enumValues (head enumValues);
|
2023-10-02 15:44:06 +02:00
|
|
|
mkBorder = default: name: desc:
|
|
|
|
mkNullable
|
2024-01-01 23:49:35 +01:00
|
|
|
nixvimTypes.border
|
2023-10-02 15:44:06 +02:00
|
|
|
default
|
|
|
|
(let
|
|
|
|
defaultDesc = ''
|
|
|
|
Defines the border to use for ${name}.
|
|
|
|
Accepts same border values as `nvim_open_win()`. See `:help nvim_open_win()` for more info.
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
if desc == ""
|
|
|
|
then defaultDesc
|
|
|
|
else ''
|
|
|
|
${desc}
|
|
|
|
${defaultDesc}
|
|
|
|
'');
|
2023-11-28 23:22:20 +01:00
|
|
|
mkSeverity = default: desc:
|
|
|
|
mkOption {
|
|
|
|
type = with types;
|
|
|
|
nullOr
|
|
|
|
(
|
|
|
|
either ints.unsigned
|
|
|
|
(
|
|
|
|
enum
|
|
|
|
["error" "warn" "info" "hint"]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
default = null;
|
|
|
|
apply =
|
|
|
|
mapNullable
|
|
|
|
(
|
|
|
|
value:
|
|
|
|
if isInt value
|
|
|
|
then value
|
|
|
|
else mkRaw "vim.diagnostic.severity.${strings.toUpper value}"
|
|
|
|
);
|
|
|
|
description = let
|
|
|
|
defaultDesc = "default: `${toString default}`";
|
|
|
|
in
|
|
|
|
if desc == ""
|
|
|
|
then defaultDesc
|
|
|
|
else ''
|
|
|
|
${desc}
|
|
|
|
|
2023-11-30 15:48:45 +01:00
|
|
|
${defaultDesc}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
mkLogLevel = default: desc:
|
|
|
|
mkOption {
|
|
|
|
type = with types;
|
|
|
|
nullOr
|
|
|
|
(
|
|
|
|
either ints.unsigned
|
|
|
|
(
|
|
|
|
enum
|
|
|
|
["off" "error" "warn" "info" "debug" "trace"]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
default = null;
|
|
|
|
apply =
|
|
|
|
mapNullable
|
|
|
|
(
|
|
|
|
value:
|
|
|
|
if isInt value
|
|
|
|
then value
|
|
|
|
else mkRaw "vim.log.levels.${strings.toUpper value}"
|
|
|
|
);
|
|
|
|
description = let
|
|
|
|
defaultDesc = "default: `${toString default}`";
|
|
|
|
in
|
|
|
|
if desc == ""
|
|
|
|
then defaultDesc
|
|
|
|
else ''
|
|
|
|
${desc}
|
|
|
|
|
2023-11-28 23:22:20 +01:00
|
|
|
${defaultDesc}
|
|
|
|
'';
|
|
|
|
};
|
2023-01-25 19:46:49 +01:00
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
mkHighlight = default: name: desc:
|
|
|
|
mkNullable
|
2024-01-01 23:47:06 +01:00
|
|
|
nixvimTypes.highlight
|
2023-10-02 15:44:06 +02:00
|
|
|
default
|
|
|
|
(
|
|
|
|
if desc == ""
|
|
|
|
then "Highlight settings."
|
|
|
|
else desc
|
|
|
|
);
|
|
|
|
};
|
2023-02-20 11:42:13 +01:00
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
mkPackageOption = name: default:
|
|
|
|
mkOption {
|
|
|
|
type = types.package;
|
|
|
|
inherit default;
|
|
|
|
description = "Plugin to use for ${name}";
|
|
|
|
};
|
2023-09-10 09:59:22 +02:00
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
extraOptionsOptions = {
|
|
|
|
extraOptions = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = types.attrs;
|
|
|
|
description = ''
|
|
|
|
These attributes will be added to the table parameter for the setup function.
|
|
|
|
(Can override other attributes set by nixvim)
|
|
|
|
'';
|
2023-01-24 01:28:01 +00:00
|
|
|
};
|
2023-10-02 15:44:06 +02:00
|
|
|
};
|
2023-01-24 01:28:01 +00:00
|
|
|
|
2023-11-22 11:19:28 +01:00
|
|
|
mkRaw = r:
|
2023-11-28 09:47:14 +01:00
|
|
|
if (isString r && (r != ""))
|
|
|
|
then {__raw = r;}
|
|
|
|
else null;
|
2023-01-24 01:28:01 +00:00
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
wrapDo = string: ''
|
|
|
|
do
|
|
|
|
${string}
|
|
|
|
end
|
|
|
|
'';
|
2023-01-24 01:28:01 +00:00
|
|
|
|
2024-01-01 23:32:55 +01:00
|
|
|
nixvimTypes = let
|
|
|
|
strLikeType = description:
|
|
|
|
mkOptionType {
|
|
|
|
name = "str";
|
|
|
|
inherit description;
|
|
|
|
descriptionClass = "noun";
|
|
|
|
check = lib.isString;
|
|
|
|
merge = lib.options.mergeEqualOption;
|
|
|
|
};
|
|
|
|
in
|
2024-01-01 23:33:53 +01:00
|
|
|
{
|
|
|
|
rawLua = mkOptionType {
|
2024-01-02 00:26:41 +01:00
|
|
|
name = "rawLua";
|
2024-01-01 23:33:53 +01:00
|
|
|
description = "raw lua code";
|
|
|
|
descriptionClass = "noun";
|
|
|
|
merge = mergeEqualOption;
|
|
|
|
check = isRawType;
|
|
|
|
};
|
2024-01-01 23:47:06 +01:00
|
|
|
|
2024-01-01 23:15:15 +01:00
|
|
|
maybeRaw = type:
|
|
|
|
types.either
|
|
|
|
type
|
|
|
|
nixvimTypes.rawLua;
|
|
|
|
|
2024-01-01 23:49:35 +01:00
|
|
|
border = with types;
|
|
|
|
oneOf [
|
|
|
|
str
|
|
|
|
(listOf str)
|
|
|
|
(listOf (listOf str))
|
|
|
|
];
|
|
|
|
|
2024-01-01 23:47:06 +01:00
|
|
|
highlight = types.submodule {
|
|
|
|
# Adds flexibility for other keys
|
|
|
|
freeformType = types.attrs;
|
|
|
|
|
|
|
|
# :help nvim_set_hl()
|
|
|
|
options = with types; {
|
2024-01-17 14:57:55 +01:00
|
|
|
fg = mkNullOrStr "Color for the foreground (color name or '#RRGGBB').";
|
|
|
|
bg = mkNullOrStr "Color for the background (color name or '#RRGGBB').";
|
|
|
|
sp = mkNullOrStr "Special color (color name or '#RRGGBB').";
|
2024-01-01 23:47:06 +01:00
|
|
|
blend = mkNullOrOption (numbers.between 0 100) "Integer between 0 and 100.";
|
|
|
|
bold = mkNullOrOption bool "";
|
|
|
|
standout = mkNullOrOption bool "";
|
|
|
|
underline = mkNullOrOption bool "";
|
|
|
|
undercurl = mkNullOrOption bool "";
|
|
|
|
underdouble = mkNullOrOption bool "";
|
|
|
|
underdotted = mkNullOrOption bool "";
|
|
|
|
underdashed = mkNullOrOption bool "";
|
|
|
|
strikethrough = mkNullOrOption bool "";
|
|
|
|
italic = mkNullOrOption bool "";
|
|
|
|
reverse = mkNullOrOption bool "";
|
|
|
|
nocombine = mkNullOrOption bool "";
|
2024-01-17 14:57:55 +01:00
|
|
|
link = mkNullOrStr "Name of another highlight group to link to.";
|
2024-01-01 23:47:06 +01:00
|
|
|
default = mkNullOrOption bool "Don't override existing definition.";
|
2024-01-17 14:57:55 +01:00
|
|
|
ctermfg = mkNullOrStr "Sets foreground of cterm color.";
|
|
|
|
ctermbg = mkNullOrStr "Sets background of cterm color.";
|
2024-01-01 23:47:06 +01:00
|
|
|
cterm = mkNullOrOption attrs ''
|
|
|
|
cterm attribute map, like |highlight-args|.
|
|
|
|
If not set, cterm attributes will match those from the attribute map documented above.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2024-01-01 23:32:55 +01:00
|
|
|
|
|
|
|
strLua = strLikeType "lua code string";
|
|
|
|
strLuaFn = strLikeType "lua function string";
|
2024-01-01 23:33:53 +01:00
|
|
|
}
|
|
|
|
# Allow to do `with nixvimTypes;` instead of `with types;`
|
|
|
|
// types;
|
2023-01-24 01:28:01 +00:00
|
|
|
|
2023-10-02 15:44:06 +02:00
|
|
|
isRawType = v: lib.isAttrs v && lib.hasAttr "__raw" v && lib.isString v.__raw;
|
|
|
|
}
|