refactor(nvim): clean up nix code
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-12-16 17:44:17 -05:00
parent 6ca0d7248b
commit 6c5ef370c5
13 changed files with 94 additions and 63 deletions

View file

@ -4,7 +4,7 @@
pkgs, pkgs,
... ...
}: let }: let
inherit (lib) getExe mkIf; inherit (lib) attrValues getExe mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
in { in {
@ -20,22 +20,31 @@ in {
viAlias = true; viAlias = true;
vimAlias = true; vimAlias = true;
extraPackages = mkIf cfg.enableIde [ extraPackages = mkIf cfg.enableIde (attrValues {
pkgs.nodePackages.bash-language-server inherit
pkgs.shellcheck (pkgs.nodePackages)
]; bash-language-server
;
inherit
(pkgs)
shellcheck
;
});
extraLuaConfig = extraLuaConfig =
mkIf cfg.enableIde mkIf cfg.enableIde
# lua # lua
'' ''
local default_capabilities = require('cmp_nvim_lsp').default_capabilities();
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
pattern = 'sh', pattern = 'sh',
command = 'setlocal ts=4 sw=4 sts=0 expandtab', command = 'setlocal ts=4 sw=4 sts=0 expandtab',
}); });
require('lspconfig').bashls.setup({ require('lspconfig').bashls.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(), capabilities = default_capabilities,
settings = { settings = {
bashIde = { bashIde = {

View file

@ -4,7 +4,7 @@
pkgs, pkgs,
... ...
}: let }: let
inherit (lib) mkIf; inherit (lib) attrValues mkIf;
inherit (pkgs.writers) writeYAML; inherit (pkgs.writers) writeYAML;
cfg = config.programs.neovim; cfg = config.programs.neovim;
@ -16,7 +16,7 @@ in
programs = { programs = {
neovim = { neovim = {
extraPackages = builtins.attrValues { extraPackages = attrValues {
inherit inherit
(pkgs) (pkgs)
gcc gcc
@ -34,24 +34,30 @@ in
}); });
local lsp = require('lspconfig'); local lsp = require('lspconfig');
local default_capabilities = require('cmp_nvim_lsp').default_capabilities();
local clangd_extensions = require('clangd_extensions.inlay_hints');
lsp.cmake.setup({ lsp.cmake.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(), capabilities = default_capabilities,
}); });
lsp.clangd.setup({ lsp.clangd.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(), capabilities = default_capabilities,
handlers = require('lsp-status').extensions.clangd.setup(), handlers = require('lsp-status').extensions.clangd.setup(),
on_attach = function(_, bufnr) on_attach = function(_, bufnr)
require("clangd_extensions.inlay_hints").setup_autocmd() clangd_extensions.setup_autocmd();
require("clangd_extensions.inlay_hints").set_inlay_hints() clangd_extensions.set_inlay_hints();
end, end,
}); });
''; '';
plugins = builtins.attrValues { plugins = attrValues {
inherit (pkgs.vimPlugins) clangd_extensions-nvim; inherit
(pkgs.vimPlugins)
clangd_extensions-nvim
;
}; };
}; };
}; };

View file

