@@ -82,66 +82,25 @@ let
82 # configured trees)
82 # configured trees)
83 luarocks_config = "luarocks-config.lua";
83 luarocks_config = "luarocks-config.lua";
84 luarocks_content = let
84 luarocks_content = let
85− extraVariablesStr = lib.concatStringsSep "\n "
85+ generatedConfig = lua.pkgs.lib.generateLuarocksConfig {
86+ inherit externalDeps;
86− (lib.mapAttrsToList (k: v: "${k}='${v}';") extraVariables);
87+ inherit extraVariables;
89− -- To prevent collisions when creating environments, we install the rock
90− -- files into per-package subdirectories
91− rocks_subdir = '${rocksSubdir}'
88+ inherit rocksSubdir;
92− -- Then we need to tell luarocks where to find the rock files per
89+ inherit requiredLuaRocks;
95− ${lib.concatStringsSep "\n, " rocksTrees}
97− '' + lib.optionalString lua.pkgs.isLuaJIT ''
91+ in
98− -- Luajit provides some additional functionality built-in; this exposes
92+ ''
99− -- that to luarock's dependency system
93+ ${generatedConfig}
101− jit='${lua.luaversion}-1';
102− ffi='${lua.luaversion}-1';
103− luaffi='${lua.luaversion}-1';
104− bit='${lua.luaversion}-1';
107− -- For single-output external dependencies
108− external_deps_dirs = {
109− ${lib.concatStringsSep "\n, " externalDepsDirs}
112− -- Some needed machinery to handle multiple-output external dependencies,
113− -- as per https://github.com/luarocks/luarocks/issues/766
114− ${lib.optionalString (lib.length depVariables > 0) ''
115− ${lib.concatStringsSep "\n " depVariables}''}
116− ${extraVariablesStr}
118− ${extraConfig}
94+ ${extraConfig}
121 rocksSubdir = "${attrs.pname}-${version}-rocks";
97 rocksSubdir = "${attrs.pname}-${version}-rocks";
123− externalDepsDirs = map
124− (x: "'${builtins.toString x}'")
125− (lib.filter (lib.isDerivation) externalDeps);
127− rocksTrees = lib.imap0
128− (i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }")
131 # Filter out the lua derivation itself from the Lua module dependency
99 # Filter out the lua derivation itself from the Lua module dependency
132 # closure, as it doesn't have a rock tree :)
100 # closure, as it doesn't have a rock tree :)
133 requiredLuaRocks = lib.filter (d: d ? luaModule)
101 requiredLuaRocks = lib.filter (d: d ? luaModule)
134 (lua.pkgs.requiredLuaModules propagatedBuildInputs);
102 (lua.pkgs.requiredLuaModules propagatedBuildInputs);
136− # Explicitly point luarocks to the relevant locations for multiple-output
137− # derivations that are external dependencies, to work around an issue it has
138− # (https://github.com/luarocks/luarocks/issues/766)
139− depVariables = lib.concatMap ({name, dep}: [
140− "${name}_INCDIR='${lib.getDev dep}/include';"
141− "${name}_LIBDIR='${lib.getLib dep}/lib';"
142− "${name}_BINDIR='${lib.getBin dep}/bin';"
145 # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
104 # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
146 externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
105 externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;