|
| 1 | +{ pkgs, lib, lua }: |
| 2 | +let |
| 3 | + requiredLuaModules = drvs: with lib; let |
| 4 | + modules = filter hasLuaModule drvs; |
| 5 | + in unique ([lua] ++ modules ++ concatLists (catAttrs "requiredLuaModules" modules)); |
| 6 | + # Check whether a derivation provides a lua module. |
| 7 | + hasLuaModule = drv: drv ? luaModule; |
| 8 | +in |
| 9 | +rec { |
| 10 | + inherit hasLuaModule requiredLuaModules; |
| 11 | + |
| 12 | + luaPathList = [ |
| 13 | + "share/lua/${lua.luaversion}/?.lua" |
| 14 | + "share/lua/${lua.luaversion}/?/init.lua" |
| 15 | + ]; |
| 16 | + luaCPathList = [ |
| 17 | + "lib/lua/${lua.luaversion}/?.so" |
| 18 | + ]; |
| 19 | + |
| 20 | + /* generate paths without a prefix |
| 21 | + */ |
| 22 | + luaPathRelStr = lib.concatStringsSep ";" luaPathList; |
| 23 | + luaCPathRelStr = lib.concatStringsSep ";" luaCPathList; |
| 24 | + |
| 25 | + /* generate LUA_(C)PATH value for a specific derivation, i.e., with absolute paths |
| 26 | + */ |
| 27 | + genLuaPathAbsStr = drv: lib.concatMapStringsSep ";" (x: "${drv}/${x}") luaPathList; |
| 28 | + genLuaCPathAbsStr = drv: lib.concatMapStringsSep ";" (x: "${drv}/${x}") luaCPathList; |
| 29 | + |
| 30 | + /* Generate a LUA_PATH with absolute paths |
| 31 | + */ |
| 32 | + # genLuaPathAbs = drv: |
| 33 | + # lib.concatStringsSep ";" (map (x: "${drv}/x") luaPathList); |
| 34 | + |
| 35 | + luaAtLeast = lib.versionAtLeast lua.luaversion; |
| 36 | + luaOlder = lib.versionOlder lua.luaversion; |
| 37 | + isLua51 = (lib.versions.majorMinor lua.version) == "5.1"; |
| 38 | + isLua52 = (lib.versions.majorMinor lua.version) == "5.2"; |
| 39 | + isLua53 = lua.luaversion == "5.3"; |
| 40 | + isLuaJIT = lib.getName lua == "luajit"; |
| 41 | + |
| 42 | + /* generates the relative path towards the folder where |
| 43 | + seems stable even when using lua_modules_path = "" |
| 44 | +
|
| 45 | + Example: |
| 46 | + getDataFolder luaPackages.stdlib |
| 47 | + => stdlib-41.2.2-1-rocks/stdlib/41.2.2-1/doc |
| 48 | + */ |
| 49 | + getDataFolder = drv: |
| 50 | + "${drv.pname}-${drv.version}-rocks/${drv.pname}/${drv.version}"; |
| 51 | + |
| 52 | + /* Convert derivation to a lua module. |
| 53 | + so that luaRequireModules can be run later |
| 54 | + */ |
| 55 | + toLuaModule = drv: |
| 56 | + drv.overrideAttrs( oldAttrs: { |
| 57 | + # Use passthru in order to prevent rebuilds when possible. |
| 58 | + passthru = (oldAttrs.passthru or {})// { |
| 59 | + luaModule = lua; |
| 60 | + requiredLuaModules = requiredLuaModules drv.propagatedBuildInputs; |
| 61 | + }; |
| 62 | + }); |
| 63 | +} |
0 commit comments