Refactor neovim config into separate modules

This commit is contained in:
Bad 2022-06-29 00:02:00 +02:00
parent a783855706
commit 3e9863bb6a
13 changed files with 234 additions and 200 deletions

View file

@ -0,0 +1,61 @@
{ lib, pkgs, config, ... }@inputs:
with lib;
let
cfg = config.mae.nvim;
in
{
imports = [
./go.nix
./rust.nix
./web_dev.nix
./other_langs.nix
];
options.mae.nvim = {
enable = mkEnableOption "enable neovim";
};
config = {
programs.neovim = mkIf cfg.enable {
enable = true;
vimdiffAlias = true;
plugins = with pkgs.vimPlugins; [
neoformat
undotree
fzf-vim
{
plugin = iceberg-vim;
config = "colorscheme iceberg";
}
vim-sleuth
];
extraConfig = ''
set background=dark
set termguicolors
set ic
set number
set autoindent
set completeopt=menuone,noinsert,noselect
set shortmess+=c
'';
coc.pluginConfig = ''
nmap <silent> <F2> <Plug>(coc-rename)
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
'';
};
};
}

View file

@ -0,0 +1,17 @@
{ lib, pkgs, config, ... }:
let
cfg = config.mae.nvim.go;
in
with lib;
{
options.mae.nvim.go = {
enable = mkEnableOption "Enable go support in nvim";
};
config.programs.neovim = mkIf cfg.enable {
coc.enable = true;
plugins = with pkgs.vimPlugins; [
pkgs.go-fold-if-err-nil
coc-go
];
};
}

View file

@ -0,0 +1,68 @@
{ lib, pkgs, config, ... }:
let
cfg = config.mae.nvim;
in
with lib;
{
imports = [
# Lua
({ ... }: {
options.mae.nvim.lua.enable = mkEnableOption "Enable lua support in nvim";
config.programs.neovim = mkIf cfg.lua.enable
{
coc.enable = true;
coc.settings.languageserver.lua = mkIf cfg.lua.enable {
command = "${pkgs.sumneko-lua-language-server}/bin/lua-language-server";
rootPatterns = [ ".git" ];
filetypes = [
"lua"
];
};
};
})
# Nix
({ ... }: {
options.mae.nvim.nix.enable = mkEnableOption "Enable nix support in nvim";
config.programs.neovim = mkIf cfg.nix.enable
{
plugins = with pkgs.vimPlugins; [
vim-nix
];
coc.enable = true;
coc.settings.languageserver.nix = mkIf cfg.nix.enable {
"command" = "${pkgs.rnix-lsp}/bin/rnix-lsp";
"filetypes" = [
"nix"
];
};
};
})
# Clangd
({ ... }: {
options.mae.nvim.clangd.enable = mkEnableOption "Enable clangd support in nvim";
config.programs.neovim = mkIf cfg.clangd.enable
{
plugins = with pkgs.vimPlugins; [
coc-clangd
];
coc.enable = true;
coc.settings = {
"clangd.checkUpdates" = false;
# Use whatever clangd is in path for dependency reasons I think I don't remember at this point
"clangd.path" = "clangd";
};
};
})
# Python
({ ... }: {
options.mae.nvim.python.enable = mkEnableOption "Enable python support in nvim";
config.programs.neovim = mkIf cfg.python.enable
{
coc.enable = true;
plugins = with pkgs.vimPlugins; [
coc-pyright
];
};
})
];
}

View file

@ -0,0 +1,23 @@
{ lib, pkgs, config, ... }:
let
cfg = config.mae.nvim.rust;
in
with lib;
{
options.mae.nvim.rust = {
enable = mkEnableOption "Enable rust support in nvim";
};
config.programs.neovim = mkIf cfg.enable {
coc.enable = true;
plugins = with pkgs.vimPlugins; [
coc-rust-analyzer
];
coc.settings = {
"rust-analyzer.server.path" = "${pkgs.rust-analyzer-nightly}/bin/rust-analyzer";
"rust-analyzer.updates.prompt" = false;
"rust-analyzer.updates.checkOnStartup" = false;
"rust-analyzer.cargo.loadOutDirsFromCheck" = true;
"rust-analyzer.procMacro.enable" = true;
};
};
}

View file

@ -0,0 +1,41 @@
{ lib, pkgs, config, ... }:
let
cfg = config.mae.nvim;
in
with lib;
{
options.mae.nvim.web = {
enable = mkEnableOption "Enable webdev support in nvim";
};
options.mae.nvim.js = {
enable = mkEnableOption "Enable js/ts support in nvim";
};
config = mkMerge [
(mkIf cfg.js.enable {
programs.neovim = {
coc.enable = true;
plugins = with pkgs.vimPlugins; [
coc-tsserver
{
plugin = vim-jsdoc;
config = ''
let g:jsdoc_formatter = "tsdoc"
let g:typescript_indent_disable = 1
'';
}
];
};
})
(mkIf cfg.web.enable {
mae.nvim.js.enable = true;
programs.neovim = {
coc.enable = true;
plugins = with pkgs.vimPlugins; [
coc-emmet
coc-html
];
};
})
];
}

