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