From bbce52c71a85c6397554b56478b170b4ae6d856b Mon Sep 17 00:00:00 2001 From: Artem Shinkarov Date: Thu, 29 Apr 2021 15:27:49 +0100 Subject: [PATCH 1/4] neovim: add `extraLuaPackages` to neovim, fixes #1964. Similarly to extraPytonPackages, we add extraLuaPackages that make lua libraries available at runtime. --- modules/programs/neovim.nix | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index e5b2c0c51e8a..bd8858ce4443 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -22,6 +22,14 @@ let merge = mergeOneOption; }; + extraLua51PackageType = mkOptionType { + name = "extra-lua51-packages"; + description = "lua5.1 packages in lua5_1.withPackages format"; + check = with types; + (x: if isFunction x then isList (x pkgs.lua51Packages) else false); + merge = mergeOneOption; + }; + pluginWithConfigType = types.submodule { options = { config = mkOption { @@ -65,6 +73,16 @@ let extraMakeWrapperArgs = lib.optionalString (cfg.extraPackages != [ ]) ''--suffix PATH : "${lib.makeBinPath cfg.extraPackages}"''; + extraMakeWrapperLuaCArgs = lib.optionalString (cfg.extraLuaPackages != [ ]) '' + --suffix LUA_CPATH ";" "${ + lib.concatMapStringsSep ";" pkgs.lua51Packages.getLuaCPath + cfg.extraLuaPackages + }"''; + extraMakeWrapperLuaArgs = lib.optionalString (cfg.extraLuaPackages != [ ]) '' + --suffix LUA_PATH ";" "${ + lib.concatMapStringsSep ";" pkgs.lua51Packages.getLuaPath + cfg.extraLuaPackages + }"''; in { options = { @@ -152,6 +170,17 @@ in { ''; }; + extraLuaPackages = mkOption { + type = with types; either extraLua51PackageType (listOf package); + default = (_: [ ]); + defaultText = "ps: []"; + example = literalExample "(ps: with ps; [ luautf8 ])"; + description = '' + A function in lua5_1.withPackages format, which returns a + list of Lua packages required for your plugins to work. + ''; + }; + package = mkOption { type = types.package; default = pkgs.neovim-unwrapped; @@ -267,7 +296,8 @@ in { programs.neovim.finalPackage = pkgs.wrapNeovimUnstable cfg.package (neovimConfig // { wrapperArgs = (lib.escapeShellArgs neovimConfig.wrapperArgs) + " " - + extraMakeWrapperArgs; + + extraMakeWrapperArgs + " " + extraMakeWrapperLuaCArgs + " " + + extraMakeWrapperLuaArgs; }); programs.bash.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; }; From b5bf4f94aaab3e16094c1309db765107138a6ad0 Mon Sep 17 00:00:00 2001 From: Artem Shinkarov Date: Thu, 29 Apr 2021 23:55:02 +0100 Subject: [PATCH 2/4] Explain why we are fixing lua packages to version 5.1. --- modules/programs/neovim.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index bd8858ce4443..0d12ab6b3c2c 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -22,6 +22,10 @@ let merge = mergeOneOption; }; + + # Currently, upstream Neovim is pinned on Lua 5.1 for LuaJIT support. + # This will need to be updated if Neovim ever migrates to a newer + # version of Lua. extraLua51PackageType = mkOptionType { name = "extra-lua51-packages"; description = "lua5.1 packages in lua5_1.withPackages format"; From 5ea5d2c1ef254c96cfe644b2d3cc05e56b95c5ed Mon Sep 17 00:00:00 2001 From: Artem Shinkarov Date: Tue, 4 May 2021 21:43:25 +0100 Subject: [PATCH 3/4] Ran ./format on neovim.nix. --- modules/programs/neovim.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index 0d12ab6b3c2c..a50d3f796f30 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -22,7 +22,6 @@ let merge = mergeOneOption; }; - # Currently, upstream Neovim is pinned on Lua 5.1 for LuaJIT support. # This will need to be updated if Neovim ever migrates to a newer # version of Lua. From b1d026d28fb49eceead066a11e60eb9f974a6c51 Mon Sep 17 00:00:00 2001 From: Artem Shinkarov Date: Tue, 4 May 2021 22:32:35 +0100 Subject: [PATCH 4/4] Add test for luaPackages in neovim. --- modules/programs/neovim.nix | 4 ++-- tests/modules/programs/neovim/plugin-config.nix | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index a50d3f796f30..357c83cf9f4f 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -175,8 +175,8 @@ in { extraLuaPackages = mkOption { type = with types; either extraLua51PackageType (listOf package); - default = (_: [ ]); - defaultText = "ps: []"; + default = [ ]; + defaultText = "[]"; example = literalExample "(ps: with ps; [ luautf8 ])"; description = '' A function in lua5_1.withPackages format, which returns a diff --git a/tests/modules/programs/neovim/plugin-config.nix b/tests/modules/programs/neovim/plugin-config.nix index 4c96fa78470a..9e9bccbcd7cf 100644 --- a/tests/modules/programs/neovim/plugin-config.nix +++ b/tests/modules/programs/neovim/plugin-config.nix @@ -20,6 +20,9 @@ with lib; ''; } ]; + extraLuaPackages = [ + pkgs.lua51Packages.luautf8 + ]; }; nmt.script = ''