modules: explicit lib usage

This commit is contained in:
raf 2024-02-20 02:05:36 +03:00
commit caf342adb1
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
27 changed files with 673 additions and 684 deletions

105
lib/binds.nix Normal file
View file

@ -0,0 +1,105 @@
{lib}: let
inherit (lib.options) mkOption;
inherit (lib.modules) mkIf;
inherit (lib.types) nullOr str submodule bool;
inherit (lib.attrsets) isAttrs mapAttrs attrsOf;
in rec {
# mkLuaBinding creates a binding with Lua and silent flags.
#
# Arguments:
# - key: The name of the binding.
# - action: The action to be performed when the binding is activated.
# - desc: The description of the binding.
mkLuaBinding = key: action: desc:
mkIf (key != null) {
"${key}" = {
inherit action desc;
lua = true;
silent = true;
};
};
# mkExprBinding creates a binding with Lua, silent, and expr flags.
#
# Arguments:
# - key: The name of the binding.
# - action: The action to be performed when the binding is activated.
# - desc: The description of the binding.
mkExprBinding = key: action: desc:
mkIf (key != null) {
"${key}" = {
inherit action desc;
lua = true;
silent = true;
expr = true;
};
};
# mkBinding creates a binding with silent flag.
#
# Arguments:
# - key: The name of the binding.
# - action: The action to be performed when the binding is activated.
# - desc: The description of the binding.
mkBinding = key: action: desc:
mkIf (key != null) {
"${key}" = {
inherit action desc;
silent = true;
};
};
# mkMappingOption creates an option that can be null or a string.
#
# Arguments:
# - description: The description of the option.
# - default: The default value of the option.
mkMappingOption = description: default:
mkOption {
type = nullOr str;
inherit default description;
};
# Utility function that takes two attrsets:
# { someKey = "some_value" } and
# { someKey = { description = "Some Description"; }; }
# and merges them into
# { someKey = { value = "some_value"; description = "Some Description"; }; }
addDescriptionsToMappings = actualMappings: mappingDefinitions:
mapAttrs (name: value: let
isNested = isAttrs value;
returnedValue =
if isNested
then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}"
else {
inherit value;
inherit (mappingDefinitions."${name}") description;
};
in
returnedValue)
actualMappings;
# mkSetBinding creates a binding with the provided action and description.
#
# Arguments:
# - binding: The binding to be set.
# - action: The action to be performed when the binding is activated.
mkSetBinding = binding: action:
mkBinding binding.value action binding.description;
# mkSetExprBinding creates an expression binding with the provided action and description.
#
# Arguments:
# - binding: The binding to be set.
# - action: The action to be performed when the binding is activated.
mkSetExprBinding = binding: action:
mkExprBinding binding.value action binding.description;
# mkSetLuaBinding creates a Lua binding with the provided action and description.
#
# Arguments:
# - binding: The binding to be set.
# - action: The action to be performed when the binding is activated.
mkSetLuaBinding = binding: action:
mkLuaBinding binding.value action binding.description;
}

View file

@ -1,8 +1,10 @@
{lib}: { {lib}: {
modules = import ./modules.nix {inherit lib;};
dag = import ./dag.nix {inherit lib;};
types = import ./types {inherit lib;}; types = import ./types {inherit lib;};
binds = import ./binds.nix {inherit lib;};
dag = import ./dag.nix {inherit lib;};
languages = import ./languages.nix {inherit lib;}; languages = import ./languages.nix {inherit lib;};
lua = import ./lua.nix {inherit lib;}; lua = import ./lua.nix {inherit lib;};
modules = import ./modules.nix {inherit lib;};
vim = import ./vim.nix {inherit lib;}; vim = import ./vim.nix {inherit lib;};
} }

View file

