vimPlugins: make usage of luaPackages less confusing

right now the src is ignored in:

```
lush-nvim = buildNeovimPlugin {
pname = "lush.nvim";
version = "2022-08-09";
src = fetchFromGitHub {
owner = "rktjmp";
repo = "lush.nvim";
rev = "6b9f399245de7bea8dac2c3bf91096ffdedfcbb7";
sha256 = "0rb77rwmbm438bmbjfk5hwrrcn5sihsa1413bdpc27rw3rrn8v8z";
};
meta.homepage = "https://github.com/rktjmp/lush.nvim/";
};
```

which is very confusing. With this PR, we correctly override the src and
the version of the package. We introduce a rockspecVersion attribute of
lua package to be able to still find the rockspec when the
"version" field needs to be different than "rockspecVersion".

authored by Matthieu Coudron and committed by Matthieu Coudron 2acce7df dbcd78e3

+36 -33
+10 -7
pkgs/applications/editors/neovim/build-neovim-plugin.nix
··· 1 { lib 2 , stdenv 3 - , buildVimPluginFrom2Nix 4 - , buildLuarocksPackage 5 - , lua51Packages 6 , toVimPlugin 7 }: 8 let ··· 19 , ... 20 }@attrs: 21 let 22 - originalLuaDrv = lua51Packages.${luaAttr}; 23 - luaDrv = lua51Packages.luaLib.overrideLuarocks originalLuaDrv (drv: { 24 extraConfig = '' 25 -- to create a flat hierarchy 26 lua_modules_path = "lua" 27 ''; 28 }); 29 - finalDrv = toVimPlugin (luaDrv.overrideAttrs(oa: { 30 nativeBuildInputs = oa.nativeBuildInputs or [] ++ [ 31 - lua51Packages.luarocksMoveDataFolder 32 ]; 33 })); 34 in
··· 1 { lib 2 , stdenv 3 + , lua 4 , toVimPlugin 5 }: 6 let ··· 17 , ... 18 }@attrs: 19 let 20 + originalLuaDrv = lua.pkgs.${luaAttr}; 21 + 22 + luaDrv = (lua.pkgs.luaLib.overrideLuarocks originalLuaDrv (drv: { 23 extraConfig = '' 24 -- to create a flat hierarchy 25 lua_modules_path = "lua" 26 ''; 27 + })).overrideAttrs (drv: { 28 + version = attrs.version; 29 + rockspecVersion = drv.rockspecVersion; 30 }); 31 + 32 + finalDrv = toVimPlugin (luaDrv.overrideAttrs(oa: attrs // { 33 nativeBuildInputs = oa.nativeBuildInputs or [] ++ [ 34 + lua.pkgs.luarocksMoveDataFolder 35 ]; 36 })); 37 in
+3 -3
pkgs/applications/editors/neovim/utils.nix
··· 1 { lib 2 - , buildLuarocksPackage 3 , callPackage 4 , vimUtils 5 , nodejs 6 , neovim-unwrapped 7 , bundlerEnv 8 , ruby 9 , python3Packages 10 , writeText 11 , wrapNeovimUnstable ··· 193 inherit legacyWrapper; 194 195 buildNeovimPluginFrom2Nix = callPackage ./build-neovim-plugin.nix { 196 - inherit (vimUtils) buildVimPluginFrom2Nix toVimPlugin; 197 - inherit buildLuarocksPackage; 198 }; 199 }
··· 1 { lib 2 , callPackage 3 , vimUtils 4 , nodejs 5 , neovim-unwrapped 6 , bundlerEnv 7 , ruby 8 + , lua 9 , python3Packages 10 , writeText 11 , wrapNeovimUnstable ··· 193 inherit legacyWrapper; 194 195 buildNeovimPluginFrom2Nix = callPackage ./build-neovim-plugin.nix { 196 + inherit (vimUtils) toVimPlugin; 197 + inherit lua; 198 }; 199 }
+21 -21
pkgs/development/interpreters/lua-5/build-lua-package.nix
··· 8 , luaLib 9 }: 10 11 - { 12 - pname 13 , version 14 15 # by default prefix `name` e.g. "lua5.2-${name}" 16 , namePrefix ? "${lua.pname}${lua.sourceVersion.major}.${lua.sourceVersion.minor}-" ··· 72 # Keep extra attributes from `attrs`, e.g., `patchPhase', etc. 73 74 let 75 - generatedRockspecFilename = "${rockspecDir}/${pname}-${version}.rockspec"; 76 77 # TODO fix warnings "Couldn't load rockspec for ..." during manifest 78 # construction -- from initial investigation, appears it will require ··· 80 # luarocks only looks for rockspecs in the default/system tree instead of all 81 # configured trees) 82 luarocks_config = "luarocks-config.lua"; 83 - luarocks_content = let 84 - generatedConfig = luaLib.generateLuarocksConfig { 85 - externalDeps = externalDeps ++ externalDepsGenerated; 86 - inherit extraVariables; 87 - inherit rocksSubdir; 88 - inherit requiredLuaRocks; 89 - }; 90 - in 91 - '' 92 - ${generatedConfig} 93 - ${extraConfig} 94 - ''; 95 - 96 - rocksSubdir = "${attrs.pname}-${version}-rocks"; 97 98 # Filter out the lua derivation itself from the Lua module dependency 99 # closure, as it doesn't have a rock tree :) ··· 106 ); 107 externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps; 108 109 - luarocksDrv = luaLib.toLuaModule ( lua.stdenv.mkDerivation ( 110 - builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariables"] // { 111 112 - name = namePrefix + pname + "-" + version; 113 114 nativeBuildInputs = [ 115 wrapLua 116 luarocks 117 - ] ++ lib.optionals doCheck ([ luarocksCheckHook ] ++ checkInputs); 118 119 buildInputs = buildInputs 120 ++ (map (d: d.dep) externalDeps');
··· 8 , luaLib 9 }: 10 11 + { pname 12 , version 13 + # we need rockspecVersion to find the .rockspec even when version changes 14 + , rockspecVersion ? version 15 16 # by default prefix `name` e.g. "lua5.2-${name}" 17 , namePrefix ? "${lua.pname}${lua.sourceVersion.major}.${lua.sourceVersion.minor}-" ··· 73 # Keep extra attributes from `attrs`, e.g., `patchPhase', etc. 74 75 let 76 + generatedRockspecFilename = "${rockspecDir}/${pname}-${rockspecVersion}.rockspec"; 77 78 # TODO fix warnings "Couldn't load rockspec for ..." during manifest 79 # construction -- from initial investigation, appears it will require ··· 81 # luarocks only looks for rockspecs in the default/system tree instead of all 82 # configured trees) 83 luarocks_config = "luarocks-config.lua"; 84 85 # Filter out the lua derivation itself from the Lua module dependency 86 # closure, as it doesn't have a rock tree :) ··· 93 ); 94 externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps; 95 96 + luarocksDrv = luaLib.toLuaModule ( lua.stdenv.mkDerivation (self: let 97 + 98 + rocksSubdir = "${self.pname}-${self.version}-rocks"; 99 + luarocks_content = let 100 + generatedConfig = luaLib.generateLuarocksConfig { 101 + externalDeps = externalDeps ++ externalDepsGenerated; 102 + inherit extraVariables rocksSubdir requiredLuaRocks; 103 + }; 104 + in 105 + '' 106 + ${generatedConfig} 107 + ${extraConfig} 108 + ''; 109 + in builtins.removeAttrs attrs ["disabled" "externalDeps" "extraVariables"] // { 110 111 + name = namePrefix + pname + "-" + self.version; 112 + inherit rockspecVersion; 113 114 nativeBuildInputs = [ 115 wrapLua 116 luarocks 117 + ] ++ lib.optionals doCheck ([ luarocksCheckHook ] ++ self.checkInputs); 118 119 buildInputs = buildInputs 120 ++ (map (d: d.dep) externalDeps');
+1 -1
pkgs/development/interpreters/lua-5/hooks/luarocks-move-data.sh
··· 5 luarocksMoveDataHook () { 6 echo "Executing luarocksMoveDataHook" 7 if [ -d "$out/$rocksSubdir" ]; then 8 - cp -rfv "$out/$rocksSubdir/$pname/$version/." "$out" 9 fi 10 11 echo "Finished executing luarocksMoveDataHook"
··· 5 luarocksMoveDataHook () { 6 echo "Executing luarocksMoveDataHook" 7 if [ -d "$out/$rocksSubdir" ]; then 8 + cp -rfv "$out/$rocksSubdir/$pname/$rockspecVersion/." "$out" 9 fi 10 11 echo "Finished executing luarocksMoveDataHook"
+1 -1
pkgs/top-level/all-packages.nix
··· 32314 }; 32315 32316 neovimUtils = callPackage ../applications/editors/neovim/utils.nix { 32317 - inherit (lua51Packages) buildLuarocksPackage; 32318 }; 32319 neovim = wrapNeovim neovim-unwrapped { }; 32320
··· 32314 }; 32315 32316 neovimUtils = callPackage ../applications/editors/neovim/utils.nix { 32317 + lua = lua5_1; 32318 }; 32319 neovim = wrapNeovim neovim-unwrapped { }; 32320