Make neovim config more composable per-language.

main
Joshua Potter 2023-11-17 11:00:35 -07:00
parent da9b70bb43
commit 0289522665
8 changed files with 162 additions and 124 deletions

View File

@ -1,33 +1,13 @@
args @ { pkgs, ... }: { config, pkgs, lib, ... }:
let let
conf = {
lua = import ./lua.nix args;
nix = import ./nix.nix args;
python = import ./python.nix args;
};
nvim-dap = { nvim-dap = {
plugin = pkgs.vimPlugins.nvim-dap; plugin = pkgs.vimPlugins.nvim-dap;
config = '' config = config.programs.neovim.nvim-dap;
lua << EOF
${builtins.concatStringsSep "\n" (builtins.map (m: "do\n${m}\nend") [
conf.python.nvim-dap
])}
EOF
'';
}; };
nvim-lspconfig = { nvim-lspconfig = {
plugin = pkgs.vimPlugins.nvim-lspconfig; plugin = pkgs.vimPlugins.nvim-lspconfig;
config = '' config = config.programs.neovim.nvim-lspconfig;
lua << EOF
${builtins.concatStringsSep "\n" (builtins.map (m: "do\n${m}\nend") [
conf.lua.nvim-lspconfig
conf.nix.nvim-lspconfig
conf.python.nvim-lspconfig
])}
EOF
'';
}; };
nvim-treesitter = { nvim-treesitter = {
@ -39,7 +19,6 @@ let
] ]
)); ));
config = '' config = ''
lua << EOF
require('nvim-treesitter.configs').setup { require('nvim-treesitter.configs').setup {
auto_install = false, auto_install = false,
highlight = { enable = true }, highlight = { enable = true },
@ -53,29 +32,74 @@ let
}, },
}, },
} }
EOF
''; '';
}; };
in in
{ {
programs.neovim = { options.programs.neovim = {
extraLuaConfig = '' nvim-dap = lib.mkOption {
vim.o.colorcolumn = '80,100' type = lib.types.lines;
vim.o.expandtab = true -- Spaces instead of tabs. example = ''
vim.o.shiftwidth = 2 -- # of spaces to use for each (auto)indent. require('...').nvim_dap()
vim.o.tabstop = 2 -- # of spaces a <Tab> in the file counts for. '';
''; description = lib.mdDoc ''
extraPackages = ( Language-specific configurations for the `nvim-dap` plugin.
conf.lua.extraPackages ++ '';
conf.nix.extraPackages ++ };
conf.python.extraPackages
); nvim-lspconfig = lib.mkOption {
plugins = [ type = lib.types.lines;
nvim-dap example = ''
nvim-lspconfig require('...').nvim_lspconfig()
nvim-treesitter '';
description = lib.mdDoc ''
Language-specific configurations for the `nvim-lspconfig` plugin.
'';
};
};
imports = [
./lang/lua.nix
./lang/nix.nix
./lang/python.nix
];
config = {
programs.neovim = {
plugins = map (p: {
inherit (p) plugin;
config = "lua << EOF\n${p.config}\nEOF";
}) [
nvim-dap
nvim-lspconfig
nvim-treesitter
];
viAlias = true;
vimAlias = true;
};
xdg.configFile."nvim/init.lua".text = lib.mkMerge [
# Extra Lua configuration to be prepended to `init.lua`. Extend the Lua
# loader to search for our /nix/store/.../?.lua files.
(let
lua = pkgs.stdenv.mkDerivation {
name = "lua";
src = ./lua;
installPhase = ''
mkdir -p $out/
cp -r ./* $out/
'';
};
in lib.mkBefore ''
package.path = '${lua}/?.lua;' .. package.path
'')
# Extra Lua configuration to be appended to `init.lua`.
(lib.mkAfter ''
vim.o.colorcolumn = '80,100'
vim.o.expandtab = true -- Spaces instead of tabs.
vim.o.shiftwidth = 2 -- # of spaces to use for each (auto)indent.
vim.o.tabstop = 2 -- # of spaces a <Tab> in the file counts for.
'')
]; ];
viAlias = true;
vimAlias = true;
}; };
} }

View File

@ -0,0 +1,10 @@
{ pkgs, ... }:
{
programs.neovim = {
nvim-lspconfig = ''
require('lspconfig').lua_ls.setup { }
'';
extraPackages = [ pkgs.lua-language-server ];
};
}

View File

@ -0,0 +1,10 @@
{ pkgs, ... }:
{
programs.neovim = {
nvim-lspconfig = ''
require('lspconfig').nil_ls.setup {}
'';
extraPackages = [ pkgs.nil ];
};
}

View File

@ -0,0 +1,26 @@
{ pkgs, ... }:
let
venv = pkgs.python3.withPackages (ps: with ps; [
debugpy
mccabe
pycodestyle
pyflakes
python-lsp-server
python-lsp-black
]);
in
{
programs.neovim = {
nvim-dap = ''
require('init.python').nvim_dap({
command = '${venv}/bin/python3.10',
})
'';
nvim-lspconfig = ''
require('init.python').nvim_lspconfig()
'';
extraPackages = [ venv ];
};
}

View File

@ -1,10 +0,0 @@
{ pkgs, ... }:
{
nvim-lspconfig = ''
require('lspconfig').lua_ls.setup { }
'';
extraPackages = with pkgs; [
lua-language-server
];
}

View File

@ -0,0 +1,49 @@
local module = {}
function module.nvim_dap(options)
local dap = require('dap')
dap.adapters.python = function(callback, config)
callback({
name = 'debugpy',
type = 'executable',
command = options.command,
args = { '-m', 'debugpy.adapter' },
options = {
source_filetype = 'python',
},
})
end
dap.configurations.python = dap.configurations.python or {}
table.insert(dap.configurations.python, {
name = 'Launch',
type = 'python',
request = 'launch',
program = '${file}',
cwd = '${workspaceFolder}',
})
end
function module.nvim_lspconfig()
require('lspconfig').pylsp.setup {
settings = {
pylsp = {
-- `flake8` currently fails in some cases. Prefer the default set of
-- utilities instead.
-- https://github.com/python-lsp/python-lsp-server/pull/434
configurationSources = 'pycodestyle',
plugins = {
autopep8 = { enabled = false },
black = { enabled = true },
mccabe = { enabled = true },
pycodestyle = { enabled = true },
pyflakes = { enabled = true },
yapf = { enabled = false },
},
},
},
}
end
return module

View File

@ -1,10 +0,0 @@
{ pkgs, ... }:
{
nvim-lspconfig = ''
require('lspconfig').nil_ls.setup { }
'';
extraPackages = with pkgs; [
nil
];
}

View File

@ -1,61 +0,0 @@
{ pkgs, ... }:
let
venv = pkgs.python3.withPackages (ps: with ps; [
debugpy
mccabe
pycodestyle
pyflakes
python-lsp-server
python-lsp-black
]);
in
{
nvim-dap = ''
local dap = require('dap')
dap.adapters.python = function(callback, config)
callback({
name = 'debugpy',
type = 'executable',
command = '${venv}/bin/python3.10',
args = { '-m', 'debugpy.adapter' },
options = {
source_filetype = 'python',
},
})
end
dap.configurations.python = dap.configurations.python or {}
table.insert(dap.configurations.python, {
name = 'Launch',
type = 'python',
request = 'launch',
program = "''${file}",
cwd = "''${workspaceFolder}",
})
'';
nvim-lspconfig = ''
require('lspconfig').pylsp.setup {
settings = {
pylsp = {
-- `flake8` currently fails in some cases:
-- https://github.com/python-lsp/python-lsp-server/pull/434
configurationSources = 'pycodestyle',
plugins = {
autopep8 = { enabled = false },
black = { enabled = true },
mccabe = { enabled = true },
pycodestyle = { enabled = true },
pyflakes = { enabled = true },
yapf = { enabled = false },
},
},
},
}
'';
extraPackages = [
venv
];
}