View file

@ -177,6 +177,7 @@ in
};
}
(lib.mkIf cfg.dockerSocket.enable {
home.sessionVariables."DOCKER_HOST" = "unix:///run/user/$UID/podman/podman.sock"; })
home.sessionVariables."DOCKER_HOST" = "unix:///run/user/$UID/podman/podman.sock";
})
]);
}

View file

@ -1,187 +1,10 @@
{ pkgs, config, ... }@inputs:
{
programs.neovim = {
mae.nvim = {
enable = true;
vimdiffAlias = true;
withNodeJs = true;
plugins = with pkgs.vimPlugins; [
{
plugin = coc-nvim;
config = ''
nmap <silent> <F2> <Plug>(coc-rename)
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
'';
}
fzf-vim
{
plugin = iceberg-vim;
config = "colorscheme iceberg";
}
{
plugin = nvim-dap;
config = ''
lua <<EOF
local dap = require'dap'
dap.adapters.go = function(callback, config)
local stdout = vim.loop.new_pipe(false)
local handle
local pid_or_err
local port = 38697
local opts = {
stdio = {nil, stdout},
args = {"dap", "-l", "127.0.0.1:" .. port},
detached = true
}
handle, pid_or_err = vim.loop.spawn("dlv", opts, function(code)
stdout:close()
handle:close()
if code ~= 0 then
print('dlv exited with code', code)
end
end)
assert(handle, 'Error running dlv: ' .. tostring(pid_or_err))
stdout:read_start(function(err, chunk)
assert(not err, err)
if chunk then
vim.schedule(function()
require('dap.repl').append(chunk)
end)
end
end)
-- Wait for delve to start
vim.defer_fn(
function()
callback({type = "server", host = "127.0.0.1", port = port})
end,
100)
end
-- https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md
dap.configurations.go = {
-- works with go.mod packages and sub packages
{
type = "go",
name = "Debug (go.mod)",
request = "launch",
program = "''${workspaceFolder}"
},
{
type = "go",
name = "Debug test (go.mod)",
request = "launch",
mode = "test",
program = "''${workspaceFolder}"
},
{
type = "go",
name = "Debug",
request = "launch",
program = "''${file}"
},
{
type = "go",
name = "Debug test", -- configuration for debugging test files
request = "launch",
mode = "test",
program = "''${file}"
},
}
EOF
nnoremap <silent> <F5> :lua require'dap'.continue()<CR>
nnoremap <silent> <F10> :lua require'dap'.step_over()<CR>
nnoremap <silent> <F11> :lua require'dap'.step_into()<CR>
nnoremap <silent> <F12> :lua require'dap'.step_out()<CR>
nnoremap <silent> <leader>b :lua require'dap'.toggle_breakpoint()<CR>
nnoremap <silent> <leader>B :lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR>
nnoremap <silent> <leader>lp :lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR>
nnoremap <silent> <leader>dr :lua require'dap'.repl.open()<CR>
nnoremap <silent> <leader>dl :lua require'dap'.run_last()<CR>
'';
}
{
plugin = nvim-dap-ui;
config = "lua require('dapui').setup()";
}
vim-sleuth
vim-nix
pkgs.go-fold-if-err-nil
coc-json
coc-emmet
coc-go
coc-html
coc-rust-analyzer
coc-pyright
coc-tsserver
coc-clangd
coc-lua
kotlin-vim
neoformat
undotree
{
plugin = vim-jsdoc;
config = ''
let g:jsdoc_formatter = "tsdoc"
let g:typescript_indent_disable = 1
'';
}
];
extraConfig = ''
set background=dark
set termguicolors
set ic
set number
set autoindent
set completeopt=menuone,noinsert,noselect
set shortmess+=c
'';
coc.enable = true;
coc.settings = {
"coc.preferences.formatOnSaveFiletypes" = [
"css"
"markdown"
"javascript"
"typescript"
];
"prettier.useTabs" = true;
"rust-analyzer.server.path" = "${pkgs.rust-analyzer-nightly}/bin/rust-analyzer";
"rust-analyzer.updates.prompt" = false;
"rust-analyzer.updates.checkOnStartup" = false;
"rust-analyzer.cargo.loadOutDirsFromCheck" = true;
"rust-analyzer.procMacro.enable" = true;
"clangd.checkUpdates" = false;
"clangd.path" = "clangd";
"svelte.plugin.svelte.format.enable" = false;
"languageserver" = {
"nix" = {
"command" = "${pkgs.rnix-lsp}/bin/rnix-lsp";
"filetypes" = [
"nix"
];
};
"lua" = {
"command" = "${pkgs.sumneko-lua-language-server}/bin/lua-language-server";
"rootPatterns" = [ ".git" ];
"filetypes" = [
"lua"
];
};
};
};
js.enable = true;
nix.enable = true;
rust.enable = true;
clangd.enable = true;
};
}