diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 8a2f8a671dab..bf90f921cafa 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -157,6 +157,9 @@ /modules/programs/ne.nix @cwyc /tests/modules/programs/ne @cwyc +/modules/programs/neovim.nix @cdunster +/tests/modules/programs/neovim @cdunster + /modules/programs/newsboat.nix @sumnerevans /tests/modules/programs/newsboat @sumnerevans diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 13bdb1e0f09f..e58a03fef6bd 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -205,4 +205,10 @@ github = "pinage404"; githubId = 6325757; }; + cdunster = { + name = "Callum Dunster"; + email = "cdunster@users.noreply.github.com"; + github = "cdunster"; + githubId = 5011912; + }; } diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index 97e84ba884c2..4a83d132c610 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -28,8 +28,7 @@ let type = mkOption { type = types.either (types.enum [ "lua" "viml" "teal" "fennel" ]) types.str; - description = - "Language used in config. Configurations are aggregated per-language."; + description = "Language used in config section of this plugin."; default = "viml"; }; @@ -311,14 +310,25 @@ in { config = ""; optional = false; }) cfg.plugins; - suppressNotVimlConfig = p: - if p.type != "viml" then p // { config = ""; } else p; + convertConfigToViml = p: + if p.type == "viml" then + p + else if p.type == "lua" then + p // { + config = '' + lua << EOF + '' + p.config + '' + + EOF''; + } + else + p // { config = ""; }; neovimConfig = pkgs.neovimUtils.makeNeovimConfig { inherit (cfg) extraPython3Packages withPython3 withNodeJs withRuby viAlias vimAlias; configure = cfg.configure // moduleConfigure; - plugins = (map suppressNotVimlConfig pluginsNormalized) + plugins = (map convertConfigToViml pluginsNormalized) ++ optionals cfg.coc.enable [{ plugin = pkgs.vimPlugins.coc-nvim; }]; customRC = cfg.extraConfig; }; diff --git a/tests/modules/programs/neovim/default.nix b/tests/modules/programs/neovim/default.nix index 8a6c316ea5f8..6fc1593bf622 100644 --- a/tests/modules/programs/neovim/default.nix +++ b/tests/modules/programs/neovim/default.nix @@ -1,6 +1,7 @@ { neovim-plugin-config = ./plugin-config.nix; neovim-coc-config = ./coc-config.nix; + neovim-plugin-config-lua = ./plugin-config-lua.nix; # waiting for a nixpkgs patch # neovim-no-init = ./no-init.nix; } diff --git a/tests/modules/programs/neovim/plugin-config-lua.nix b/tests/modules/programs/neovim/plugin-config-lua.nix new file mode 100644 index 000000000000..ff84ebfb51b2 --- /dev/null +++ b/tests/modules/programs/neovim/plugin-config-lua.nix @@ -0,0 +1,34 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.neovim = { + enable = true; + extraConfig = '' + " This should be present in init.vim + ''; + plugins = with pkgs.vimPlugins; [ + vim-nix + { + plugin = vim-commentary; + type = "lua"; + config = '' + -- This should be present in a lua block. + vim.opt.number = true + ''; + } + ]; + }; + + nmt.script = '' + vimrc="$TESTED/home-files/.config/nvim/init.vim" + vimrcNormalized="$(normalizeStorePaths "$vimrc")" + + assertFileExists "$vimrc" + assertFileContent "$vimrcNormalized" "${./plugin-config-lua.vim}" + ''; + }; +} + diff --git a/tests/modules/programs/neovim/plugin-config-lua.vim b/tests/modules/programs/neovim/plugin-config-lua.vim new file mode 100644 index 000000000000..e4217295051d --- /dev/null +++ b/tests/modules/programs/neovim/plugin-config-lua.vim @@ -0,0 +1,11 @@ +set packpath^=/nix/store/00000000000000000000000000000000-vim-pack-dir +set runtimepath^=/nix/store/00000000000000000000000000000000-vim-pack-dir + +" vim-commentary {{{ +lua << EOF +-- This should be present in a lua block. +vim.opt.number = true + +EOF +" }}} +" This should be present in init.vim