1{
2 stdenv,
3 lib,
4 buildLuarocksPackage,
5 cmake,
6 fetchFromGitHub,
7 libuv,
8 lua,
9 luaOlder,
10 nix-update-script,
11 runCommand,
12}:
13
14buildLuarocksPackage rec {
15 pname = "luv";
16 version = "1.50.0-1";
17
18 src = fetchFromGitHub {
19 owner = "luvit";
20 repo = "luv";
21 rev = version;
22 # Need deps/lua-compat-5.3 only
23 fetchSubmodules = true;
24 hash = "sha256-PS3+qpELpX0tr7UqrlnE4NYScJb50j+9J4fbH9CTr/s=";
25 };
26
27 # to make sure we dont use bundled deps
28 prePatch = ''
29 rm -rf deps/lua deps/luajit deps/libuv
30 '';
31
32 patches =
33 [
34 # Fails with "Uncaught Error: ./tests/test-dns.lua:164: assertion failed!"
35 # and "./tests/test-tty.lua:19: bad argument #1 to 'is_readable' (Expected
36 # uv_stream userdata)"
37 ./disable-failing-tests.patch
38 ]
39 ++ lib.optionals stdenv.hostPlatform.isDarwin [
40 # Fails with "Uncaught Error: ./tests/test-udp.lua:261: EHOSTUNREACH"
41 ./disable-failing-darwin-tests.patch
42 ];
43
44 buildInputs = [ libuv ];
45 nativeBuildInputs = [ cmake ];
46
47 # Need to specify WITH_SHARED_LIBUV=ON cmake flag, but
48 # Luarocks doesn't take cmake variables from luarocks config.
49 # Need to specify it in rockspec. See https://github.com/luarocks/luarocks/issues/1160.
50 knownRockspec = runCommand "luv-${version}.rockspec" { } ''
51 patch ${src}/luv-scm-0.rockspec -o - > $out <<'EOF'
52 --- a/luv-scm-0.rockspec
53 +++ b/luv-scm-0.rockspec
54 @@ -1,5 +1,5 @@
55 package = "luv"
56 -version = "scm-0"
57 +version = "${version}"
58 source = {
59 url = 'git://github.com/luvit/luv.git'
60 }
61 @@ -24,6 +24,7 @@
62 build =
63 type = 'cmake',
64 variables = {
65 + WITH_SHARED_LIBUV="ON",
66 CMAKE_C_FLAGS="$(CFLAGS)",
67 CMAKE_MODULE_LINKER_FLAGS="$(LIBFLAG)",
68 LUA_LIBDIR="$(LUA_LIBDIR)",
69 EOF
70 '';
71
72 __darwinAllowLocalNetworking = true;
73
74 doInstallCheck = true;
75 installCheckPhase = ''
76 runHook preInstallCheck
77 luarocks test
78 runHook postInstallCheck
79 '';
80
81 disabled = luaOlder "5.1";
82
83 passthru = {
84 tests.test =
85 runCommand "luv-${version}-test"
86 {
87 nativeBuildInputs = [ (lua.withPackages (ps: [ ps.luv ])) ];
88 }
89 ''
90 lua <<EOF
91 local uv = require("luv")
92 assert(uv.fs_mkdir(assert(uv.os_getenv("out")), 493))
93 print(uv.version_string())
94 EOF
95 '';
96
97 updateScript = nix-update-script { };
98 };
99
100 meta = {
101 homepage = "https://github.com/luvit/luv";
102 description = "Bare libuv bindings for lua";
103 longDescription = ''
104 This library makes libuv available to lua scripts. It was made for the luvit
105 project but should usable from nearly any lua project.
106 '';
107 license = lib.licenses.asl20;
108 maintainers = with lib.maintainers; [ stasjok ];
109 platforms = lua.meta.platforms;
110 };
111}