@ -4,70 +4,9 @@
nixpkgsLib: let nixpkgsLib: let
mkNvimLib = import ./.; mkNvimLib = import ./.;
in in
nixpkgsLib.extend (self: super: rec { nixpkgsLib.extend (self: super: {
nvim = mkNvimLib {lib = self;}; nvim = mkNvimLib {lib = self;};
mkLuaBinding = key: action: desc:
self.mkIf (key != null) {
"${key}" = {
inherit action desc;
lua = true;
silent = true;
};
};
mkExprBinding = key: action: desc:
self.mkIf (key != null) {
"${key}" = {
inherit action desc;
lua = true;
silent = true;
expr = true;
};
};
mkBinding = key: action: desc:
self.mkIf (key != null) {
"${key}" = {
inherit action desc;
silent = true;
};
};
mkMappingOption = description: default:
self.mkOption {
type = self.types.nullOr self.types.str;
inherit default description;
};
# Utility function that takes two attrsets:
# { someKey = "some_value" } and
# { someKey = { description = "Some Description"; }; }
# and merges them into
# { someKey = { value = "some_value"; description = "Some Description"; }; }
addDescriptionsToMappings = actualMappings: mappingDefinitions:
self.attrsets.mapAttrs (name: value: let
isNested = self.isAttrs value;
returnedValue =
if isNested
then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}"
else {
value = value;
description = mappingDefinitions."${name}".description;
};
in
returnedValue)
actualMappings;
mkSetBinding = binding: action:
mkBinding binding.value action binding.description;
mkSetExprBinding = binding: action:
mkExprBinding binding.value action binding.description;
mkSetLuaBinding = binding: action:
mkLuaBinding binding.value action binding.description;
# For forward compatibility. # For forward compatibility.
literalExpression = super.literalExpression or super.literalExample; literalExpression = super.literalExpression or super.literalExample;
}) })

View file

@ -39,13 +39,12 @@
core = map (p: ./core + "/${p}") [ core = map (p: ./core + "/${p}") [
"build" "build"
"mappings"
"warnings" "warnings"
]; ];
neovim = map (p: ./neovim + "/${p}") [ neovim = map (p: ./neovim + "/${p}") [
"basic" "basic"
"maps" "mappings"
"spellcheck" "spellcheck"
]; ];

View file

