diff options
-rw-r--r-- | pkgs/development/interpreters/lua-5/build-lua-package.nix | 63 | ||||
-rw-r--r-- | pkgs/development/interpreters/lua-5/hooks/default.nix | 27 | ||||
-rw-r--r-- | pkgs/development/interpreters/lua-5/hooks/setup-hook.sh (renamed from pkgs/development/interpreters/lua-5/setup-hook.sh) | 0 | ||||
-rw-r--r-- | pkgs/development/interpreters/lua-5/setup-hook.nix | 15 | ||||
-rw-r--r-- | pkgs/development/lua-modules/lib.nix | 68 | ||||
-rw-r--r-- | pkgs/top-level/lua-packages.nix | 16 |
6 files changed, 112 insertions, 77 deletions
diff --git a/pkgs/development/interpreters/lua-5/build-lua-package.nix b/pkgs/development/interpreters/lua-5/build-lua-package.nix index 64e872ad5f6..e74649cab4a 100644 --- a/pkgs/development/interpreters/lua-5/build-lua-package.nix +++ b/pkgs/development/interpreters/lua-5/build-lua-package.nix @@ -82,66 +82,25 @@ let # configured trees) luarocks_config = "luarocks-config.lua"; luarocks_content = let - extraVariablesStr = lib.concatStringsSep "\n " - (lib.mapAttrsToList (k: v: "${k}='${v}';") extraVariables); - in '' - local_cache = "" - -- 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 = { - ${lib.concatStringsSep "\n, " externalDepsDirs} - } - 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}''} - ${extraVariablesStr} - } - ${extraConfig} - ''; + generatedConfig = lua.pkgs.lib.generateLuarocksConfig { + inherit externalDeps; + inherit extraVariables; + inherit rocksSubdir; + inherit requiredLuaRocks; + }; + in + '' + ${generatedConfig} + ${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 diff --git a/pkgs/development/interpreters/lua-5/hooks/default.nix b/pkgs/development/interpreters/lua-5/hooks/default.nix new file mode 100644 index 00000000000..8fd725a9b8a --- /dev/null +++ b/pkgs/development/interpreters/lua-5/hooks/default.nix @@ -0,0 +1,27 @@ +# Hooks for building lua packages. +{ lua +, lib +, makeSetupHook +, findutils +, runCommand +}: + +let + callPackage = lua.pkgs.callPackage; + luaInterpreter = lua.interpreter; +in { + + lua-setup-hook = LuaPathSearchPaths: LuaCPathSearchPaths: + let + hook = ./setup-hook.sh; + in runCommand "lua-setup-hook.sh" { + # hum doesn't seem to like caps !! BUG ? + luapathsearchpaths=lib.escapeShellArgs LuaPathSearchPaths; + luacpathsearchpaths=lib.escapeShellArgs LuaCPathSearchPaths; + } '' + cp ${hook} hook.sh + substituteAllInPlace hook.sh + mv hook.sh $out + ''; + +} diff --git a/pkgs/development/interpreters/lua-5/setup-hook.sh b/pkgs/development/interpreters/lua-5/hooks/setup-hook.sh index 1c445b82afd..1c445b82afd 100644 --- a/pkgs/development/interpreters/lua-5/setup-hook.sh +++ b/pkgs/development/interpreters/lua-5/hooks/setup-hook.sh diff --git a/pkgs/development/interpreters/lua-5/setup-hook.nix b/pkgs/development/interpreters/lua-5/setup-hook.nix index 62caffd8d8a..e69de29bb2d 100644 --- a/pkgs/development/interpreters/lua-5/setup-hook.nix +++ b/pkgs/development/interpreters/lua-5/setup-hook.nix @@ -1,15 +0,0 @@ -{ runCommand, lib, }: - -LuaPathSearchPaths: LuaCPathSearchPaths: - -let - hook = ./setup-hook.sh; -in runCommand "lua-setup-hook.sh" { - # hum doesn't seem to like caps !! BUG ? - luapathsearchpaths=lib.escapeShellArgs LuaPathSearchPaths; - luacpathsearchpaths=lib.escapeShellArgs LuaCPathSearchPaths; -} '' - cp ${hook} hook.sh - substituteAllInPlace hook.sh - mv hook.sh $out -'' diff --git a/pkgs/development/lua-modules/lib.nix b/pkgs/development/lua-modules/lib.nix index 9c31f9a5c53..0d429b3ba6d 100644 --- a/pkgs/development/lua-modules/lib.nix +++ b/pkgs/development/lua-modules/lib.nix @@ -60,4 +60,72 @@ rec { requiredLuaModules = requiredLuaModules drv.propagatedBuildInputs; }; }); + + /* generate luarocks config + + generateLuarocksConfig { + externalDeps = [ { name = "CRYPTO"; dep = pkgs.openssl; } ]; + rocksSubdir = "subdir"; + }; + */ + generateLuarocksConfig = { + externalDeps + , requiredLuaRocks + , extraVariables ? {} + , rocksSubdir + }: let + rocksTrees = lib.imap0 + (i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }") + requiredLuaRocks; + + # 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; + + externalDepsDirs = map + (x: "'${builtins.toString x}'") + (lib.filter (lib.isDerivation) externalDeps); + + extraVariablesStr = lib.concatStringsSep "\n " + (lib.mapAttrsToList (k: v: "${k}='${v}';") extraVariables); + in '' + local_cache = "" + -- 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 = { + ${lib.concatStringsSep "\n, " externalDepsDirs} + } + 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}''} + ${extraVariablesStr} + } + ''; } diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix index 80f71dc1942..3d8272633f1 100644 --- a/pkgs/top-level/lua-packages.nix +++ b/pkgs/top-level/lua-packages.nix @@ -12,18 +12,12 @@ , fetchFromGitHub, which, writeText , pkgs , lib -}: +}@args: let packages = ( self: let - - # a function of lua_path / lua_cpath - lua-setup-hook = callPackage ../development/interpreters/lua-5/setup-hook.nix { - inherit lib; - }; - callPackage = pkgs.newScope self; buildLuaApplication = args: buildLuarocksPackage ({namePrefix="";} // args ); @@ -52,11 +46,13 @@ in # helper functions for dealing with LUA_PATH and LUA_CPATH lib = luaLib; - getLuaPath = drv: luaLib.getPath drv (luaLib.luaPathList lua.luaversion) ; - getLuaCPath = drv: luaLib.getPath drv (luaLib.luaCPathList lua.luaversion) ; + getLuaPath = drv: getPath drv (luaLib.luaPathList lua.luaversion) ; + getLuaCPath = drv: getPath drv (luaLib.luaCPathList lua.luaversion) ; + inherit (callPackage ../development/interpreters/lua-5/hooks { inherit (args) lib;}) + lua-setup-hook; - inherit lua lua-setup-hook callPackage; + inherit lua callPackage; inherit buildLuaPackage buildLuarocksPackage buildLuaApplication; inherit (luaLib) luaOlder luaAtLeast isLua51 isLua52 isLua53 isLuaJIT requiredLuaModules toLuaModule hasLuaModule; |