@@ -82,66 +82,25 @@ let
8282 # configured trees)
8383 luarocks_config = "luarocks-config.lua";
8484 luarocks_content = let
85− extraVariablesStr = lib.concatStringsSep "\n "
86− (lib.mapAttrsToList (k: v: "${k}='${v}';") extraVariables);
87− in ''
88− local_cache = ""
89− -- To prevent collisions when creating environments, we install the rock
90− -- files into per-package subdirectories
91− rocks_subdir = '${rocksSubdir}'
92− -- Then we need to tell luarocks where to find the rock files per
93− -- dependency
94− rocks_trees = {
95− ${lib.concatStringsSep "\n, " rocksTrees}
96− }
97− '' + lib.optionalString lua.pkgs.isLuaJIT ''
98− -- Luajit provides some additional functionality built-in; this exposes
99− -- that to luarock's dependency system
100− rocks_provided = {
101− jit='${lua.luaversion}-1';
102− ffi='${lua.luaversion}-1';
103− luaffi='${lua.luaversion}-1';
104− bit='${lua.luaversion}-1';
105− }
106− '' + ''
107− -- For single-output external dependencies
108− external_deps_dirs = {
109− ${lib.concatStringsSep "\n, " externalDepsDirs}
110− }
111− variables = {
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}
117− }
118− ${extraConfig}
119− '';
85+ generatedConfig = lua.pkgs.lib.generateLuarocksConfig {
86+ inherit externalDeps;
87+ inherit extraVariables;
88+ inherit rocksSubdir;
89+ inherit requiredLuaRocks;
90+ };
91+ in
92+ ''
93+ ${generatedConfig}
94+ ${extraConfig}
95+ '';
12096
12197 rocksSubdir = "${attrs.pname}-${version}-rocks";
12298
123− externalDepsDirs = map
124− (x: "'${builtins.toString x}'")
125− (lib.filter (lib.isDerivation) externalDeps);
126−
127− rocksTrees = lib.imap0
128− (i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }")
129− requiredLuaRocks;
130−
13199 # Filter out the lua derivation itself from the Lua module dependency
132100 # closure, as it doesn't have a rock tree :)
133101 requiredLuaRocks = lib.filter (d: d ? luaModule)
134102 (lua.pkgs.requiredLuaModules propagatedBuildInputs);
135103
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';"
143− ]) externalDeps';
144−
145104 # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
146105 externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
147106in