luaPackages.luarocks: generate luarocks as well

When installing a lua package that depends on luarocks, luarocks was not
capable of recognizing the luarocks module: https://github.com/NixOS/nixpkgs/issues/316009 .

As explained here https://github.com/luarocks/luarocks/issues/1659,
luarocks needs a manifest to recognize the package.
I first attempted to generate a manifest with `luarocks-admin
make-manifest` on our current manual luarocks derivation but this ended
up being too hackish as the `make-manifest` requires a .rockspec or
.rock to work, which we had not.

It seemed simpled to just rename the current manual luarocks derivation to luarocks_bootstrap
in order to break cyclic dependencies in buildLuarocksPackage and add a
generated luarocks derivation. Previously it was impossible to test
luarocks because of the cyclic dependency but we will now be able to
test the generated derivation.
This commit is contained in:
Matthieu C. 2024-05-31 17:42:08 +02:00
parent 5ceeafa47d
commit 2ea757a029
6 changed files with 68 additions and 4 deletions

View File

@ -77,6 +77,7 @@ lualogging,,,,,,
luaossl,,,,,5.1,
luaposix,,,,34.1.1-1,,vyp lblasc
luarepl,,,,,,
luarocks,,,,,,mrcjkb teto
luarocks-build-rust-mlua,,,,,,mrcjkb
luarocks-build-treesitter-parser,,,,,,mrcjkb
luasec,,,,,,flosse

1 name rockspec ref server version luaversion maintainers
77 luaossl 5.1
78 luaposix 34.1.1-1 vyp lblasc
79 luarepl
80 luarocks mrcjkb teto
81 luarocks-build-rust-mlua mrcjkb
82 luarocks-build-treesitter-parser mrcjkb
83 luasec flosse

View File

@ -2,7 +2,7 @@
{ lib
, lua
, wrapLua
, luarocks
, luarocks_bootstrap
, writeTextFile
# Whether the derivation provides a lua module or not.
@ -91,7 +91,7 @@ let
nativeBuildInputs = [
lua # for lua.h
wrapLua
luarocks
luarocks_bootstrap
];
inherit doCheck extraConfig rockspecFilename knownRockspec externalDeps nativeCheckInputs;
@ -99,7 +99,7 @@ let
buildInputs = let
# example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
externalDeps' = lib.filter (dep: !lib.isDerivation dep) self.externalDeps;
in [ lua.pkgs.luarocks ]
in [ luarocks_bootstrap ]
++ buildInputs
++ lib.optionals self.doCheck ([ luarocksCheckHook ] ++ self.nativeCheckInputs)
++ (map (d: d.dep) externalDeps')

View File

@ -1913,6 +1913,30 @@ buildLuarocksPackage {
};
}) {};
luarocks = callPackage({ buildLuarocksPackage, fetchFromGitHub, fetchurl }:
buildLuarocksPackage {
pname = "luarocks";
version = "3.11.0-1";
knownRockspec = (fetchurl {
url = "mirror://luarocks/luarocks-3.11.0-1.rockspec";
sha256 = "0pi55445dskpw6nhrq52589h4v39fsf23c0kp8d4zg2qaf6y2n38";
}).outPath;
src = fetchFromGitHub {
owner = "luarocks";
repo = "luarocks";
rev = "v3.11.0";
hash = "sha256-mSwwBuLWoMT38iYaV/BTdDmmBz4heTRJzxBHC0Vrvc4=";
};
meta = {
homepage = "http://www.luarocks.org";
description = "A package manager for Lua modules.";
maintainers = with lib.maintainers; [ mrcjkb teto ];
license.fullName = "MIT";
};
}) {};
luarocks-build-rust-mlua = callPackage({ buildLuarocksPackage, fetchFromGitHub, fetchurl }:
buildLuarocksPackage {
pname = "luarocks-build-rust-mlua";

View File

@ -54,6 +54,8 @@
, vimPlugins
, vimUtils
, yajl
, zip
, unzip
, zlib
, zziplib
}:
@ -407,6 +409,34 @@ in
];
});
# As a nix user, use this derivation instead of "luarocks_bootstrap"
luarocks = prev.luarocks.overrideAttrs (oa: {
nativeBuildInputs = oa.nativeBuildInputs ++ [ installShellFiles lua unzip ];
# cmake is just to compile packages with "cmake" buildType, not luarocks itself
dontUseCmakeConfigure = true;
propagatedBuildInputs = [ zip unzip cmake ];
postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installShellCompletion --cmd luarocks \
--bash <($out/bin/luarocks completion bash) \
--fish <($out/bin/luarocks completion fish) \
--zsh <($out/bin/luarocks completion zsh)
installShellCompletion --cmd luarocks-admin \
--bash <($out/bin/luarocks-admin completion bash) \
--fish <($out/bin/luarocks-admin completion fish) \
--zsh <($out/bin/luarocks-admin completion zsh)
'';
meta = oa.meta // {
mainProgram = "luarocks";
};
});
luasec = prev.luasec.overrideAttrs (oa: {
externalDeps = [
{ name = "OPENSSL"; dep = openssl; }

View File

@ -1,3 +1,12 @@
/*
This is a minimal/manual luarocks derivation used by `buildLuarocksPackage` to install lua packages.
As a nix user, you should use the generated lua.pkgs.luarocks that contains a luarocks manifest
which makes it recognizable to luarocks.
Generating the manifest for luarocks_bootstrap seemed too hackish, which is why we end up
with two "luarocks" derivations.
*/
{ lib
, stdenv
, fetchFromGitHub

View File

@ -54,7 +54,7 @@ rec {
inherit (pkgs.buildPackages) makeSetupHook makeWrapper;
};
luarocks = toLuaModule (callPackage ../development/tools/misc/luarocks/default.nix { });
luarocks_bootstrap = toLuaModule (callPackage ../development/tools/misc/luarocks/default.nix { });
# a fork of luarocks used to generate nix lua derivations from rockspecs
luarocks-nix = toLuaModule (callPackage ../development/tools/misc/luarocks/luarocks-nix.nix { });