nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

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 ··· 17 19 , ... 18 20 }@attrs: 19 21 let 20 - originalLuaDrv = lua51Packages.${luaAttr}; 21 - luaDrv = lua51Packages.luaLib.overrideLuarocks originalLuaDrv (drv: { 22 + originalLuaDrv = lua.pkgs.${luaAttr}; 23 + 24 + luaDrv = (lua.pkgs.luaLib.overrideLuarocks originalLuaDrv (drv: { 22 25 extraConfig = '' 23 26 -- to create a flat hierarchy 24 27 lua_modules_path = "lua" 25 28 ''; 29 + })).overrideAttrs (drv: { 30 + version = attrs.version; 31 + rockspecVersion = drv.rockspecVersion; 26 32 }); 27 - finalDrv = toVimPlugin (luaDrv.overrideAttrs(oa: { 33 + 34 + finalDrv = toVimPlugin (luaDrv.overrideAttrs(oa: attrs // { 28 35 nativeBuildInputs = oa.nativeBuildInputs or [] ++ [ 29 - lua51Packages.luarocksMoveDataFolder 36 + lua.pkgs.luarocksMoveDataFolder 30 37 ]; 31 38 })); 32 39 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}-" ··· 73 72 # Keep extra attributes from `attrs`, e.g., `patchPhase', etc. 74 73 75 74 let 76 - generatedRockspecFilename = "${rockspecDir}/${pname}-${version}.rockspec"; 75 + generatedRockspecFilename = "${rockspecDir}/${pname}-${rockspecVersion}.rockspec"; 77 76 78 77 # TODO fix warnings "Couldn't load rockspec for ..." during manifest 79 78 # construction -- from initial investigation, appears it will require ··· 81 80 # luarocks only looks for rockspecs in the default/system tree instead of all 82 81 # configured trees) 83 82 luarocks_config = "luarocks-config.lua"; 84 - luarocks_content = let 85 - generatedConfig = luaLib.generateLuarocksConfig { 86 - externalDeps = externalDeps ++ externalDepsGenerated; 87 - inherit extraVariables; 88 - inherit rocksSubdir; 89 - inherit requiredLuaRocks; 90 - }; 91 - in 92 - '' 93 - ${generatedConfig} 94 - ${extraConfig} 95 - ''; 96 - 97 - rocksSubdir = "${attrs.pname}-${version}-rocks"; 98 83 99 84 # Filter out the lua derivation itself from the Lua module dependency 100 85 # closure, as it doesn't have a rock tree :) ··· 93 106 ); 94 107 externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps; 95 108 96 - luarocksDrv = luaLib.toLuaModule ( lua.stdenv.mkDerivation ( 97 - builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariables"] // { 109 + luarocksDrv = luaLib.toLuaModule ( lua.stdenv.mkDerivation (self: let 98 110 99 - name = namePrefix + pname + "-" + version; 111 + rocksSubdir = "${self.pname}-${self.version}-rocks"; 112 + luarocks_content = let 113 + generatedConfig = luaLib.generateLuarocksConfig { 114 + externalDeps = externalDeps ++ externalDepsGenerated; 115 + inherit extraVariables rocksSubdir requiredLuaRocks; 116 + }; 117 + in 118 + '' 119 + ${generatedConfig} 120 + ${extraConfig} 121 + ''; 122 + in builtins.removeAttrs attrs ["disabled" "externalDeps" "extraVariables"] // { 123 + 124 + name = namePrefix + pname + "-" + self.version; 125 + inherit rockspecVersion; 100 126 101 127 nativeBuildInputs = [ 102 128 wrapLua 103 129 luarocks 104 - ] ++ lib.optionals doCheck ([ luarocksCheckHook ] ++ checkInputs); 130 + ] ++ lib.optionals doCheck ([ luarocksCheckHook ] ++ self.checkInputs); 105 131 106 132 buildInputs = buildInputs 107 133 ++ (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