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.51.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-vQfr0TwhkvRDJwZnxDD/53yCzyDouzQimTnwj4drs/c=";
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 # Fails with "Uncaught Error: ./tests/test-dns.lua:164: assertion failed!"
34 # and "./tests/test-tty.lua:19: bad argument #1 to 'is_readable' (Expected
35 # uv_stream userdata)"
36 ./disable-failing-tests.patch
37 ]
38 ++ lib.optionals stdenv.hostPlatform.isDarwin [
39 # Fails with "Uncaught Error: ./tests/test-udp.lua:261: EHOSTUNREACH"
40 ./disable-failing-darwin-tests.patch
41 ];
42
43 buildInputs = [ libuv ];
44 nativeBuildInputs = [ cmake ];
45
46 # Need to specify WITH_SHARED_LIBUV=ON cmake flag, but
47 # Luarocks doesn't take cmake variables from luarocks config.
48 # Need to specify it in rockspec. See https://github.com/luarocks/luarocks/issues/1160.
49 knownRockspec = runCommand "luv-${version}.rockspec" { } ''
50 patch ${src}/luv-scm-0.rockspec -o - > $out <<'EOF'
51 --- a/luv-scm-0.rockspec
52 +++ b/luv-scm-0.rockspec
53 @@ -1,5 +1,5 @@
54 package = "luv"
55 -version = "scm-0"
56 +version = "${version}"
57 source = {
58 url = 'git://github.com/luvit/luv.git'
59 }
60 @@ -24,6 +24,7 @@
61 build =
62 type = 'cmake',
63 variables = {
64 + WITH_SHARED_LIBUV="ON",
65 CMAKE_C_FLAGS="$(CFLAGS)",
66 CMAKE_MODULE_LINKER_FLAGS="$(LIBFLAG)",
67 LUA_LIBDIR="$(LUA_LIBDIR)",
68 EOF
69 '';
70
71 __darwinAllowLocalNetworking = true;
72
73 doInstallCheck = true;
74 installCheckPhase = ''
75 runHook preInstallCheck
76 luarocks test
77 runHook postInstallCheck
78 '';
79
80 disabled = luaOlder "5.1";
81
82 passthru = {
83 tests.test =
84 runCommand "luv-${version}-test"
85 {
86 nativeBuildInputs = [ (lua.withPackages (ps: [ ps.luv ])) ];
87 }
88 ''
89 lua <<EOF
90 local uv = require("luv")
91 assert(uv.fs_mkdir(assert(uv.os_getenv("out")), 493))
92 print(uv.version_string())
93 EOF
94 '';
95
96 updateScript = nix-update-script { };
97 };
98
99 meta = {
100 homepage = "https://github.com/luvit/luv";
101 description = "Bare libuv bindings for lua";
102 longDescription = ''
103 This library makes libuv available to lua scripts. It was made for the luvit
104 project but should usable from nearly any lua project.
105 '';
106 license = lib.licenses.asl20;
107 maintainers = with lib.maintainers; [ stasjok ];
108 platforms = lua.meta.platforms;
109 };
110}