1# do not add pkgs, it messes up splicing
2{ stdenv
3, cmake
4, curl
5, cyrus_sasl
6, dbus
7, expat
8, fetchFromGitHub
9, fetchpatch
10, fetchurl
11, fixDarwinDylibNames
12, glib
13, glibc
14, gmp
15, gnulib
16, gnum4
17, gobject-introspection
18, installShellFiles
19, lib
20, libevent
21, libiconv
22, libmpack
23, libmysqlclient
24, libuuid
25, libuv
26, libxcrypt
27, libyaml
28, mariadb
29, mpfr
30, neovim-unwrapped
31, openldap
32, openssl
33, pcre
34, pkg-config
35, postgresql
36, readline
37, sqlite
38, unbound
39, vimPlugins
40, vimUtils
41, yajl
42, zlib
43, zziplib
44}:
45
46final: prev:
47with prev;
48{
49 ##########################################3
50 #### manual fixes for generated packages
51 ##########################################3
52 bit32 = prev.bit32.overrideAttrs (oa: {
53 # Small patch in order to no longer redefine a Lua 5.2 function that Luajit
54 # 2.1 also provides, see https://github.com/LuaJIT/LuaJIT/issues/325 for
55 # more
56 patches = [
57 ./bit32.patch
58 ];
59 meta.broken = luaOlder "5.1" || luaAtLeast "5.4";
60 });
61
62 busted = prev.busted.overrideAttrs (oa: {
63 nativeBuildInputs = oa.nativeBuildInputs ++ [
64 installShellFiles
65 ];
66 postConfigure = ''
67 substituteInPlace ''${rockspecFilename} \
68 --replace "'lua_cliargs = 3.0-1'," "'lua_cliargs >= 3.0-1',"
69 '';
70 postInstall = ''
71 installShellCompletion --cmd busted \
72 --zsh completions/zsh/_busted \
73 --bash completions/bash/busted.bash
74 '';
75 });
76
77 cqueues = prev.cqueues.overrideAttrs (oa: rec {
78 # Parse out a version number without the Lua version inserted
79 version = with lib; let
80 version' = prev.cqueues.version;
81 rel = splitVersion version';
82 date = head rel;
83 rev = last (splitString "-" (last rel));
84 in
85 "${date}-${rev}";
86
87 meta.broken = luaOlder "5.1" || luaAtLeast "5.4";
88
89 nativeBuildInputs = oa.nativeBuildInputs ++ [
90 gnum4
91 ];
92
93 externalDeps = [
94 { name = "CRYPTO"; dep = openssl; }
95 { name = "OPENSSL"; dep = openssl; }
96 ];
97
98 # Upstream rockspec is pointlessly broken into separate rockspecs, per Lua
99 # version, which doesn't work well for us, so modify it
100 postConfigure = let inherit (prev.cqueues) pname; in
101 ''
102 # 'all' target auto-detects correct Lua version, which is fine for us as
103 # we only have the right one available :)
104 sed -Ei ''${rockspecFilename} \
105 -e 's|lua == 5.[[:digit:]]|lua >= 5.1, <= 5.3|' \
106 -e 's|build_target = "[^"]+"|build_target = "all"|' \
107 -e 's|version = "[^"]+"|version = "${version}"|'
108 specDir=$(dirname ''${rockspecFilename})
109 cp ''${rockspecFilename} "$specDir/${pname}-${version}.rockspec"
110 rockspecFilename="$specDir/${pname}-${version}.rockspec"
111 '';
112 });
113
114 cyrussasl = prev.cyrussasl.overrideAttrs (drv: {
115 externalDeps = [
116 { name = "LIBSASL"; dep = cyrus_sasl; }
117 ];
118 });
119
120 fennel = prev.fennel.overrideAttrs(oa: {
121 nativeBuildInputs = oa.nativeBuildInputs ++ [
122 installShellFiles
123 ];
124 postInstall = ''
125 installManPage fennel.1
126 '';
127 });
128
129 http = prev.http.overrideAttrs (oa: {
130 patches = [
131 (fetchpatch {
132 name = "invalid-state-progression.patch";
133 url = "https://github.com/daurnimator/lua-http/commit/cb7b59474a.diff";
134 sha256 = "1vmx039n3nqfx50faqhs3wgiw28ws416rhw6vh6srmh9i826dac7";
135 })
136 ];
137 /* TODO: separate docs derivation? (pandoc is heavy)
138 nativeBuildInputs = [ pandoc ];
139 makeFlags = [ "-C doc" "lua-http.html" "lua-http.3" ];
140 */
141 });
142
143 lpty = prev.lpty.overrideAttrs (oa: {
144 meta.broken = luaOlder "5.1" || luaAtLeast "5.3";
145 });
146
147 ldbus = prev.ldbus.overrideAttrs (oa: {
148 extraVariables = {
149 DBUS_DIR = "${dbus.lib}";
150 DBUS_ARCH_INCDIR = "${dbus.lib}/lib/dbus-1.0/include";
151 DBUS_INCDIR = "${dbus.dev}/include/dbus-1.0";
152 };
153 buildInputs = [
154 dbus
155 ];
156 });
157
158 ljsyscall = prev.ljsyscall.overrideAttrs (oa: rec {
159 version = "unstable-20180515";
160 # package hasn't seen any release for a long time
161 src = fetchFromGitHub {
162 owner = "justincormack";
163 repo = "ljsyscall";
164 rev = "e587f8c55aad3955dddab3a4fa6c1968037b5c6e";
165 sha256 = "06v52agqyziwnbp2my3r7liv245ddmb217zmyqakh0ldjdsr8lz4";
166 };
167 knownRockspec = "rockspec/ljsyscall-scm-1.rockspec";
168 # actually library works fine with lua 5.2
169 preConfigure = ''
170 sed -i 's/lua == 5.1/lua >= 5.1, < 5.3/' ${knownRockspec}
171 '';
172 meta.broken = luaOlder "5.1" || luaAtLeast "5.3";
173
174 propagatedBuildInputs = with lib; oa.propagatedBuildInputs ++ optional (!isLuaJIT) luaffi;
175 });
176
177 lgi = prev.lgi.overrideAttrs (oa: {
178 nativeBuildInputs = oa.nativeBuildInputs ++ [
179 pkg-config
180 ];
181 buildInputs = [
182 glib
183 gobject-introspection
184 ];
185 patches = [
186 (fetchpatch {
187 name = "lgi-find-cairo-through-typelib.patch";
188 url = "https://github.com/psychon/lgi/commit/46a163d9925e7877faf8a4f73996a20d7cf9202a.patch";
189 sha256 = "0gfvvbri9kyzhvq3bvdbj2l6mwvlz040dk4mrd5m9gz79f7w109c";
190 })
191 ];
192
193 # https://github.com/lgi-devs/lgi/pull/300
194 postPatch = ''
195 substituteInPlace lgi/Makefile tests/Makefile \
196 --replace 'PKG_CONFIG =' 'PKG_CONFIG ?='
197 '';
198
199 # there is only a rockspec.in in the repo, the actual rockspec must be generated
200 preConfigure = ''
201 make rock
202 '';
203 });
204
205 lmathx = prev.luaLib.overrideLuarocks prev.lmathx (drv:
206 if luaAtLeast "5.1" && luaOlder "5.2" then {
207 version = "20120430.51-1";
208 knownRockspec = (fetchurl {
209 url = "https://luarocks.org/lmathx-20120430.51-1.rockspec";
210 sha256 = "148vbv2g3z5si2db7rqg5bdily7m4sjyh9w6r3jnx3csvfaxyhp0";
211 }).outPath;
212 src = fetchurl {
213 url = "https://web.tecgraf.puc-rio.br/~lhf/ftp/lua/5.1/lmathx.tar.gz";
214 sha256 = "0sa553d0zlxhvpsmr4r7d841f16yq4wr3fg7i07ibxkz6yzxax51";
215 };
216 } else
217 if luaAtLeast "5.2" && luaOlder "5.3" then {
218 version = "20120430.52-1";
219 knownRockspec = (fetchurl {
220 url = "https://luarocks.org/lmathx-20120430.52-1.rockspec";
221 sha256 = "14rd625sipakm72wg6xqsbbglaxyjba9nsajsfyvhg0sz8qjgdya";
222 }).outPath;
223 src = fetchurl {
224 url = "http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/5.2/lmathx.tar.gz";
225 sha256 = "19dwa4z266l2njgi6fbq9rak4rmx2fsx1s0p9sl166ar3mnrdwz5";
226 };
227 } else
228 {
229 disabled = luaOlder "5.1" || luaAtLeast "5.5";
230 # works fine with 5.4 as well
231 postConfigure = ''
232 substituteInPlace ''${rockspecFilename} \
233 --replace 'lua ~> 5.3' 'lua >= 5.3, < 5.5'
234 '';
235 });
236
237 lmpfrlib = prev.lmpfrlib.overrideAttrs (oa: {
238 externalDeps = [
239 { name = "GMP"; dep = gmp; }
240 { name = "MPFR"; dep = mpfr; }
241 ];
242 unpackPhase = ''
243 cp $src $(stripHash $src)
244 '';
245 });
246
247 lrexlib-gnu = prev.lrexlib-gnu.overrideAttrs (oa: {
248 buildInputs = oa.buildInputs ++ [
249 gnulib
250 ];
251 });
252
253 lrexlib-pcre = prev.lrexlib-pcre.overrideAttrs (oa: {
254 externalDeps = [
255 { name = "PCRE"; dep = pcre; }
256 ];
257 });
258
259 lrexlib-posix = prev.lrexlib-posix.overrideAttrs (oa: {
260 buildInputs = oa.buildInputs ++ [
261 glibc.dev
262 ];
263 });
264
265 lua-curl = prev.lua-curl.overrideAttrs (oa: {
266 buildInputs = oa.buildInputs ++ [
267 curl.dev
268 ];
269 });
270
271 lua-iconv = prev.lua-iconv.overrideAttrs (oa: {
272 buildInputs = oa.buildInputs ++ [
273 libiconv
274 ];
275 });
276
277 lua-lsp = prev.lua-lsp.overrideAttrs (oa: {
278 # until Alloyed/lua-lsp#28
279 postConfigure = ''
280 substituteInPlace ''${rockspecFilename} \
281 --replace '"dkjson ~> 2.5",' '"dkjson >= 2.5",'
282 '';
283 });
284
285 lua-zlib = prev.lua-zlib.overrideAttrs (oa: {
286 buildInputs = oa.buildInputs ++ [
287 zlib.dev
288 ];
289 meta.broken = luaOlder "5.1" || luaAtLeast "5.4";
290 });
291
292 luadbi-mysql = prev.luadbi-mysql.overrideAttrs (oa: {
293 extraVariables = {
294 # Can't just be /include and /lib, unfortunately needs the trailing 'mysql'
295 MYSQL_INCDIR = "${libmysqlclient.dev}/include/mysql";
296 MYSQL_LIBDIR = "${libmysqlclient}/lib/mysql";
297 };
298 buildInputs = oa.buildInputs ++ [
299 mariadb.client
300 libmysqlclient
301 ];
302 });
303
304 luadbi-postgresql = prev.luadbi-postgresql.overrideAttrs (oa: {
305 buildInputs = oa.buildInputs ++ [
306 postgresql
307 ];
308 });
309
310 luadbi-sqlite3 = prev.luadbi-sqlite3.overrideAttrs (oa: {
311 externalDeps = [
312 { name = "SQLITE"; dep = sqlite; }
313 ];
314 });
315
316 luaevent = prev.luaevent.overrideAttrs (oa: {
317 propagatedBuildInputs = oa.propagatedBuildInputs ++ [
318 luasocket
319 ];
320 externalDeps = [
321 { name = "EVENT"; dep = libevent; }
322 ];
323 disabled = luaOlder "5.1" || luaAtLeast "5.4";
324 });
325
326 luaexpat = prev.luaexpat.overrideAttrs (_: {
327 externalDeps = [
328 { name = "EXPAT"; dep = expat; }
329 ];
330 });
331
332 # TODO Somehow automatically amend buildInputs for things that need luaffi
333 # but are in luajitPackages?
334 luaffi = prev.luaffi.overrideAttrs (oa: {
335 # The packaged .src.rock version is pretty old, and doesn't work with Lua 5.3
336 src = fetchFromGitHub {
337 owner = "facebook";
338 repo = "luaffifb";
339 rev = "532c757e51c86f546a85730b71c9fef15ffa633d";
340 sha256 = "1nwx6sh56zfq99rcs7sph0296jf6a9z72mxknn0ysw9fd7m1r8ig";
341 };
342 knownRockspec = with prev.luaffi; "${pname}-${version}.rockspec";
343 meta.broken = luaOlder "5.1" || luaAtLeast "5.4" || isLuaJIT;
344 });
345
346 lualdap = prev.lualdap.overrideAttrs (_: {
347 externalDeps = [
348 { name = "LDAP"; dep = openldap; }
349 ];
350 });
351
352 luaossl = prev.luaossl.overrideAttrs (_: {
353 externalDeps = [
354 { name = "CRYPTO"; dep = openssl; }
355 { name = "OPENSSL"; dep = openssl; }
356 ];
357 });
358
359 luaposix = prev.luaposix.overrideAttrs (_: {
360 externalDeps = [
361 { name = "CRYPT"; dep = libxcrypt; }
362 ];
363 });
364
365 luasec = prev.luasec.overrideAttrs (oa: {
366 externalDeps = [
367 { name = "OPENSSL"; dep = openssl; }
368 ];
369 });
370
371 luasql-sqlite3 = prev.luasql-sqlite3.overrideAttrs (oa: {
372 externalDeps = [
373 { name = "SQLITE"; dep = sqlite; }
374 ];
375 });
376
377 luasystem = prev.luasystem.overrideAttrs (oa: lib.optionalAttrs stdenv.isLinux {
378 buildInputs = [ glibc.out ];
379 });
380
381 luazip = prev.luazip.overrideAttrs (oa: {
382 buildInputs = oa.buildInputs ++ [
383 zziplib
384 ];
385 });
386
387 lua-yajl = prev.lua-yajl.overrideAttrs (oa: {
388 buildInputs = oa.buildInputs ++ [
389 yajl
390 ];
391 });
392
393 luaunbound = prev.luaunbound.overrideAttrs (oa: {
394 externalDeps = [
395 { name = "libunbound"; dep = unbound; }
396 ];
397 });
398
399 lua-subprocess = prev.lua-subprocess.overrideAttrs (oa: {
400 meta.broken = luaOlder "5.1" || luaAtLeast "5.4";
401 });
402
403 lush-nvim = prev.lush-nvim.overrideAttrs (drv: {
404 doCheck = false;
405 });
406
407 luuid = prev.luuid.overrideAttrs (oa: {
408 externalDeps = [
409 { name = "LIBUUID"; dep = libuuid; }
410 ];
411 # Trivial patch to make it work in both 5.1 and 5.2. Basically just the
412 # tiny diff between the two upstream versions placed behind an #if.
413 # Upstreams:
414 # 5.1: http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/5.1/luuid.tar.gz
415 # 5.2: http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/5.2/luuid.tar.gz
416 patchFlags = [ "-p2" ];
417 patches = [
418 ./luuid.patch
419 ];
420 postConfigure = ''
421 sed -Ei ''${rockspecFilename} -e 's|lua >= 5.2|lua >= 5.1,|'
422 '';
423 meta = oa.meta // {
424 broken = luaOlder "5.1" || (luaAtLeast "5.4");
425 platforms = lib.platforms.linux;
426 };
427 });
428
429
430 # as advised in https://github.com/luarocks/luarocks/issues/1402#issuecomment-1080616570
431 # we shouldn't use luarocks machinery to build complex cmake components
432 libluv = stdenv.mkDerivation {
433
434 pname = "libluv";
435 inherit (prev.luv) version meta src;
436
437 cmakeFlags = [
438 "-DBUILD_SHARED_LIBS=ON"
439 "-DBUILD_MODULE=OFF"
440 "-DWITH_SHARED_LIBUV=ON"
441 "-DLUA_BUILD_TYPE=System"
442 "-DWITH_LUA_ENGINE=${if isLuaJIT then "LuaJit" else "Lua"}"
443 ];
444
445 # to make sure we dont use bundled deps
446 postUnpack = ''
447 rm -rf deps/lua deps/libuv
448 '';
449
450 buildInputs = [ libuv final.lua ];
451
452 nativeBuildInputs = [ pkg-config cmake ]
453 ++ lib.optionals stdenv.isDarwin [ fixDarwinDylibNames ];
454 };
455
456 luv = prev.luv.overrideAttrs (oa: {
457
458 nativeBuildInputs = oa.nativeBuildInputs ++ [ pkg-config ];
459 buildInputs = [ libuv ];
460
461 # Use system libuv instead of building local and statically linking
462 extraVariables = {
463 WITH_SHARED_LIBUV = "ON";
464 };
465
466 # we unset the LUA_PATH since the hook erases the interpreter defaults (To fix)
467 # tests is not run since they are not part of the tarball anymore
468 preCheck = ''
469 unset LUA_PATH
470 rm tests/test-{dns,thread}.lua
471 '';
472 });
473
474 lyaml = prev.lyaml.overrideAttrs (oa: {
475 buildInputs = [
476 libyaml
477 ];
478 });
479
480 mpack = prev.mpack.overrideAttrs (drv: {
481 buildInputs = (drv.buildInputs or []) ++ [ libmpack ];
482 env = {
483 # the rockspec doesn't use the makefile so you may need to export more flags
484 USE_SYSTEM_LUA = "yes";
485 USE_SYSTEM_MPACK = "yes";
486 };
487 });
488
489 rapidjson = prev.rapidjson.overrideAttrs (oa: {
490 preBuild = ''
491 sed -i '/set(CMAKE_CXX_FLAGS/d' CMakeLists.txt
492 sed -i '/set(CMAKE_C_FLAGS/d' CMakeLists.txt
493 '';
494 });
495
496 readline = prev.readline.overrideAttrs (oa: {
497 propagatedBuildInputs = oa.propagatedBuildInputs ++ [ readline.out ];
498 extraVariables = rec {
499 READLINE_INCDIR = "${readline.dev}/include";
500 HISTORY_INCDIR = READLINE_INCDIR;
501 };
502 unpackCmd = ''
503 unzip "$curSrc"
504 tar xf *.tar.gz
505 '';
506 # Without this, source root is wrongly set to ./readline-2.6/doc
507 setSourceRoot = ''
508 sourceRoot=./readline-${lib.versions.majorMinor oa.version}
509 '';
510 });
511
512 sqlite = prev.sqlite.overrideAttrs (drv: {
513
514 doCheck = true;
515 nativeCheckInputs = [ final.plenary-nvim neovim-unwrapped ];
516
517 # we override 'luarocks test' because otherwise neovim doesn't find/load the plenary plugin
518 checkPhase = ''
519 export LIBSQLITE="${sqlite.out}/lib/libsqlite3${stdenv.hostPlatform.extensions.sharedLibrary}"
520 export HOME="$TMPDIR";
521
522 nvim --headless -i NONE \
523 -u test/minimal_init.vim --cmd "set rtp+=${vimPlugins.plenary-nvim}" \
524 -c "PlenaryBustedDirectory test/auto/ { minimal_init = './test/minimal_init.vim' }"
525 '';
526
527 });
528
529 std-_debug = prev.std-_debug.overrideAttrs (oa: {
530 # run make to generate lib/std/_debug/version.lua
531 preConfigure = ''
532 make all
533 '';
534 });
535
536 std-normalize = prev.std-normalize.overrideAttrs (oa: {
537 # run make to generate lib/std/_debug/version.lua
538 preConfigure = ''
539 make all
540 '';
541 });
542
543 vstruct = prev.vstruct.overrideAttrs (_: {
544 meta.broken = (luaOlder "5.1" || luaAtLeast "5.3");
545 });
546
547 vusted = prev.vusted.overrideAttrs (_: {
548 # make sure vusted_entry.vim doesn't get wrapped
549 postInstall = ''
550 chmod -x $out/bin/vusted_entry.vim
551 '';
552 });
553
554
555 # aliases
556 cjson = prev.lua-cjson;
557}