From 58f255a4cbd3371d042cb2a7b54572678860dce6 Mon Sep 17 00:00:00 2001 From: Callum Dunster Date: Tue, 15 Feb 2022 10:48:50 +0100 Subject: [PATCH 1/2] neovim: Support lua plugin config Add support for using lua for plugin configuration by adding a lua block around the config in the generated init.vim file. --- modules/programs/neovim.nix | 20 ++++++++--- tests/modules/programs/neovim/default.nix | 1 + .../programs/neovim/plugin-config-lua.nix | 34 +++++++++++++++++++ .../programs/neovim/plugin-config-lua.vim | 11 ++++++ 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 tests/modules/programs/neovim/plugin-config-lua.nix create mode 100644 tests/modules/programs/neovim/plugin-config-lua.vim 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 From 1ea7469eaf001b42198ebfff4922b4367d050da0 Mon Sep 17 00:00:00 2001 From: Callum Dunster Date: Tue, 15 Feb 2022 11:20:40 +0100 Subject: [PATCH 2/2] neovim: Add cdunster as maintainer --- .github/CODEOWNERS | 3 +++ modules/lib/maintainers.nix | 6 ++++++ 2 files changed, 9 insertions(+) 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; + }; }