python313Packages.traits: fix build (#373698)
[NixPkgs.git] / pkgs / tools / security / tor / torsocks.nix
blob5092a1e42af9298ec9a4247dae55019ce6b6572e
2   lib,
3   stdenv,
4   fetchFromGitLab,
5   fetchpatch,
6   autoreconfHook,
7   libcap,
8 }:
10 stdenv.mkDerivation rec {
11   pname = "torsocks";
12   version = "2.4.0";
14   src = fetchFromGitLab {
15     domain = "gitlab.torproject.org";
16     group = "tpo";
17     owner = "core";
18     repo = "torsocks";
19     rev = "v${version}";
20     sha256 = "sha256-ocJkoF9LMLC84ukFrm5pzjp/1gaXqDz8lzr9TdG+f88=";
21   };
23   patches = [
24     # fix compatibility with C99
25     # https://gitlab.torproject.org/tpo/core/torsocks/-/merge_requests/9
26     (fetchpatch {
27       url = "https://gitlab.torproject.org/tpo/core/torsocks/-/commit/1171bf2fd4e7a0cab02cf5fca59090b65af9cd29.patch";
28       hash = "sha256-qu5/0fy72+02QI0cVE/6YrR1kPuJxsZfG8XeODqVOPY=";
29     })
30     # tsocks_libc_accept4 only exists on Linux, use tsocks_libc_accept on other platforms
31     (fetchpatch {
32       url = "https://gitlab.torproject.org/tpo/core/torsocks/uploads/eeec9833512850306a42a0890d283d77/0001-Fix-macros-for-accept4-2.patch";
33       hash = "sha256-XWi8+UFB8XgBFSl5QDJ+hLu/dH4CvAwYbeZz7KB10Bs=";
34     })
35     # no gethostbyaddr_r on darwin
36     ./torsocks-gethostbyaddr-darwin.patch
37   ];
39   postPatch =
40     ''
41       # Patch torify_app()
42       sed -i \
43         -e 's,\(local app_path\)=`which $1`,\1=`type -P $1`,' \
44         src/bin/torsocks.in
45     ''
46     + lib.optionalString stdenv.hostPlatform.isLinux ''
47       sed -i \
48         -e 's,\(local getcap\)=.*,\1=${libcap}/bin/getcap,' \
49         src/bin/torsocks.in
50     '';
52   nativeBuildInputs = [ autoreconfHook ];
54   doInstallCheck = true;
55   installCheckTarget = "check-recursive";
57   meta = {
58     description = "Wrapper to safely torify applications";
59     mainProgram = "torsocks";
60     homepage = "https://gitlab.torproject.org/tpo/core/torsocks";
61     license = lib.licenses.gpl2Plus;
62     platforms = lib.platforms.unix;
63     maintainers = with lib.maintainers; [ thoughtpolice ];
64   };