aboutsummaryrefslogtreecommitdiff
path: root/pkgs/development/interpreters/lua-5
diff options
context:
space:
mode:
authorMatthieu Coudron <mattator@gmail.com>2019-06-19 14:23:31 +0200
committerGitHub <noreply@github.com>2019-06-19 14:23:31 +0200
commitc33153bf1395e1149bf018ea391977b0ae399dde (patch)
tree030fb5d077f9942f9c9181b9b72d3079bb124128 /pkgs/development/interpreters/lua-5
parent56cc1e3aca3d877c3cab4f2d5b170245470deb46 (diff)
parent671e53af6736630cad70e8c404f263c8720ae3a1 (diff)
Merge pull request #63108 from Shados/lua-packaging-improvements-pr
Lua/luarocks packaging improvements
Diffstat (limited to 'pkgs/development/interpreters/lua-5')
-rw-r--r--pkgs/development/interpreters/lua-5/build-lua-package.nix113
1 files changed, 85 insertions, 28 deletions
diff --git a/pkgs/development/interpreters/lua-5/build-lua-package.nix b/pkgs/development/interpreters/lua-5/build-lua-package.nix
index f383c7283698..7133f54025b1 100644
--- a/pkgs/development/interpreters/lua-5/build-lua-package.nix
+++ b/pkgs/development/interpreters/lua-5/build-lua-package.nix
@@ -27,12 +27,13 @@ name ? "${attrs.pname}-${attrs.version}"
, propagatedNativeBuildInputs ? []
# used to disable derivation, useful for specific lua versions
+# TODO move from this setting meta.broken to a 'disabled' attribute on the
+# package, then use that to skip/include in each lua${ver}Packages set?
, disabled ? false
# Additional arguments to pass to the makeWrapper function, which wraps
# generated binaries.
, makeWrapperArgs ? []
-, external_deps ? propagatedBuildInputs ++ buildInputs
# Skip wrapping of lua programs altogether
, dontWrapLuaPrograms ? false
@@ -42,11 +43,19 @@ name ? "${attrs.pname}-${attrs.version}"
, passthru ? {}
, doCheck ? false
-# appended to the luarocks generated config
-# in peculiar variables like { EVENT_INCDIR } can be useful to work around
-# luarocks limitations, ie, luarocks consider include/lib folders to be subfolders of the same package in external_deps_dirs
-# as explained in https://github.com/luarocks/luarocks/issues/766
+# Non-Lua / system (e.g. C library) dependencies. Is a list of deps, where
+# each dep is either a derivation, or an attribute set like
+# { name = "rockspec external_dependencies key"; dep = derivation; }
+# The latter is used to work-around luarocks having a problem with
+# multiple-output derivations as external deps:
+# https://github.com/luarocks/luarocks/issues/766<Paste>
+, externalDeps ? lib.unique (lib.filter (drv: !drv ? luaModule) (propagatedBuildInputs ++ buildInputs))
+
+# Appended to the generated luarocks config
, extraConfig ? ""
+# Inserted into the generated luarocks config in the "variables" table
+, extraVariables ? ""
+# 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"
@@ -58,44 +67,95 @@ name ? "${attrs.pname}-${attrs.version}"
# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
-if disabled
-then throw "${name} not supported for interpreter ${lua}"
-else
let
-
- deps_dirs= lib.concatStringsSep ", " (
- map (x: "\"${builtins.toString x}\"") external_deps
- );
-
- # TODO
- # - add rocktrees (look at torch-distro.nix/https://github.com/luarocks/luarocks/wiki/Config-file-format)
- # - silence warnings
- luarocks_config = "luarocksConfig";
+ # 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,
+ # luarocks only looks for rockspecs in the default/system tree instead of all
+ # configured trees)
+ luarocks_config = "luarocks-config.lua";
luarocks_content = ''
local_cache = ""
- -- array of strings
+ -- To prevent collisions when creating environments, we install the rock
+ -- files into per-package subdirectories
+ rocks_subdir = '${rocksSubdir}'
+ -- Then we need to tell luarocks where to find the rock files per
+ -- dependency
+ rocks_trees = {
+ ${lib.concatStringsSep "\n, " rocksTrees}
+ }
+ '' + lib.optionalString lua.pkgs.isLuaJIT ''
+ -- Luajit provides some additional functionality built-in; this exposes
+ -- that to luarock's dependency system
+ rocks_provided = {
+ jit='${lua.luaversion}-1';
+ ffi='${lua.luaversion}-1';
+ luaffi='${lua.luaversion}-1';
+ bit='${lua.luaversion}-1';
+ }
+ '' + ''
+ -- For single-output external dependencies
external_deps_dirs = {
- ${deps_dirs}
+ ${lib.concatStringsSep "\n, " externalDepsDirs}
}
- rocks_trees = {
+ variables = {
+ -- Some needed machinery to handle multiple-output external dependencies,
+ -- as per https://github.com/luarocks/luarocks/issues/766
+ ${lib.optionalString (lib.length depVariables > 0) ''
+ ${lib.concatStringsSep "\n " depVariables}''}
+ ${extraVariables}
}
${extraConfig}
'';
+
+ rocksSubdir = "${attrs.pname}-${version}-rocks";
+
+ externalDepsDirs = map
+ (x: "'${builtins.toString x}'")
+ (lib.filter (lib.isDerivation) externalDeps);
+
+ rocksTrees = lib.imap0
+ (i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }")
+ requiredLuaRocks;
+
+ # Filter out the lua derivation itself from the Lua module dependency
+ # closure, as it doesn't have a rock tree :)
+ requiredLuaRocks = lib.filter (d: d ? luaModule)
+ (lua.pkgs.requiredLuaModules propagatedBuildInputs);
+
+ # Explicitly point luarocks to the relevant locations for multiple-output
+ # derivations that are external dependencies, to work around an issue it has
+ # (https://github.com/luarocks/luarocks/issues/766)
+ depVariables = lib.concatMap ({name, dep}: [
+ "${name}_INCDIR='${lib.getDev dep}/include';"
+ "${name}_LIBDIR='${lib.getLib dep}/lib';"
+ "${name}_BINDIR='${lib.getBin dep}/bin';"
+ ]) externalDeps';
+
+ # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
+ externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
in
toLuaModule ( lua.stdenv.mkDerivation (
-builtins.removeAttrs attrs ["disabled" "checkInputs"] // {
+builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps"] // {
name = namePrefix + name;
buildInputs = [ wrapLua lua.pkgs.luarocks ]
++ buildInputs
++ lib.optionals doCheck checkInputs
+ ++ (map (d: d.dep) externalDeps')
;
# propagate lua to active setup-hook in nix-shell
propagatedBuildInputs = propagatedBuildInputs ++ [ lua ];
- doCheck = false;
+ inherit doCheck;
+
+ # @-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 rocksSubdir;
# enabled only for src.rock
setSourceRoot= let
@@ -162,23 +222,20 @@ builtins.removeAttrs attrs ["disabled" "checkInputs"] // {
nix_debug "ROCKSPEC $rockspecFilename"
nix_debug "cwd: $PWD"
- $LUAROCKS make --deps-mode=none --tree $out ''${rockspecFilename}
-
- # to prevent collisions when creating environments
- # also added -f as it doesn't always exist
- # don't remove the whole directory as
- rm -rf $out/lib/luarocks/rocks-${lua.luaversion}/manifest
+ $LUAROCKS make --deps-mode=all --tree=$out ''${rockspecFilename}
runHook postInstall
'';
passthru = {
inherit lua; # The lua interpreter
+ inherit externalDeps;
} // passthru;
meta = with lib.maintainers; {
platforms = lua.meta.platforms;
# add extra maintainer(s) to every package
maintainers = (meta.maintainers or []) ++ [ ];
+ broken = disabled;
} // meta;
}))