From 13bbcd5a5feffa4a91f4e4068e68e9baf2f90223 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 12 May 2021 20:54:32 +0200 Subject: vim: better config with lua, with some dev config --- common/vim.nix | 206 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 124 insertions(+), 82 deletions(-) (limited to 'common/vim.nix') diff --git a/common/vim.nix b/common/vim.nix index aa74a39..ec43738 100644 --- a/common/vim.nix +++ b/common/vim.nix @@ -2,81 +2,108 @@ inputs: { config, pkgs, lib, ... }: -let myNeovim = (pkgs.neovim.override { - configure = { - - inherit (config.vim) beforePlugins; - - customRC = with lib; - (concatStringsSep - "\n" - (mapAttrsToList - (variable: value: "let g:${variable} = ${value}") - config.vim.variables)) - + "\n" - + builtins.readFile ../dotfiles/vimrc.vim + config.vim.extraConfig; - - vam = with pkgs; { - pluginDictionaries = [ - # UI - { name = "undotree"; } - { name = "gruvbox-community"; } - { name = "gitgutter"; } - { name = "lightline-vim"; } - { name = "vim-dirvish"; } - - # Motions - { name = "camelcasemotion"; } - { name = "surround"; } - { name = "targets-vim"; } - - # Frameworks - { name = "deoplete-nvim"; } - { name = "neosnippet"; } - { name = "neosnippet-snippets"; } - { name = "neoformat"; } - { name = "ctrlp"; } - # Syntax generic completion for deoplete - { name = "neco-syntax"; } - - # Languages - { name = "vim-polyglot"; } - { name = "editorconfig-vim"; } - # Vim completion for deoplete - { name = "neco-vim"; } - { name = "deoplete-zsh"; } - { name = "vim-pandoc"; } - { name = "vim-pandoc-syntax"; } - - # Languages (but not programming languages) - { name = "vim-grammarous"; } - - # Other - { name = "tmux-complete-vim"; } - { name = "fugitive"; } - { name = "rhubarb"; } - { name = "repeat"; } - { name = "vim-unimpaired"; } - { name = "tabular"; } - { name = "vimwiki"; } - { name = "vim-abolish"; } - - ] ++ config.vim.extraPlugins; +let + inherit (pkgs.unstable) vimPlugins wrapNeovim; - }; + neovim-unwrapped = inputs.neovim-master.defaultPackage.${config.nixpkgs.system}; + + cfg = config.vim; + + myConfigPackage = with lib; + pkgs.writeTextDir + "share/vim-plugins/myConfig/lua/myConfig.lua" + '' + -- Autogenerated variables from the NixOS configuration + + ${(concatStringsSep + "\n" + (mapAttrsToList + (variable: value: "vim.g.${variable} = ${value}") + cfg.variables))} + + -- vim.lua from the NixOS configuration + + ${builtins.readFile ../dotfiles/vim.lua} + + -- luaConfig from the NixOS configuration + + ${cfg.luaConfig} + ''; + + myNeovim = wrapNeovim neovim-unwrapped { + configure = { + inherit (config.vim) beforePlugins; + + customRC = '' + autocmd VimEnter * lua require("myConfig") + + ${cfg.extraConfig} + ''; + + packages.myVimPackage = with vimPlugins; { + start = [ + myConfigPackage + + # Dependencies + plenary-nvim + popup-nvim + + # UI + undotree + gruvbox-community + lualine-nvim + gitsigns-nvim + vim-dirvish + lsp-status-nvim + + completion-nvim + completion-buffers + snippets-nvim + + telescope-nvim + + # Treesitter + nvim-treesitter + completion-treesitter + nvim-treesitter-textobjects + nvim-treesitter-context + + # Motions + camelcasemotion + surround + targets-vim + + neoformat + + # Languages + vim-polyglot + editorconfig-vim + vim-pandoc + vim-pandoc-syntax + + # Languages (but not programming languages) + vim-grammarous + + # Other + tmux-complete-vim + fugitive + rhubarb + repeat + vim-unimpaired + tabular + vim-abolish + ] ++ config.vim.extraPlugins; + }; + }; }; -}); -in { +in +{ options.vim = with lib; { variables = mkOption { type = types.attrsOf types.str; - default = { - dominant_color = "'${config.theme.colors.dominant}'"; - ripgrep_path = "'${pkgs.ripgrep}/bin/rg'"; - fd_path = "'${pkgs.fd}/bin/fd'"; - }; + default = {}; description = '' Extra global variables to add at the beginning of the vim configuration. @@ -85,17 +112,11 @@ in { }; extraPlugins = mkOption { - type = types.listOf (types.attrsOf types.str); - default = []; + type = with types; listOf package; + default = [ ]; description = "Names of extra plugins to add"; }; - extraRepoPlugins = mkOption { - type = types.listOf (types.attrsOf types.str); - default = []; - description = "Names of extra plugins to add that are present in the local repository"; - }; - beforePlugins = mkOption { type = types.lines; default = ""; @@ -107,9 +128,30 @@ in { default = ""; description = "Extra lines to add at the end of the vim configuration"; }; + + luaConfig = mkOption { + type = types.lines; + default = ""; + description = "Lua Neovim configuration"; + }; + + wrappedPackage = mkOption { + type = types.package; + description = "Resulting wrapped Neovim package"; + readOnly = true; + }; }; config = { + vim = { + wrappedPackage = myNeovim; + variables = { + dominant_color = "'${config.theme.colors.dominant}'"; + ripgrep_path = "'${pkgs.ripgrep}/bin/rg'"; + fd_path = "'${pkgs.fd}/bin/fd'"; + }; + }; + environment.systemPackages = with pkgs; [ myNeovim ]; @@ -119,13 +161,13 @@ in { }; home-manager.users.minijackson = { ... }: - { - xdg.dataFile."nvim/backup/.keep".text = ""; - }; + { + xdg.dataFile."nvim/backup/.keep".text = ""; + }; home-manager.users.root = { ... }: - { - xdg.dataFile."nvim/backup/.keep".text = ""; - }; + { + xdg.dataFile."nvim/backup/.keep".text = ""; + }; }; } -- cgit v1.2.3