From 2acce7dfdcf382757e6fe219e04668e7a63bf48a Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 11 Sep 2022 21:48:38 +0200 Subject: [PATCH] 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". --- .../editors/neovim/build-neovim-plugin.nix | 17 ++++---- pkgs/applications/editors/neovim/utils.nix | 6 +-- .../interpreters/lua-5/build-lua-package.nix | 42 +++++++++---------- .../lua-5/hooks/luarocks-move-data.sh | 2 +- pkgs/top-level/all-packages.nix | 2 +- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/pkgs/applications/editors/neovim/build-neovim-plugin.nix b/pkgs/applications/editors/neovim/build-neovim-plugin.nix index f89d36741e94..b99733523b87 100644 --- a/pkgs/applications/editors/neovim/build-neovim-plugin.nix +++ b/pkgs/applications/editors/neovim/build-neovim-plugin.nix @@ -1,8 +1,6 @@ { lib , stdenv -, buildVimPluginFrom2Nix -, buildLuarocksPackage -, lua51Packages +, lua , toVimPlugin }: let @@ -19,16 +17,21 @@ in , ... }@attrs: let - originalLuaDrv = lua51Packages.${luaAttr}; - luaDrv = lua51Packages.luaLib.overrideLuarocks originalLuaDrv (drv: { + originalLuaDrv = lua.pkgs.${luaAttr}; + + luaDrv = (lua.pkgs.luaLib.overrideLuarocks originalLuaDrv (drv: { extraConfig = '' -- to create a flat hierarchy lua_modules_path = "lua" ''; + })).overrideAttrs (drv: { + version = attrs.version; + rockspecVersion = drv.rockspecVersion; }); - finalDrv = toVimPlugin (luaDrv.overrideAttrs(oa: { + + finalDrv = toVimPlugin (luaDrv.overrideAttrs(oa: attrs // { nativeBuildInputs = oa.nativeBuildInputs or [] ++ [ - lua51Packages.luarocksMoveDataFolder + lua.pkgs.luarocksMoveDataFolder ]; })); in diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix index d5845ac4a66a..05037eafcb87 100644 --- a/pkgs/applications/editors/neovim/utils.nix +++ b/pkgs/applications/editors/neovim/utils.nix @@ -1,11 +1,11 @@ { lib -, buildLuarocksPackage , callPackage , vimUtils , nodejs , neovim-unwrapped , bundlerEnv , ruby +, lua , python3Packages , writeText , wrapNeovimUnstable @@ -193,7 +193,7 @@ in inherit legacyWrapper; buildNeovimPluginFrom2Nix = callPackage ./build-neovim-plugin.nix { - inherit (vimUtils) buildVimPluginFrom2Nix toVimPlugin; - inherit buildLuarocksPackage; + inherit (vimUtils) toVimPlugin; + inherit lua; }; } diff --git a/pkgs/development/interpreters/lua-5/build-lua-package.nix b/pkgs/development/interpreters/lua-5/build-lua-package.nix index b2f82ddb4694..d11c0d0f0390 100644 --- a/pkgs/development/interpreters/lua-5/build-lua-package.nix +++ b/pkgs/development/interpreters/lua-5/build-lua-package.nix @@ -8,9 +8,10 @@ , luaLib }: -{ -pname +{ pname , version +# we need rockspecVersion to find the .rockspec even when version changes +, rockspecVersion ? version # by default prefix `name` e.g. "lua5.2-${name}" , namePrefix ? "${lua.pname}${lua.sourceVersion.major}.${lua.sourceVersion.minor}-" @@ -72,7 +73,7 @@ pname # Keep extra attributes from `attrs`, e.g., `patchPhase', etc. let - generatedRockspecFilename = "${rockspecDir}/${pname}-${version}.rockspec"; + generatedRockspecFilename = "${rockspecDir}/${pname}-${rockspecVersion}.rockspec"; # TODO fix warnings "Couldn't load rockspec for ..." during manifest # construction -- from initial investigation, appears it will require @@ -80,20 +81,6 @@ let # luarocks only looks for rockspecs in the default/system tree instead of all # configured trees) luarocks_config = "luarocks-config.lua"; - luarocks_content = let - generatedConfig = luaLib.generateLuarocksConfig { - externalDeps = externalDeps ++ externalDepsGenerated; - inherit extraVariables; - inherit rocksSubdir; - inherit requiredLuaRocks; - }; - in - '' - ${generatedConfig} - ${extraConfig} - ''; - - rocksSubdir = "${attrs.pname}-${version}-rocks"; # Filter out the lua derivation itself from the Lua module dependency # closure, as it doesn't have a rock tree :) @@ -106,15 +93,28 @@ let ); externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps; - luarocksDrv = luaLib.toLuaModule ( lua.stdenv.mkDerivation ( -builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariables"] // { + luarocksDrv = luaLib.toLuaModule ( lua.stdenv.mkDerivation (self: let - name = namePrefix + pname + "-" + version; + rocksSubdir = "${self.pname}-${self.version}-rocks"; + luarocks_content = let + generatedConfig = luaLib.generateLuarocksConfig { + externalDeps = externalDeps ++ externalDepsGenerated; + inherit extraVariables rocksSubdir requiredLuaRocks; + }; + in + '' + ${generatedConfig} + ${extraConfig} + ''; + in builtins.removeAttrs attrs ["disabled" "externalDeps" "extraVariables"] // { + + name = namePrefix + pname + "-" + self.version; + inherit rockspecVersion; nativeBuildInputs = [ wrapLua luarocks - ] ++ lib.optionals doCheck ([ luarocksCheckHook ] ++ checkInputs); + ] ++ lib.optionals doCheck ([ luarocksCheckHook ] ++ self.checkInputs); buildInputs = buildInputs ++ (map (d: d.dep) externalDeps'); diff --git a/pkgs/development/interpreters/lua-5/hooks/luarocks-move-data.sh b/pkgs/development/interpreters/lua-5/hooks/luarocks-move-data.sh index f0b56178f01e..9870c9976eae 100644 --- a/pkgs/development/interpreters/lua-5/hooks/luarocks-move-data.sh +++ b/pkgs/development/interpreters/lua-5/hooks/luarocks-move-data.sh @@ -5,7 +5,7 @@ echo "Sourcing luarocks-move-data-hook.sh" luarocksMoveDataHook () { echo "Executing luarocksMoveDataHook" if [ -d "$out/$rocksSubdir" ]; then - cp -rfv "$out/$rocksSubdir/$pname/$version/." "$out" + cp -rfv "$out/$rocksSubdir/$pname/$rockspecVersion/." "$out" fi echo "Finished executing luarocksMoveDataHook" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 33730884e91c..d9794074a643 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -32314,7 +32314,7 @@ with pkgs; }; neovimUtils = callPackage ../applications/editors/neovim/utils.nix { - inherit (lua51Packages) buildLuarocksPackage; + lua = lua5_1; }; neovim = wrapNeovim neovim-unwrapped { };