From 7b2265b90671fee0ecae4dd5574b001108c4d486 Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Wed, 15 May 2024 17:37:03 +0200 Subject: [PATCH] Add more lsp support, completions in nvim via coq --- common/tooling/default.nix | 60 ++----------------------------- common/tooling/lsp.nix | 68 +++++++++++++++++++++++++++++++++++ common/tooling/nix.nix | 8 +++-- common/tooling/nvim.nix | 74 ++++++++++++++++++++++++++++++++++++++ common/tooling/python.nix | 6 ++++ common/tooling/rust.nix | 27 ++++++++++++++ 6 files changed, 183 insertions(+), 60 deletions(-) create mode 100644 common/tooling/lsp.nix create mode 100644 common/tooling/nvim.nix create mode 100644 common/tooling/rust.nix diff --git a/common/tooling/default.nix b/common/tooling/default.nix index 729cc6e..cf577ce 100644 --- a/common/tooling/default.nix +++ b/common/tooling/default.nix @@ -13,7 +13,6 @@ let getExe optionals mkIf - concatLines ; in { @@ -22,6 +21,9 @@ in ./nix.nix ./security.nix ./python.nix + ./rust.nix + ./nvim.nix + ./lsp.nix ]; config = mkIf (enable && tooling.enable) { @@ -35,14 +37,11 @@ in urlencode pstree - dos2unix - treefmt file wget hyfetch util-linux btop - neovim-remote linuxPackages.perf eza @@ -82,7 +81,6 @@ in config = { init.defaultBranch = "main"; credential.username = tooling.git_user; - core.editor = getExe pkgs.neovim; user.name = tooling.git_user; user.email = tooling.git_email; push.autoSetupRemote = true; @@ -113,46 +111,9 @@ in services.dbus.implementation = "broker"; - grimmShared.tooling.nvim = { - plugins = with pkgs.vimPlugins; [ - fugitive - nvim-lspconfig - ]; - }; - boot.tmp.cleanOnBoot = true; zramSwap.enable = true; - programs.neovim = { - enable = true; - viAlias = true; - defaultEditor = true; - configure = { - customRC = - let - luarc = pkgs.writeText "init.lua" (concatLines tooling.nvim.extraLuaRC); - in - '' - set number - set hidden - set fileencodings=utf-8 - set nocompatible - set clipboard+=unnamedplus - set ff=unix - - luafile ${luarc} - - if filereadable($HOME . "/.vimrc") - source ~/.vimrc - endif - ''; - packages.myVimPackage = { - start = tooling.nvim.plugins; - opt = [ ]; - }; - }; - }; - programs.ssh = { startAgent = true; enableAskPassword = graphical; @@ -163,21 +124,6 @@ in options.grimmShared.tooling = { enable = mkEnableOption "grimm-tooling"; - - nvim = { - plugins = mkOption { - type = types.listOf types.package; - default = [ ]; - description = "Extra vim plugins to include"; - }; - - extraLuaRC = mkOption { - type = types.listOf types.nonEmptyStr; - default = [ ]; - description = "Extra init LUA scripts"; - }; - }; - git_user = mkOption { type = types.str; default = "Grimmauld"; diff --git a/common/tooling/lsp.nix b/common/tooling/lsp.nix new file mode 100644 index 0000000..96ab557 --- /dev/null +++ b/common/tooling/lsp.nix @@ -0,0 +1,68 @@ +{ + pkgs, + config, + lib, + ... +}: +let + inherit (config.grimmShared) enable tooling; + inherit (lib) + mkOption + types + mkIf + getName + mkEnableOption + filter + ; +in +{ + config = mkIf (enable && tooling.enable) { + environment.systemPackages = map (v: v.package) tooling.lang_servers; + + grimmShared.tooling.nvim.extraLuaRC = + [ "vim.g.coq_settings = { auto_start = 'shut-up' }" ] + ++ (map ( + v: "require'lspconfig'.${v.name}.setup(require('coq').lsp_ensure_capabilities(${v.config}))" + ) (filter (v: v.vimIntegration) tooling.lang_servers)); + + grimmShared.tooling.nvim.plugins = with pkgs.vimPlugins; [ + nvim-lspconfig + coq_nvim + coq-artifacts + ]; + }; + + options.grimmShared.tooling.lang_servers = mkOption { + type = types.listOf ( + types.submodule ( + { config, ... }: + { + options = { + name = mkOption { + type = types.nullOr types.nonEmptyStr; + default = getName config.package; + description = "lspconfig module name"; + }; + + config = mkOption { + type = types.nonEmptyStr; + default = "{}"; + description = "options to pass to lspconfig"; + }; + + vimIntegration = mkEnableOption "Enable coq/nvim-lspconfig integration" // { + default = true; + }; + + package = mkOption { + type = types.package; + description = "LSP package"; + }; + }; + } + ) + ); + default = { }; + description = "Language servers available on the system"; + }; +} diff --git a/common/tooling/nix.nix b/common/tooling/nix.nix index 7ade4dc..01b8346 100644 --- a/common/tooling/nix.nix +++ b/common/tooling/nix.nix @@ -18,9 +18,11 @@ environment.sessionVariables = lib.mkIf pkgs.config.allowUnfree { NIXPKGS_ALLOW_UNFREE = "1"; }; - grimmShared.tooling.nvim.extraLuaRC = lib.singleton '' - require'lspconfig'.nixd.setup{} - ''; + grimmShared.tooling.nvim = { + plugins = with pkgs.vimPlugins; [ vim-nix ]; + }; + + grimmShared.tooling.lang_servers = [ { package = pkgs.nixd; } ]; nix.settings = { experimental-features = [ diff --git a/common/tooling/nvim.nix b/common/tooling/nvim.nix new file mode 100644 index 0000000..3cf6be3 --- /dev/null +++ b/common/tooling/nvim.nix @@ -0,0 +1,74 @@ +{ + pkgs, + config, + lib, + ... +}: +let + inherit (config.grimmShared) enable tooling; + inherit (lib) + mkOption + types + getExe + mkIf + concatLines + ; +in +{ + config = mkIf (enable && tooling.enable) { + environment.systemPackages = with pkgs; [ + dos2unix + treefmt + neovim-remote + ]; + + programs.git.config.core.editor = getExe pkgs.neovim; + + grimmShared.tooling.nvim.plugins = with pkgs.vimPlugins; [ fugitive ]; + + programs.neovim = { + enable = true; + viAlias = true; + defaultEditor = true; + withPython3 = true; + configure = { + customRC = + let + luarc = pkgs.writeText "init.lua" (concatLines tooling.nvim.extraLuaRC); + in + '' + set number + set hidden + set fileencodings=utf-8 + set nocompatible + set clipboard+=unnamedplus + set ff=unix + + luafile ${luarc} + + if filereadable($HOME . "/.vimrc") + source ~/.vimrc + endif + ''; + packages.myVimPackage = { + start = tooling.nvim.plugins; + opt = [ ]; + }; + }; + }; + }; + + options.grimmShared.tooling.nvim = { + plugins = mkOption { + type = types.listOf types.package; + default = [ ]; + description = "Extra vim plugins to include"; + }; + + extraLuaRC = mkOption { + type = types.listOf types.nonEmptyStr; + default = [ ]; + description = "Extra init LUA scripts"; + }; + }; +} diff --git a/common/tooling/python.nix b/common/tooling/python.nix index 9e34158..5bbb88b 100644 --- a/common/tooling/python.nix +++ b/common/tooling/python.nix @@ -19,6 +19,8 @@ in config = lib.mkIf (enable && tooling.enable) { environment.systemPackages = [ (pkgs.python3.withPackages pyLibs) + pkgs.yapf + pkgs.pyright ] ++ lib.optionals graphical (with pkgs; [ jetbrains.pycharm-community ]); programs.xonsh = { @@ -30,5 +32,9 @@ in ); package = pkgs.xonsh.wrapper.override { extraPackages = pyLibs; }; }; + + grimmShared.tooling.nvim.extraLuaRC = lib.singleton '' + require'lspconfig'.pyright.setup{} + ''; }; } diff --git a/common/tooling/rust.nix b/common/tooling/rust.nix new file mode 100644 index 0000000..5297a71 --- /dev/null +++ b/common/tooling/rust.nix @@ -0,0 +1,27 @@ +{ + pkgs, + lib, + config, + ... +}: +let + inherit (config.grimmShared) enable tooling graphical; +in +{ + config = lib.mkIf (enable && tooling.enable) { + environment.systemPackages = + with pkgs; + [ + rustfmt + pkg-config + ] + ++ lib.optionals graphical [ jetbrains.clion ]; + + grimmShared.tooling.lang_servers = [ + { + package = pkgs.rust-analyzer; + name = "rust_analyzer"; + } + ]; + }; +}