1{ stdenv, lib, fetchFromGitHub, fetchpatch, autoconf, automake, libtool, pkg-config, ApplicationServices, CoreServices, pkgsStatic }:
2
3stdenv.mkDerivation rec {
4 version = "1.44.2";
5 pname = "libuv";
6
7 src = fetchFromGitHub {
8 owner = pname;
9 repo = pname;
10 rev = "v${version}";
11 sha256 = "sha256-K6v+00basjI32ON27ZjC5spQi/zWCcslDwQwyosq2iY=";
12 };
13
14 outputs = [ "out" "dev" ];
15
16 patches = [
17 # Fix tests for statically linked variant upstream PR is
18 # https://github.com/libuv/libuv/pull/3735
19 (fetchpatch {
20 url = "https://github.com/libuv/libuv/commit/9d898acc564351dde74e9ed9865144e5c41f5beb.patch";
21 sha256 = "sha256-6XsjrseD8a+ny887EKOX0NmHocLMXGf2YL13vkNHUZ0=";
22 })
23 ];
24
25 postPatch = let
26 toDisable = [
27 "getnameinfo_basic" "udp_send_hang_loop" # probably network-dependent
28 "tcp_connect_timeout" # tries to reach out to 8.8.8.8
29 "spawn_setuid_fails" "spawn_setgid_fails" "fs_chown" # user namespaces
30 "getaddrinfo_fail" "getaddrinfo_fail_sync"
31 "threadpool_multiple_event_loops" # times out on slow machines
32 "get_passwd" # passed on NixOS but failed on other Linuxes
33 "tcp_writealot" "udp_multicast_join" "udp_multicast_join6" # times out sometimes
34 "fs_fstat" # https://github.com/libuv/libuv/issues/2235#issuecomment-1012086927
35
36 # Assertion failed in test/test-tcp-bind6-error.c on line 60: r == UV_EADDRINUSE
37 # Assertion failed in test/test-tcp-bind-error.c on line 99: r == UV_EADDRINUSE
38 "tcp_bind6_error_addrinuse" "tcp_bind_error_addrinuse_listen"
39 ] ++ lib.optionals stdenv.isDarwin [
40 # Sometimes: timeout (no output), failed uv_listen. Someone
41 # should report these failures to libuv team. There tests should
42 # be much more robust.
43 "process_title" "emfile" "poll_duplex" "poll_unidirectional"
44 "ipc_listen_before_write" "ipc_listen_after_write" "ipc_tcp_connection"
45 "tcp_alloc_cb_fail" "tcp_ping_pong" "tcp_ref3" "tcp_ref4"
46 "tcp_bind6_error_inval" "tcp_bind6_error_addrinuse" "tcp_read_stop"
47 "tcp_unexpected_read" "tcp_write_to_half_open_connection"
48 "tcp_oob" "tcp_close_accept" "tcp_create_early_accept"
49 "tcp_create_early" "tcp_close" "tcp_bind_error_inval"
50 "tcp_bind_error_addrinuse" "tcp_shutdown_after_write"
51 "tcp_open" "tcp_write_queue_order" "tcp_try_write" "tcp_writealot"
52 "multiple_listen" "delayed_accept"
53 "shutdown_close_tcp" "shutdown_eof" "shutdown_twice" "callback_stack"
54 "tty_pty" "condvar_5" "hrtime" "udp_multicast_join"
55 # Tests that fail when sandboxing is enabled.
56 "fs_event_close_in_callback" "fs_event_watch_dir" "fs_event_error_reporting"
57 "fs_event_watch_dir_recursive" "fs_event_watch_file"
58 "fs_event_watch_file_current_dir" "fs_event_watch_file_exact_path"
59 "process_priority" "udp_create_early_bad_bind"
60 ] ++ lib.optionals stdenv.isAarch32 [
61 # I observe this test failing with some regularity on ARMv7:
62 # https://github.com/libuv/libuv/issues/1871
63 "shutdown_close_pipe"
64 ];
65 tdRegexp = lib.concatStringsSep "\\|" toDisable;
66 in lib.optionalString doCheck ''
67 sed '/${tdRegexp}/d' -i test/test-list.h
68 '';
69
70 nativeBuildInputs = [ automake autoconf libtool pkg-config ];
71 buildInputs = lib.optionals stdenv.isDarwin [ ApplicationServices CoreServices ];
72
73 preConfigure = ''
74 LIBTOOLIZE=libtoolize ./autogen.sh
75 '';
76
77 enableParallelBuilding = true;
78
79 # separateDebugInfo breaks static build
80 # https://github.com/NixOS/nixpkgs/issues/219466
81 separateDebugInfo = !stdenv.hostPlatform.isStatic;
82
83 doCheck = true;
84
85 # Some of the tests use localhost networking.
86 __darwinAllowLocalNetworking = true;
87
88 passthru.tests.static = pkgsStatic.libuv;
89
90 meta = with lib; {
91 description = "A multi-platform support library with a focus on asynchronous I/O";
92 homepage = "https://libuv.org/";
93 changelog = "https://github.com/libuv/libuv/blob/v${version}/ChangeLog";
94 maintainers = with maintainers; [ cstrahan ];
95 platforms = platforms.all;
96 license = with licenses; [ mit isc bsd2 bsd3 cc-by-40 ];
97 };
98
99}