From 5b73af6f5b142b0a926492427c0dd7891915ccf4 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 15 Aug 2021 23:11:32 +0200 Subject: [PATCH] update-luarocks-packages: support in-repo rockspecs to handle derivations that are not registered or updated on luarocks.org, for instance neovim plugins. --- .../interpreters/lua-5/build-lua-package.nix | 38 +++++++++++++------ .../lua-modules/generated-packages.nix | 29 ++++++++------ .../lua-modules/generic/default.nix | 2 +- pkgs/top-level/lua-packages.nix | 4 +- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/pkgs/development/interpreters/lua-5/build-lua-package.nix b/pkgs/development/interpreters/lua-5/build-lua-package.nix index 74f5b2b7b395..02c92cc51170 100644 --- a/pkgs/development/interpreters/lua-5/build-lua-package.nix +++ b/pkgs/development/interpreters/lua-5/build-lua-package.nix @@ -7,9 +7,10 @@ }: { -name ? "${attrs.pname}-${attrs.version}" +# name ? "${attrs.pname}-${attrs.version}" +pname, -, version +version # by default prefix `name` e.g. "lua5.2-${name}" , namePrefix ? if lua.pkgs.isLuaJIT @@ -60,7 +61,9 @@ name ? "${attrs.pname}-${attrs.version}" # The two above arguments have access to builder variables -- e.g. to $out # relative to srcRoot, path to the rockspec to use when using rocks -, rockspecFilename ? "../*.rockspec" +, rockspecFilename ? null + # "../*.rockspec" +, rockspecDir ? "." # must be set for packages that don't have a rock , knownRockspec ? null @@ -71,6 +74,9 @@ name ? "${attrs.pname}-${attrs.version}" # Keep extra attributes from `attrs`, e.g., `patchPhase', etc. let + generatedRockspecFilename = "${pname}-${version}.rockspec"; + + # TODO fix warnings "Couldn't load rockspec for ..." during manifest # construction -- from initial investigation, appears it will require # upstream luarocks changes to fix cleanly (during manifest construction, @@ -144,7 +150,7 @@ in toLuaModule ( lua.stdenv.mkDerivation ( builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariables"] // { - name = namePrefix + name; + name = namePrefix + pname + "-" + version; buildInputs = [ wrapLua lua.pkgs.luarocks ] ++ buildInputs @@ -159,12 +165,13 @@ builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariab # @-patterns do not capture formal argument default values, so we need to # explicitly inherit this for it to be available as a shell variable in the # builder - inherit rockspecFilename; + # inherit rockspecFilename; inherit rocksSubdir; # enabled only for src.rock setSourceRoot= let - name_only= lib.getName name; + # name_only= lib.getName name; + name_only= pname; in lib.optionalString (knownRockspec == null) '' # format is rockspec_basename/source_basename @@ -180,18 +187,23 @@ builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariab ${luarocks_content} EOF export LUAROCKS_CONFIG="$PWD/${luarocks_config}"; - '' - + lib.optionalString (knownRockspec != null) '' - # prevents the following type of error: - # Inconsistency between rockspec filename (42fm1b3d7iv6fcbhgm9674as3jh6y2sh-luv-1.22.0-1.rockspec) and its contents (luv-1.22.0-1.rockspec) - rockspecFilename="$TMP/$(stripHash ''${knownRockspec})" - cp ''${knownRockspec} "$rockspecFilename" '' + + lib.optionalString (rockspecFilename == null) '' + rockspecFilename="${generatedRockspecFilename}" + '' + # + lib.optionalString (knownRockspec != null) '' + + # # prevents the following type of error: + # # Inconsistency between rockspec filename (42fm1b3d7iv6fcbhgm9674as3jh6y2sh-luv-1.22.0-1.rockspec) and its contents (luv-1.22.0-1.rockspec) + # rockspecFilename="$TMP/$(stripHash ''${knownRockspec})" + # cp ''${knownRockspec} "$rockspecFilename" + # '' + '' runHook postConfigure ''; + # TODO could be moved to configurePhase buildPhase = '' runHook preBuild @@ -225,7 +237,9 @@ builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariab nix_debug "ROCKSPEC $rockspecFilename" nix_debug "cwd: $PWD" + set -x $LUAROCKS make --deps-mode=all --tree=$out ''${rockspecFilename} + set +x runHook postInstall ''; diff --git a/pkgs/development/lua-modules/generated-packages.nix b/pkgs/development/lua-modules/generated-packages.nix index d7a146ad4242..775d31cffb49 100644 --- a/pkgs/development/lua-modules/generated-packages.nix +++ b/pkgs/development/lua-modules/generated-packages.nix @@ -69,10 +69,11 @@ basexx = buildLuarocksPackage { pname = "basexx"; version = "0.4.1-1"; - knownRockspec = (fetchurl { - url = "https://luarocks.org/basexx-0.4.1-1.rockspec"; - sha256 = "0kmydxm2wywl18cgj303apsx7hnfd68a9hx9yhq10fj7yfcxzv5f"; - }).outPath; + # knownRockspec = (fetchurl { + # url = "https://luarocks.org/basexx-0.4.1-1.rockspec"; + # sha256 = "0kmydxm2wywl18cgj303apsx7hnfd68a9hx9yhq10fj7yfcxzv5f"; + # }).outPath; + rockspecDir = "dist"; src = fetchurl { url = "https://github.com/aiq/basexx/archive/v0.4.1.tar.gz"; @@ -112,6 +113,8 @@ bit32 = buildLuarocksPackage { pname = "bit32"; version = "5.3.0-1"; + NIX_DEBUG=3; + src = fetchurl { url = "https://luarocks.org/bit32-5.3.0-1.src.rock"; sha256 = "19i7kc2pfg9hc6qjq4kka43q6qk71bkl2rzvrjaks6283q6wfyzy"; @@ -1617,10 +1620,12 @@ plenary-nvim = buildLuarocksPackage { pname = "plenary.nvim"; version = "scm-1"; - knownRockspec = (fetchurl { - url = "https://luarocks.org/plenary.nvim-scm-1.rockspec"; - sha256 = "1xgqq0skg3vxahlnh1libc5dvhafp11k6k8cs65jcr9sw6xjycwh"; - }).outPath; + # knownRockspec = (fetchurl { + # url = "https://luarocks.org/plenary.nvim-scm-1.rockspec"; + # sha256 = "1xgqq0skg3vxahlnh1libc5dvhafp11k6k8cs65jcr9sw6xjycwh"; + # }).outPath; + # shouldn't this be the default ? + rockspecPath="."; src = fetchgit ( removeAttrs (builtins.fromJSON ''{ "url": "git://github.com/nvim-lua/plenary.nvim", @@ -1684,10 +1689,10 @@ say = buildLuarocksPackage { pname = "say"; version = "1.3-1"; - knownRockspec = (fetchurl { - url = "https://luarocks.org/say-1.3-1.rockspec"; - sha256 = "0bknglb0qwd6r703wp3hcb6z2xxd14kq4md3sg9al3b28fzxbhdv"; - }).outPath; + # knownRockspec = (fetchurl { + # url = "https://luarocks.org/say-1.3-1.rockspec"; + # sha256 = "0bknglb0qwd6r703wp3hcb6z2xxd14kq4md3sg9al3b28fzxbhdv"; + # }).outPath; src = fetchurl { url = "https://github.com/Olivine-Labs/say/archive/v1.3-1.tar.gz"; diff --git a/pkgs/development/lua-modules/generic/default.nix b/pkgs/development/lua-modules/generic/default.nix index de21d3d6a3e6..183a958b4e1f 100644 --- a/pkgs/development/lua-modules/generic/default.nix +++ b/pkgs/development/lua-modules/generic/default.nix @@ -20,7 +20,7 @@ else attrs // { - name = "lua${lua.luaversion}-" + attrs.name; + name = "lua${lua.luaversion}-" + attrs.pname + "-" + attrs.version; propagatedBuildInputs = propagatedBuildInputs ++ [ lua # propagate it for its setup-hook ]; diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix index f16917a94394..246d62b903b3 100644 --- a/pkgs/top-level/lua-packages.nix +++ b/pkgs/top-level/lua-packages.nix @@ -99,8 +99,8 @@ with self; { luarocks-nix = callPackage ../development/tools/misc/luarocks/luarocks-nix.nix { }; - luxio = buildLuaPackage rec { - name = "luxio-${version}"; + luxio = buildLuaPackage { + pname = "luxio"; version = "13"; src = fetchurl {