@ -1,7 +1,7 @@
{lib, ...}: let {lib, ...}: let
inherit (lib) mkOption types; inherit (lib.types) submodule str bool attrsOf nullOr;
inherit (lib) nvim; inherit (lib.options) mkOption;
inherit (nvim.modules) mkBoolOption; inherit (lib.nvim.modules) mkBoolOption;
# Most of the keybindings code is highly inspired by pta2002/nixvim. Thank you! # Most of the keybindings code is highly inspired by pta2002/nixvim. Thank you!
mapConfigOptions = { mapConfigOptions = {
@ -30,23 +30,23 @@
"Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default."; "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default.";
desc = mkOption { desc = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = null; default = null;
description = "A description of this keybind, to be shown in which-key, if you have it enabled."; description = "A description of this keybind, to be shown in which-key, if you have it enabled.";
}; };
}; };
mapOption = types.submodule { mapOption = submodule {
options = options =
mapConfigOptions mapConfigOptions
// { // {
action = mkOption { action = mkOption {
type = types.str; type = str;
description = "The action to execute."; description = "The action to execute.";
}; };
lua = mkOption { lua = mkOption {
type = types.bool; type = bool;
description = '' description = ''
If true, `action` is considered to be lua code. If true, `action` is considered to be lua code.
Thus, it will not be wrapped in `""`. Thus, it will not be wrapped in `""`.
@ -59,14 +59,14 @@
mapOptions = mode: mapOptions = mode:
mkOption { mkOption {
description = "Mappings for ${mode} mode"; description = "Mappings for ${mode} mode";
type = types.attrsOf mapOption; type = attrsOf mapOption;
default = {}; default = {};
}; };
in { in {
options = { options = {
vim = { vim = {
maps = mkOption { maps = mkOption {
type = types.submodule { type = submodule {
options = { options = {
normal = mapOptions "normal"; normal = mapOptions "normal";
insert = mapOptions "insert"; insert = mapOptions "insert";

View file

@ -1,11 +1,15 @@
{ {
pkgs,
config, config,
lib, lib,
... ...
}: let }: let
inherit (builtins) toJSON; inherit (builtins) toJSON;
inherit (lib) mkIf nvim mkLuaBinding mkMerge; inherit (lib.trivial) boolToString toString;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.strings) optionalString;
inherit (lib.lists) optionals;
inherit (lib.nvim.binds) mkLuaBinding;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.assistant.copilot; cfg = config.vim.assistant.copilot;
@ -22,21 +26,22 @@
''; '';
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = vim = {
startPlugins =
[ [
"copilot-lua" "copilot-lua"
cfg.copilotNodePackage cfg.copilotNodePackage
] ]
++ lib.optionals (cfg.cmp.enable) [ ++ optionals cfg.cmp.enable [
"copilot-cmp" "copilot-cmp"
]; ];
vim.luaConfigRC.copilot = nvim.dag.entryAnywhere '' luaConfigRC.copilot = entryAnywhere ''
require("copilot").setup({ require("copilot").setup({
-- available options: https://github.com/zbirenbaum/copilot.lua -- available options: https://github.com/zbirenbaum/copilot.lua
copilot_node_command = "${cfg.copilotNodeCommand}", copilot_node_command = "${cfg.copilotNodeCommand}",
panel = { panel = {
enabled = ${lib.boolToString (!cfg.cmp.enable)}, enabled = ${boolToString (!cfg.cmp.enable)},
keymap = { keymap = {
jump_prev = false, jump_prev = false,
jump_next = false, jump_next = false,
@ -50,7 +55,7 @@ in {
}, },
}, },
suggestion = { suggestion = {
enabled = ${lib.boolToString (!cfg.cmp.enable)}, enabled = ${boolToString (!cfg.cmp.enable)},
keymap = { keymap = {
accept = false, accept = false,
accept_word = false, accept_word = false,
@ -62,12 +67,13 @@ in {
}, },
}) })
${lib.optionalString (cfg.cmp.enable) '' ${optionalString cfg.cmp.enable ''
require("copilot_cmp").setup() require("copilot_cmp").setup()
''} ''}
''; '';
vim.maps.normal = mkMerge [ maps = {
normal = mkMerge [
(mkLuaBinding cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion") (mkLuaBinding cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion")
(mkLuaBinding cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion") (mkLuaBinding cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion")
(mkLuaBinding cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion") (mkLuaBinding cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion")
@ -78,7 +84,7 @@ in {
cfg.mappings.panel.open) "[copilot] Accept suggestion") cfg.mappings.panel.open) "[copilot] Accept suggestion")
]; ];
vim.maps.insert = mkMerge [ insert = mkMerge [
(mkLuaBinding cfg.mappings.suggestion.accept "require(\"copilot.suggestion\").accept" "[copilot] Accept suggestion") (mkLuaBinding cfg.mappings.suggestion.accept "require(\"copilot.suggestion\").accept" "[copilot] Accept suggestion")
(mkLuaBinding cfg.mappings.suggestion.acceptLine "require(\"copilot.suggestion\").accept_line" "[copilot] Accept suggestion (line)") (mkLuaBinding cfg.mappings.suggestion.acceptLine "require(\"copilot.suggestion\").accept_line" "[copilot] Accept suggestion (line)")
(mkLuaBinding cfg.mappings.suggestion.acceptWord "require(\"copilot.suggestion\").accept_word" "[copilot] Accept suggestion (word)") (mkLuaBinding cfg.mappings.suggestion.acceptWord "require(\"copilot.suggestion\").accept_word" "[copilot] Accept suggestion (word)")
@ -87,4 +93,6 @@ in {
(mkLuaBinding cfg.mappings.suggestion.dismiss "require(\"copilot.suggestion\").dismiss" "[copilot] dismiss suggestion") (mkLuaBinding cfg.mappings.suggestion.dismiss "require(\"copilot.suggestion\").dismiss" "[copilot] dismiss suggestion")
]; ];
}; };
};
};
} }

View file

@ -4,7 +4,9 @@
lib, lib,
... ...
}: let }: let
inherit (lib) mkEnableOption mkOption types; inherit (lib.types) enum float nullOr package str;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.meta) getExe;
cfg = config.vim.assistant.copilot; cfg = config.vim.assistant.copilot;
in { in {
@ -14,7 +16,7 @@ in {
panel = { panel = {
position = mkOption { position = mkOption {
type = types.enum [ type = enum [
"bottom" "bottom"
"top" "top"
"left" "left"
@ -24,7 +26,7 @@ in {
description = "Panel position"; description = "Panel position";
}; };
ratio = mkOption { ratio = mkOption {
type = types.float; type = float;
default = 0.4; default = 0.4;
description = "Panel size"; description = "Panel size";
}; };
@ -33,81 +35,81 @@ in {
mappings = { mappings = {
panel = { panel = {
jumpPrev = mkOption { jumpPrev = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = "[["; default = "[[";
description = "Jump to previous suggestion"; description = "Jump to previous suggestion";
}; };
jumpNext = mkOption { jumpNext = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = "]]"; default = "]]";
description = "Jump to next suggestion"; description = "Jump to next suggestion";
}; };
accept = mkOption { accept = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = "<CR>"; default = "<CR>";
description = "Accept suggestion"; description = "Accept suggestion";
}; };
refresh = mkOption { refresh = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = "gr"; default = "gr";
description = "Refresh suggestions"; description = "Refresh suggestions";
}; };
open = mkOption { open = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = "<M-CR>"; default = "<M-CR>";
description = "Open suggestions"; description = "Open suggestions";
}; };
}; };
suggestion = { suggestion = {
accept = mkOption { accept = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = "<M-l>"; default = "<M-l>";
description = "Accept suggetion"; description = "Accept suggetion";
}; };
acceptWord = mkOption { acceptWord = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = null; default = null;
description = "Accept next word"; description = "Accept next word";
}; };
acceptLine = mkOption { acceptLine = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = null; default = null;
description = "Accept next line"; description = "Accept next line";
}; };
prev = mkOption { prev = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = "<M-[>"; default = "<M-[>";
description = "Previous suggestion"; description = "Previous suggestion";
}; };
next = mkOption { next = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = "<M-]>"; default = "<M-]>";
description = "Next suggestion"; description = "Next suggestion";
}; };
dismiss = mkOption { dismiss = mkOption {
type = types.nullOr types.str; type = nullOr str;
default = "<C-]>"; default = "<C-]>";
description = "Dismiss suggestion"; description = "Dismiss suggestion";
}; };
}; };
}; };
copilotNodeCommand = mkOption {
type = types.str;
default = "${lib.getExe cfg.copilotNodePackage}";
description = ''
The command that will be executed to initiate nodejs for GitHub Copilot.
Recommended to leave as default.
'';
};
copilotNodePackage = mkOption { copilotNodePackage = mkOption {
type = with types; nullOr package; type = nullOr package;
default = pkgs.nodejs-slim; default = pkgs.nodejs-slim;
description = '' description = ''
The nodeJS package that will be used for GitHub Copilot. If you are using a custom node command The nodeJS package that will be used for GitHub Copilot. If you are using a custom node command
you may want to set this option to null so that the package is not pulled from nixpkgs. you may want to set this option to null so that the package is not pulled from nixpkgs.
''; '';
}; };
copilotNodeCommand = mkOption {
type = str;
default = "${getExe cfg.copilotNodePackage}";
description = ''
The command that will be executed to initiate nodejs for GitHub Copilot.
Recommended to leave as default.
'';
};
}; };
} }

View file

@ -1,6 +1,5 @@
_: { {
imports = [ imports = [
./copilot ./copilot
# ./tabnine.nix # removed until I find a way around the initialisation script the plugin requires
]; ];
} }

View file

@ -1,54 +0,0 @@
{
config,
lib,
...
}: let
inherit (builtins) toJSON;
inherit (lib) mkIf mkMerge mkExprBinding boolToString nvim;
cfg = config.vim.assistant.tabnine;
in {
config = mkIf cfg.enable {
vim.startPlugins = ["tabnine-nvim"];
vim.maps.insert = mkMerge [
(mkExprBinding cfg.mappings.accept ''
function()
local state = require("tabnine.state")
local completion = require("tabnine.completion")
if not state.completions_cache then
return "${toJSON cfg.mappings.accept}"
end
vim.schedule(completion.accept)
end
'' "orzel")
(mkExprBinding cfg.mappings.dismiss ''
function()
local state = require("tabnine.state")
local completion = require("tabnine.completion")
if not state.completions_cache then
return "${toJSON cfg.mappings.dismiss}"
end
vim.schedule(function()
completion.clear()
state.completions_cache = nil
end)
end
'' "orzel")
];
vim.luaConfigRC.tabnine-nvim = nvim.dag.entryAnywhere ''
require('tabnine').setup({
disable_auto_comment = ${boolToString cfg.disable_auto_comment},
accept_keymap = null,
dismiss_keymap = null,
debounce_ms = ${cfg.debounce_ms},
exclude_filetypes = ${cfg.exclude_filetypes},
})
'';
};
}

View file

@ -1,6 +0,0 @@
_: {
imports = [
./config.nix
./tabnine.nix
];
}

View file

@ -1,30 +0,0 @@
{lib, ...}: let
inherit (lib) mkEnableOption mkOption types mkMappingOption;
in {
options.vim.assistant.tabnine = {
enable = mkEnableOption "Tabnine assistant";
disable_auto_comment = mkOption {
type = types.bool;
default = true;
description = "Disable auto comment";
};
mappings = {
accept = mkMappingOption "Accept [Tabnine]" "<Tab>";
dismiss = mkMappingOption "Dismiss [Tabnine]" "<C-]>";
};
debounce_ms = mkOption {
type = types.int;
default = 800;
description = "Debounce ms";
};
exclude_filetypes = mkOption {
type = types.listOf types.str;
default = ["TelescopePrompt" "NvimTree" "alpha"];
description = "Exclude filetypes";
};
};
}

View file

@ -1,4 +1,4 @@
_: { {
imports = [ imports = [
./nvim-autopairs ./nvim-autopairs
]; ];

View file

@ -1,18 +1,20 @@
{ {
lib,
config, config,
lib,
... ...
}: let }: let
inherit (lib) mkIf nvim optionalString boolToString; inherit (lib.strings) optionalString;
inherit (lib.trivial) boolToString;
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.autopairs; cfg = config.vim.autopairs;
in { in {
config = config = mkIf cfg.enable {
mkIf (cfg.enable) vim = {
{ startPlugins = ["nvim-autopairs"];
vim.startPlugins = ["nvim-autopairs"];
vim.luaConfigRC.autopairs = nvim.dag.entryAnywhere '' luaConfigRC.autopairs = entryAnywhere ''
require("nvim-autopairs").setup{} require("nvim-autopairs").setup{}
${optionalString (config.vim.autocomplete.type == "nvim-compe") '' ${optionalString (config.vim.autocomplete.type == "nvim-compe") ''
require('nvim-autopairs.completion.compe').setup({ require('nvim-autopairs.completion.compe').setup({
@ -23,4 +25,5 @@ in {
''} ''}
''; '';
}; };
};
} }

View file

@ -1,4 +1,4 @@
_: { {
imports = [ imports = [
./config.nix ./config.nix
./nvim-autopairs.nix ./nvim-autopairs.nix

View file

@ -1,31 +1,37 @@
{lib, ...}: let {lib, ...}: let
inherit (lib) mkEnableOption mkOption types; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.tyoes) enum bool;
in { in {
options.vim = { options.vim = {
autopairs = { autopairs = {
enable = mkEnableOption "autopairs" // {default = false;}; enable = mkEnableOption "autopairs";
type = mkOption { type = mkOption {
type = types.enum ["nvim-autopairs"]; type = enum ["nvim-autopairs"];
default = "nvim-autopairs"; default = "nvim-autopairs";
description = "Set the autopairs type. Options: nvim-autopairs [nvim-autopairs]"; description = ''
Set the autopairs type.
Options:
- nvim-autopairs [nvim-autopairs]
'';
}; };
nvim-compe = { nvim-compe = {
map_cr = mkOption { map_cr = mkOption {
type = types.bool; type = bool;
default = true; default = true;
description = ''map <CR> on insert mode''; description = ''map <CR> on insert mode'';
}; };
map_complete = mkOption { map_complete = mkOption {
type = types.bool; type = bool;
default = true; default = true;
description = "auto insert `(` after select function or method item"; description = "auto insert `(` after select function or method item";
}; };
auto_select = mkOption { auto_select = mkOption {
type = types.bool; type = bool;
default = false; default = false;
description = "auto select first item"; description = "auto select first item";
}; };

View file

@ -1,8 +1,9 @@
{lib, ...}: let {lib, ...}: let
inherit (lib) mkEnableOption mkMappingOption; inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption;
in { in {
options.vim.comments.comment-nvim = { options.vim.comments.comment-nvim = {
enable = mkEnableOption "smart and powerful comment plugin for neovim comment-nvim"; enable = mkEnableOption "smart and powerful comment plugin for neovim [comment-nvim]";
mappings = { mappings = {
toggleCurrentLine = mkMappingOption "Toggle current line comment" "gcc"; toggleCurrentLine = mkMappingOption "Toggle current line comment" "gcc";

View file

@ -1,4 +1,4 @@
_: { {
imports = [ imports = [
./comment-nvim ./comment-nvim
]; ];

View file

@ -1,4 +1,4 @@
_: { {
imports = [ imports = [
./nvim-cmp ./nvim-cmp
]; ];

View file

@ -4,8 +4,11 @@
... ...
}: let }: let
inherit (builtins) toJSON; inherit (builtins) toJSON;
inherit (lib) addDescriptionsToMappings concatMapStringsSep attrNames concatStringsSep mapAttrsToList mkIf mkSetLuaBinding mkMerge optionalString; inherit (lib.binds) addDescriptionsToMappings mkSetLuaBinding;
inherit (lib.nvim) dag; inherit (lib.strings) concatMapStringsSep concatStringsSep optionalString;
inherit (lib.attrsets) attrNames mapAttrsToList;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.dag) entryAfter entryAnywhere;
cfg = config.vim.autocomplete; cfg = config.vim.autocomplete;
lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable; lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable;
@ -33,11 +36,12 @@
dagPlacement = dagPlacement =
if lspkindEnabled if lspkindEnabled
then dag.entryAfter ["lspkind"] then entryAfter ["lspkind"]
else dag.entryAnywhere; else entryAnywhere;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = [ vim = {
startPlugins = [
"nvim-cmp" "nvim-cmp"
"cmp-buffer" "cmp-buffer"
"cmp-vsnip" "cmp-vsnip"
@ -45,7 +49,7 @@ in {
"vim-vsnip" "vim-vsnip"
]; ];
vim.autocomplete.sources = { autocomplete.sources = {
"nvim-cmp" = null; "nvim-cmp" = null;
"vsnip" = "[VSnip]"; "vsnip" = "[VSnip]";
"buffer" = "[Buffer]"; "buffer" = "[Buffer]";
@ -54,7 +58,8 @@ in {
"copilot" = "[Copilot]"; "copilot" = "[Copilot]";
}; };
vim.maps.insert = mkMerge [ maps = {
insert = mkMerge [
(mkSetLuaBinding mappings.complete '' (mkSetLuaBinding mappings.complete ''
require('cmp').complete require('cmp').complete
'') '')
@ -119,7 +124,7 @@ in {
'') '')
]; ];
vim.maps.command = mkMerge [ command = mkMerge [
(mkSetLuaBinding mappings.complete '' (mkSetLuaBinding mappings.complete ''
require('cmp').complete require('cmp').complete
'') '')
@ -134,7 +139,7 @@ in {
'') '')
]; ];
vim.maps.select = mkMerge [ select = mkMerge [
(mkSetLuaBinding mappings.next '' (mkSetLuaBinding mappings.next ''
function() function()
local cmp = require('cmp') local cmp = require('cmp')
@ -176,10 +181,11 @@ in {
end end
'') '')
]; ];
};
# TODO: alternative snippet engines to vsnip # TODO: alternative snippet engines to vsnip
# https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L82 # https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L82
vim.luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement '' luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement ''
local nvim_cmp_menu_map = function(entry, vim_item) local nvim_cmp_menu_map = function(entry, vim_item)
-- name for each source -- name for each source
vim_item.menu = ({ vim_item.menu = ({
@ -195,7 +201,7 @@ in {
local cmp = require'cmp' local cmp = require'cmp'
cmp.setup({ cmp.setup({
${optionalString (config.vim.ui.borders.enable) '' ${optionalString config.vim.ui.borders.enable ''
-- explicitly enabled by setting ui.borders.enable = true -- explicitly enabled by setting ui.borders.enable = true
-- TODO: try to get nvim-cmp to follow global border style -- TODO: try to get nvim-cmp to follow global border style
window = { window = {
@ -233,9 +239,10 @@ in {
''} ''}
''); '');
vim.snippets.vsnip.enable = snippets.vsnip.enable =
if (cfg.type == "nvim-cmp") if (cfg.type == "nvim-cmp")
then true then true
else config.vim.snippets.vsnip.enable; else config.vim.snippets.vsnip.enable;
}; };
};
} }

View file

@ -1,4 +1,4 @@
_: { {
imports = [ imports = [
./config.nix ./config.nix
./nvim-cmp.nix ./nvim-cmp.nix

View file

@ -1,9 +1,10 @@
{lib, ...}: let {lib, ...}: let
inherit (lib) mkEnableOption mkMappingOption mkOption types; inherit (lib.types) enum nullOr attrsOf str;
inherit (lib) mkEnableOption mkMappingOption mkOption;
in { in {
options.vim = { options.vim = {
autocomplete = { autocomplete = {
enable = mkEnableOption "enable autocomplete" // {default = false;}; enable = mkEnableOption "enable autocomplete";
mappings = { mappings = {
complete = mkMappingOption "Complete [nvim-cmp]" "<C-Space>"; complete = mkMappingOption "Complete [nvim-cmp]" "<C-Space>";
@ -16,9 +17,14 @@ in {
}; };
type = mkOption { type = mkOption {
type = types.enum ["nvim-cmp"]; type = enum ["nvim-cmp"];
default = "nvim-cmp"; default = "nvim-cmp";
description = "Set the autocomplete plugin. Options: [nvim-cmp]"; description = ''
Set the autocomplete plugin.
Options:
- [nvim-cmp]
'';
}; };
sources = mkOption { sources = mkOption {
@ -31,7 +37,7 @@ in {
Note: only use a single attribute name per attribute set Note: only use a single attribute name per attribute set
''; '';
type = with types; attrsOf (nullOr str); type = attrsOf (nullOr str);
default = {}; default = {};
example = '' example = ''
{nvim-cmp = null; buffer = "[Buffer]";} {nvim-cmp = null; buffer = "[Buffer]";}
@ -48,9 +54,9 @@ in {
Default is to call the menu mapping function. Default is to call the menu mapping function.
''; '';
type = types.str; type = str;
default = "nvim_cmp_menu_map"; default = "nvim_cmp_menu_map";
example = lib.literalMD '' example = ''
```lua ```lua
function(entry, vim_item) function(entry, vim_item)
return vim_item return vim_item

View file

@ -1,11 +1,7 @@
{ {lib, ...}: let
config, inherit (lib.options) mkEnableOption;
lib,
...
}: let
inherit (lib) mkEnableOption;
in { in {
options.vim.dashboard.alpha = { options.vim.dashboard.alpha = {
enable = mkEnableOption "dashboard via alpha.nvim"; enable = mkEnableOption "dashboard [alpha-nvim]";
}; };
} }

View file

@ -3,19 +3,21 @@
lib, lib,
... ...
}: let }: let
inherit (lib) mkIf nvim; inherit (lib.options) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.dashboard.alpha; cfg = config.vim.dashboard.alpha;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = [ vim = {
startPlugins = [
"alpha-nvim" "alpha-nvim"
"nvim-web-devicons" "nvim-web-devicons"
]; ];
# the entire credit for this dashboard configuration to https://github.com/Rishabh672003 # the entire credit for this dashboard configuration to https://github.com/Rishabh672003
# honestly, excellent work # honestly, excellent work
vim.luaConfigRC.alpha = nvim.dag.entryAnywhere '' luaConfigRC.alpha = entryAnywhere ''
local alpha = require("alpha") local alpha = require("alpha")
local plenary_path = require("plenary.path") local plenary_path = require("plenary.path")
local dashboard = require("alpha.themes.dashboard") local dashboard = require("alpha.themes.dashboard")
@ -216,4 +218,5 @@ in {
alpha.setup(config) alpha.setup(config)
''; '';
}; };
};
} }

View file

@ -1,4 +1,4 @@
_: { {
imports = [ imports = [
./alpha.nix ./alpha.nix
./config.nix ./config.nix

View file

@ -3,17 +3,20 @@
lib, lib,
... ...
}: let }: let
inherit (lib) mkIf nvim; inherit (lib.options) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.dashboard.dashboard-nvim; cfg = config.vim.dashboard.dashboard-nvim;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = [ vim = {
startPlugins = [
"dashboard-nvim" "dashboard-nvim"
]; ];
vim.luaConfigRC.dashboard-nvim = nvim.dag.entryAnywhere '' luaConfigRC.dashboard-nvim = entryAnywhere ''
require("dashboard").setup{} require("dashboard").setup{}
''; '';
}; };
};
} }

View file

@ -1,4 +1,4 @@
{...}: { {
imports = [ imports = [
./alpha ./alpha
./dashboard-nvim ./dashboard-nvim