inputs: { config, pkgs, lib, ... }: let inherit (pkgs.unstable) vimPlugins wrapNeovim tree-sitter; luaFormat = inputs.self.lib.generators.lua { }; neovim-unwrapped = pkgs.unstable.neovim-unwrapped; cfg = config.vim; myConfigPackage = with lib; let config = '' -- Autogenerated variables from the NixOS configuration ${(concatStringsSep "\n" (mapAttrsToList (variable: value: "vim.g.${variable} = ${luaFormat.generate value}") cfg.variables))} -- vim.lua from the NixOS configuration ${builtins.readFile ../dotfiles/vim.lua} -- luaConfig from the NixOS configuration ${cfg.luaConfig} ''; in pkgs.runCommand "myConfig" { pname = "myConfig"; inherit config; passAsFile = [ "config" ]; runLocal = true; } '' mkdir -p "$out/lua" mv "$configPath" "$out/lua/myConfig.lua" ''; myNeovim = wrapNeovim neovim-unwrapped { configure = { inherit (config.vim) beforePlugins; customRC = '' lua require("myConfig") ${cfg.extraConfig} ''; packages.myVimPackage = with vimPlugins; { start = [ myConfigPackage # Dependencies plenary-nvim popup-nvim # UI undotree gruvbox-community lualine-nvim lualine-lsp-progress gitsigns-nvim diffview-nvim nvim-notify indent-blankline-nvim # Completion nvim-cmp cmp-buffer cmp-calc cmp-cmdline cmp-latex-symbols cmp-nvim-lsp cmp-path cmp-spell cmp-tmux cmp-treesitter cmp-vsnip # Snippets vim-vsnip vim-vsnip-integ # Telescope telescope-nvim telescope-file-browser-nvim telescope-ui-select-nvim # Treesitter (nvim-treesitter.withPlugins (_: tree-sitter.allGrammars)) nvim-treesitter-textobjects nvim-treesitter-context nvim-treesitter-refactor vim-matchup # Motions camelcasemotion vim-surround targets-vim neoformat # Languages vim-polyglot editorconfig-vim vim-pandoc # Other tmux-complete-vim vim-fugitive neogit vim-rhubarb vim-repeat vim-unimpaired tabular vim-abolish vim-oscyank comment-nvim null-ls-nvim ] ++ config.vim.extraPlugins; }; }; }; in { options.vim = with lib; { variables = mkOption { type = types.attrsOf luaFormat.type; default = { }; description = "Extra global variables to add at the beginning of the vim configuration."; }; extraPlugins = mkOption { type = with types; listOf package; default = [ ]; description = "Names of extra plugins to add"; }; beforePlugins = mkOption { type = types.lines; default = ""; description = "Extra lines to add in the vim configuration before loading plugins"; }; extraConfig = mkOption { type = types.lines; 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.unstable; [ myNeovim deadnix statix # TODO: add global vale config vale ]; environment.sessionVariables = { EDITOR = "nvim"; MANPAGER = "nvim +Man!"; }; home-manager.users.minijackson = { ... }: { xdg.dataFile."nvim/backup/.keep".text = ""; }; home-manager.users.root = { ... }: { xdg.dataFile."nvim/backup/.keep".text = ""; }; }; }