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;
11 Use this to override the arguments passed to buildLuarocksPackage
13 overrideLuarocks = drv: f: (drv.override (args: args // {
14 buildLuarocksPackage = drv: (args.buildLuarocksPackage drv).override f;
16 overrideScope = scope: overrideLuarocks (drv.overrideScope scope) f;
21 inherit overrideLuarocks;
22 inherit hasLuaModule requiredLuaModules;
25 "share/lua/${lua.luaversion}/?.lua"
26 "share/lua/${lua.luaversion}/?/init.lua"
29 "lib/lua/${lua.luaversion}/?.so"
32 /* generate paths without a prefix
34 luaPathRelStr = lib.concatStringsSep ";" luaPathList;
35 luaCPathRelStr = lib.concatStringsSep ";" luaCPathList;
37 /* generate LUA_(C)PATH value for a specific derivation, i.e., with absolute paths
39 genLuaPathAbsStr = drv: lib.concatMapStringsSep ";" (x: "${drv}/${x}") luaPathList;
40 genLuaCPathAbsStr = drv: lib.concatMapStringsSep ";" (x: "${drv}/${x}") luaCPathList;
42 /* Generate a LUA_PATH with absolute paths
44 # genLuaPathAbs = drv:
45 # lib.concatStringsSep ";" (map (x: "${drv}/x") luaPathList);
47 luaAtLeast = lib.versionAtLeast lua.luaversion;
48 luaOlder = lib.versionOlder lua.luaversion;
49 isLua51 = (lib.versions.majorMinor lua.version) == "5.1";
50 isLua52 = (lib.versions.majorMinor lua.version) == "5.2";
51 isLua53 = lua.luaversion == "5.3";
52 isLuaJIT = lib.getName lua == "luajit";
54 /* generates the relative path towards the folder where
55 seems stable even when using lua_modules_path = ""
58 getDataFolder luaPackages.stdlib
59 => stdlib-41.2.2-1-rocks/stdlib/41.2.2-1/doc
62 "${drv.pname}-${drv.version}-rocks/${drv.pname}/${drv.version}";
64 /* Convert derivation to a lua module.
65 so that luaRequireModules can be run later
68 drv.overrideAttrs( oldAttrs: {
69 # Use passthru in order to prevent rebuilds when possible.
70 passthru = (oldAttrs.passthru or {}) // {
72 requiredLuaModules = requiredLuaModules drv.propagatedBuildInputs;
76 /* generate luarocks config
78 generateLuarocksConfig {
79 externalDeps = [ { name = "CRYPTO"; dep = pkgs.openssl; } ];
80 rocksSubdir = "subdir";
83 generateLuarocksConfig = {
86 # a list of lua derivations
91 rocksTrees = lib.imap0
92 (i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }")
95 # Explicitly point luarocks to the relevant locations for multiple-output
96 # derivations that are external dependencies, to work around an issue it has
97 # (https://github.com/luarocks/luarocks/issues/766)
98 depVariables = lib.concatMap ({name, dep}: [
99 "${name}_INCDIR='${lib.getDev dep}/include';"
100 "${name}_LIBDIR='${lib.getLib dep}/lib';"
101 "${name}_BINDIR='${lib.getBin dep}/bin';"
104 # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
105 externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
107 externalDepsDirs = map
108 (x: "'${builtins.toString x}'")
109 (lib.filter (lib.isDerivation) externalDeps);
111 extraVariablesStr = lib.concatStringsSep "\n "
112 (lib.mapAttrsToList (k: v: "${k}='${v}';") extraVariables);
115 -- To prevent collisions when creating environments, we install the rock
116 -- files into per-package subdirectories
117 rocks_subdir = '${rocksSubdir}'
118 -- first tree is the default target where new rocks are installed,
119 -- any other trees in the list are treated as additional sources of installed rocks for matching dependencies.
121 {name = "current", root = '${placeholder "out"}', rocks_dir = "current" },
122 ${lib.concatStringsSep "\n, " rocksTrees}
124 '' + lib.optionalString lua.pkgs.isLuaJIT ''
125 -- Luajit provides some additional functionality built-in; this exposes
126 -- that to luarock's dependency system
128 jit='${lua.luaversion}-1';
129 ffi='${lua.luaversion}-1';
130 luaffi='${lua.luaversion}-1';
131 bit='${lua.luaversion}-1';
134 -- For single-output external dependencies
135 external_deps_dirs = {
136 ${lib.concatStringsSep "\n, " externalDepsDirs}
139 -- Some needed machinery to handle multiple-output external dependencies,
140 -- as per https://github.com/luarocks/luarocks/issues/766
141 ${lib.optionalString (lib.length depVariables > 0) ''
142 ${lib.concatStringsSep "\n " depVariables}''}