@ -4,14 +4,14 @@
pkgs, pkgs,
... ...
}: let }: let
inherit (lib) mkIf; inherit (lib) attrValues mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
in in
mkIf cfg.enableIde { mkIf cfg.enableIde {
programs = { programs = {
neovim = { neovim = {
extraPackages = builtins.attrValues { extraPackages = attrValues {
inherit inherit
(pkgs) (pkgs)
omnisharp-roslyn omnisharp-roslyn
@ -29,13 +29,13 @@ in
local omnisharp_extended = require('omnisharp_extended'); local omnisharp_extended = require('omnisharp_extended');
require('lspconfig').omnisharp.setup({ require('lspconfig').omnisharp.setup({
cmd = { "dotnet", "${pkgs.omnisharp-roslyn}/lib/omnisharp-roslyn/OmniSharp.dll" }, cmd = { 'dotnet', '${pkgs.omnisharp-roslyn}/lib/omnisharp-roslyn/OmniSharp.dll' },
handlers = { handlers = {
["textDocument/definition"] = omnisharp_extended.definition_handler, ['textDocument/definition'] = omnisharp_extended.definition_handler,
["textDocument/typeDefinition"] = omnisharp_extended.type_definition_handler, ['textDocument/typeDefinition'] = omnisharp_extended.type_definition_handler,
["textDocument/references"] = omnisharp_extended.references_handler, ['textDocument/references'] = omnisharp_extended.references_handler,
["textDocument/implementation"] = omnisharp_extended.implementation_handler, ['textDocument/implementation'] = omnisharp_extended.implementation_handler,
}, },
settings = { settings = {
@ -59,8 +59,11 @@ in
}); });
''; '';
plugins = builtins.attrValues { plugins = attrValues {
inherit (pkgs.vimPlugins) omnisharp-extended-lsp-nvim; inherit
(pkgs.vimPlugins)
omnisharp-extended-lsp-nvim
;
}; };
}; };
}; };

View file

@ -18,6 +18,7 @@ in {
./lua.nix ./lua.nix
./python.nix ./python.nix
./rust.nix ./rust.nix
(import ./markdown.nix self) (import ./markdown.nix self)
(import ./nix.nix self) (import ./nix.nix self)
(import ./web.nix self) (import ./web.nix self)

View file

@ -4,12 +4,12 @@
pkgs, pkgs,
... ...
}: let }: let
inherit (lib) getExe mkIf; inherit (lib) attrValues getExe mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
javaSdk = pkgs.temurin-bin-17; javaSdk = pkgs.temurin-bin-17;
javaPkgs = builtins.attrValues {inherit (pkgs) gradle maven;}; javaPkgs = attrValues {inherit (pkgs) gradle maven;};
in in
mkIf cfg.enableIde { mkIf cfg.enableIde {
home.packages = javaPkgs; home.packages = javaPkgs;

View file

@ -4,14 +4,14 @@
pkgs, pkgs,
... ...
}: let }: let
inherit (lib) mkIf; inherit (lib) attrValues mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
in in
mkIf cfg.enableIde { mkIf cfg.enableIde {
programs = { programs = {
neovim = { neovim = {
extraPackages = builtins.attrValues { extraPackages = attrValues {
inherit inherit
(pkgs) (pkgs)
vscode-langservers-extracted vscode-langservers-extracted
@ -32,13 +32,14 @@ in
}); });
local lsp = require('lspconfig'); local lsp = require('lspconfig');
local default_capabilities = require('cmp_nvim_lsp').default_capabilities();
lsp.jsonls.setup({ lsp.jsonls.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(), capabilities = default_capabilities,
}); });
lsp.yamlls.setup({ lsp.yamlls.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(), capabilities = default_capabilities,
settings = { settings = {
yaml = { yaml = {

View file

@ -4,7 +4,7 @@
pkgs, pkgs,
... ...
}: let }: let
inherit (lib) mkIf; inherit (lib) attrValues mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
@ -13,8 +13,11 @@ in
mkIf cfg.enableIde { mkIf cfg.enableIde {
programs = { programs = {
neovim = { neovim = {
extraPackages = builtins.attrValues { extraPackages = attrValues {
inherit (pkgs) lua-language-server; inherit
(pkgs)
lua-language-server
;
}; };
plugins = [ plugins = [
@ -24,6 +27,8 @@ in
config = config =
# lua # lua
'' ''
local default_capabilities = require('cmp_nvim_lsp').default_capabilities();
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
pattern = 'lua', pattern = 'lua',
command = 'setlocal ts=4 sw=4 sts=0 expandtab', command = 'setlocal ts=4 sw=4 sts=0 expandtab',
@ -40,7 +45,7 @@ in
}); });
require('lspconfig').lua_ls.setup({ require('lspconfig').lua_ls.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(), capabilities = default_capabilities,
}); });
''; '';
} }

View file

@ -8,14 +8,14 @@ self: {
inherit (self.inputs) vimplugin-easytables-src; inherit (self.inputs) vimplugin-easytables-src;
inherit (self.lib.${pkgs.system}) buildPlugin; inherit (self.lib.${pkgs.system}) buildPlugin;
inherit (lib) mkIf; inherit (lib) attrValues mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
in { in {
config = mkIf cfg.enableIde { config = mkIf cfg.enableIde {
programs = { programs = {
neovim = { neovim = {
extraPackages = builtins.attrValues { extraPackages = attrValues {
inherit inherit
(pkgs) (pkgs)
pandoc pandoc

View file

@ -5,7 +5,8 @@ self: {
pkgs, pkgs,
... ...
}: let }: let
inherit (lib) getExe hasPrefix mkIf removePrefix; inherit (builtins) toJSON;
inherit (lib) attrValues getExe hasPrefix mkIf removePrefix;
inherit (osConfig.networking) hostName; inherit (osConfig.networking) hostName;
cfg = config.programs.neovim; cfg = config.programs.neovim;
@ -31,15 +32,17 @@ in {
} }
]; ];
home.packages = [ home.packages = attrValues {
inherit
defaultFormatter defaultFormatter
nixdPkg nixdPkg
]; ;
};
# nixd by default kinda spams LspLog # nixd by default kinda spams LspLog
home.sessionVariables.NIXD_FLAGS = "-log=error"; home.sessionVariables.NIXD_FLAGS = "-log=error";
xdg.dataFile."${flakeDir}/.nixd.json".text = builtins.toJSON { xdg.dataFile."${flakeDir}/.nixd.json".text = toJSON {
nixpkgs = { nixpkgs = {
expr = "import (builtins.getFlake \"${flakeDir}\").inputs.nixpkgs {}"; expr = "import (builtins.getFlake \"${flakeDir}\").inputs.nixpkgs {}";
}; };
@ -50,9 +53,9 @@ in {
programs = { programs = {
neovim = { neovim = {
extraPackages = [ extraPackages = attrValues {
nixdPkg inherit nixdPkg;
]; };
extraLuaConfig = extraLuaConfig =
# lua # lua

View file

@ -4,31 +4,33 @@
pkgs, pkgs,
... ...
}: let }: let
inherit (lib) mkIf; inherit (lib) attrValues mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
in in {
mkIf cfg.enableIde { config = mkIf cfg.enableIde {
programs = { programs = {
neovim = { neovim = {
withPython3 = true; withPython3 = true;
extraPython3Packages = py: extraPython3Packages = py:
with py; ([ (attrValues {
python-lsp-server inherit (py) python-lsp-server;
] })
++ python-lsp-server.optional-dependencies.all); ++ py.python-lsp-server.optional-dependencies.all;
extraPackages = with pkgs.python3Packages; ([ extraPackages =
python-lsp-server (attrValues {
] inherit (pkgs.python3Packages) python-lsp-server;
++ python-lsp-server.optional-dependencies.all); })
++ pkgs.python3Packages.python-lsp-server.optional-dependencies.all;
extraLuaConfig = extraLuaConfig =
# lua # lua
'' ''
require('lspconfig').pylsp.setup({ require('lspconfig').pylsp.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(), capabilities = require('cmp_nvim_lsp').default_capabilities(),
settings = { settings = {
pylsp = { pylsp = {
plugins = { plugins = {
@ -42,4 +44,5 @@ in
''; '';
}; };
}; };
};
} }

View file

@ -7,7 +7,7 @@ self: {
inherit (self.inputs) vimplugin-ts-error-translator-src; inherit (self.inputs) vimplugin-ts-error-translator-src;
inherit (self.lib.${pkgs.system}) buildPlugin; inherit (self.lib.${pkgs.system}) buildPlugin;
inherit (lib) mkIf; inherit (lib) attrValues mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
in { in {
@ -16,7 +16,7 @@ in {
neovim = { neovim = {
withNodeJs = true; withNodeJs = true;
extraPackages = builtins.attrValues { extraPackages = attrValues {
inherit inherit
(pkgs) (pkgs)
neovim-node-client neovim-node-client