From 2ea757a0299331deda57fda9395cf2592ee460ee Mon Sep 17 00:00:00 2001 From: "Matthieu C." <886074+teto@users.noreply.github.com> Date: Fri, 31 May 2024 17:42:08 +0200 Subject: [PATCH] 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. --- maintainers/scripts/luarocks-packages.csv | 1 + .../lua-5/build-luarocks-package.nix | 6 ++-- .../lua-modules/generated-packages.nix | 24 +++++++++++++++ pkgs/development/lua-modules/overrides.nix | 30 +++++++++++++++++++ .../tools/misc/luarocks/default.nix | 9 ++++++ pkgs/top-level/lua-packages.nix | 2 +- 6 files changed, 68 insertions(+), 4 deletions(-) diff --git a/maintainers/scripts/luarocks-packages.csv b/maintainers/scripts/luarocks-packages.csv index 23497e6d80d7..e9d10e90b8d4 100644 --- a/maintainers/scripts/luarocks-packages.csv +++ b/maintainers/scripts/luarocks-packages.csv @@ -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 diff --git a/pkgs/development/interpreters/lua-5/build-luarocks-package.nix b/pkgs/development/interpreters/lua-5/build-luarocks-package.nix index b4eec6d8ff2d..0e4f62d42e2d 100644 --- a/pkgs/development/interpreters/lua-5/build-luarocks-package.nix +++ b/pkgs/development/interpreters/lua-5/build-luarocks-package.nix @@ -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') diff --git a/pkgs/development/lua-modules/generated-packages.nix b/pkgs/development/lua-modules/generated-packages.nix index 276ee7736325..ffb9f43a234e 100644 --- a/pkgs/development/lua-modules/generated-packages.nix +++ b/pkgs/development/lua-modules/generated-packages.nix @@ -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"; diff --git a/pkgs/development/lua-modules/overrides.nix b/pkgs/development/lua-modules/overrides.nix index b3c35ea20254..ff6f2e73fcbc 100644 --- a/pkgs/development/lua-modules/overrides.nix +++ b/pkgs/development/lua-modules/overrides.nix @@ -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; } diff --git a/pkgs/development/tools/misc/luarocks/default.nix b/pkgs/development/tools/misc/luarocks/default.nix index ce832140703a..55c2c079e7c4 100644 --- a/pkgs/development/tools/misc/luarocks/default.nix +++ b/pkgs/development/tools/misc/luarocks/default.nix @@ -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 diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix index a13c9c3f6c86..7a251531ac70 100644 --- a/pkgs/top-level/lua-packages.nix +++ b/pkgs/top-level/lua-packages.nix @@ -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 { });