inputs: { config, pkgs, lib, ... }: 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 vim-oscyank ] ++ config.vim.extraPlugins; }; }; }; in { options.vim = with lib; { variables = mkOption { type = types.attrsOf types.str; default = {}; description = '' Extra global variables to add at the beginning of the vim configuration. Remember to escape strings with single-quotes. ''; }; 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; [ myNeovim ]; environment.sessionVariables = { EDITOR = "nvim"; }; home-manager.users.minijackson = { ... }: { xdg.dataFile."nvim/backup/.keep".text = ""; }; home-manager.users.root = { ... }: { xdg.dataFile."nvim/backup/.keep".text = ""; }; }; }