yek: init at 0.16.0 (#374979)
[NixPkgs.git] / pkgs / applications / networking / p2p / transmission / 4.nix
blob45dcb717f2b8ce7c83cc5168fab6be90118c0659
2   stdenv,
3   lib,
4   fetchFromGitHub,
5   fetchpatch2,
6   cmake,
7   pkg-config,
8   python3,
9   openssl,
10   curl,
11   libevent,
12   inotify-tools,
13   systemd,
14   zlib,
15   pcre,
16   libb64,
17   libutp,
18   libdeflate,
19   utf8cpp,
20   fmt,
21   libpsl,
22   miniupnpc,
23   dht,
24   libnatpmp,
25   libiconv,
26   Foundation,
27   # Build options
28   enableGTK3 ? false,
29   gtkmm3,
30   xorg,
31   wrapGAppsHook3,
32   enableQt5 ? false,
33   enableQt6 ? false,
34   qt5,
35   qt6Packages,
36   nixosTests,
37   enableSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd,
38   enableDaemon ? true,
39   enableCli ? true,
40   installLib ? false,
41   apparmorRulesFromClosure,
44 let
45   inherit (lib) cmakeBool optionals;
47   apparmorRules = apparmorRulesFromClosure { name = "transmission-daemon"; } (
48     [
49       curl
50       libdeflate
51       libevent
52       libnatpmp
53       libpsl
54       miniupnpc
55       openssl
56       pcre
57       zlib
58     ]
59     ++ optionals enableSystemd [ systemd ]
60     ++ optionals stdenv.hostPlatform.isLinux [ inotify-tools ]
61   );
64 stdenv.mkDerivation (finalAttrs: {
65   pname = "transmission";
66   version = "4.0.6";
68   src = fetchFromGitHub {
69     owner = "transmission";
70     repo = "transmission";
71     rev = finalAttrs.version;
72     hash = "sha256-KBXvBFgrJ3njIoXrxHbHHLsiocwfd7Eba/GNI8uZA38=";
73     fetchSubmodules = true;
74   };
76   patches = [
77     (fetchpatch2 {
78       url = "https://github.com/transmission/transmission/commit/febfe49ca3ecab1a7142ecb34012c1f0b2bcdee8.patch?full_index=1";
79       hash = "sha256-Ge0+AXf/ilfMieGBAdvvImY7JOb0gGIdeKprC37AROs=";
80       excludes = [
81         # The submodule that we don't use (we use our miniupnp)
82         "third-party/miniupnp"
83         # Hunk fails for this one, but we don't care because we don't rely upon
84         # xcode definitions even for the Darwin build.
85         "Transmission.xcodeproj/project.pbxproj"
86       ];
87     })
88   ];
90   outputs = [
91     "out"
92     "apparmor"
93   ];
95   cmakeFlags =
96     [
97       (cmakeBool "ENABLE_CLI" enableCli)
98       (cmakeBool "ENABLE_DAEMON" enableDaemon)
99       (cmakeBool "ENABLE_GTK" enableGTK3)
100       (cmakeBool "ENABLE_MAC" false) # requires xcodebuild
101       (cmakeBool "ENABLE_QT" (enableQt5 || enableQt6))
102       (cmakeBool "INSTALL_LIB" installLib)
103     ]
104     ++ optionals stdenv.hostPlatform.isDarwin [
105       # Transmission sets this to 10.13 if not explicitly specified, see https://github.com/transmission/transmission/blob/0be7091eb12f4eb55f6690f313ef70a66795ee72/CMakeLists.txt#L7-L16.
106       "-DCMAKE_OSX_DEPLOYMENT_TARGET=${stdenv.hostPlatform.darwinMinVersion}"
107     ];
109   postPatch = ''
110     # Clean third-party libraries to ensure system ones are used.
111     # Excluding gtest since it is hardcoded to vendored version. The rest of the listed libraries are not packaged.
112     pushd third-party
113     for f in *; do
114         if [[ ! $f =~ googletest|wildmat|fast_float|wide-integer|jsonsl ]]; then
115             rm -r "$f"
116         fi
117     done
118     popd
119     rm \
120       cmake/FindFmt.cmake \
121       cmake/FindUtfCpp.cmake
122     # Upstream uses different config file name.
123     substituteInPlace CMakeLists.txt --replace 'find_package(UtfCpp)' 'find_package(utf8cpp)'
125     # Use gettext even on Darwin
126     substituteInPlace libtransmission/utils.h \
127       --replace-fail '#if defined(HAVE_GETTEXT) && !defined(__APPLE__)' '#if defined(HAVE_GETTEXT)'
128   '';
130   nativeBuildInputs =
131     [
132       pkg-config
133       cmake
134       python3
135     ]
136     ++ optionals enableGTK3 [ wrapGAppsHook3 ]
137     ++ optionals enableQt5 [ qt5.wrapQtAppsHook ]
138     ++ optionals enableQt6 [ qt6Packages.wrapQtAppsHook ];
140   buildInputs =
141     [
142       curl
143       dht
144       fmt
145       libb64
146       libdeflate
147       libevent
148       libnatpmp
149       libpsl
150       libutp
151       miniupnpc
152       openssl
153       pcre
154       utf8cpp
155       zlib
156     ]
157     ++ optionals enableQt5 (
158       with qt5;
159       [
160         qttools
161         qtbase
162       ]
163     )
164     ++ optionals enableQt6 (
165       with qt6Packages;
166       [
167         qttools
168         qtbase
169         qtsvg
170       ]
171     )
172     ++ optionals enableGTK3 [
173       gtkmm3
174       xorg.libpthreadstubs
175     ]
176     ++ optionals enableSystemd [ systemd ]
177     ++ optionals stdenv.hostPlatform.isLinux [ inotify-tools ];
179   postInstall = ''
180     mkdir $apparmor
181     cat >$apparmor/bin.transmission-daemon <<EOF
182     include <tunables/global>
183     $out/bin/transmission-daemon {
184       include <abstractions/base>
185       include <abstractions/nameservice>
186       include <abstractions/ssl_certs>
187       include "${apparmorRules}"
188       r @{PROC}/sys/kernel/random/uuid,
189       r @{PROC}/sys/vm/overcommit_memory,
190       r @{PROC}/@{pid}/environ,
191       r @{PROC}/@{pid}/mounts,
192       rwk /tmp/tr_session_id_*,
194       r $out/share/transmission/public_html/**,
196       include <local/bin.transmission-daemon>
197     }
198     EOF
199     install -Dm0444 -t $out/share/icons ../qt/icons/transmission.svg
200   '';
202   passthru.tests = {
203     apparmor = nixosTests.transmission_4; # starts the service with apparmor enabled
204     smoke-test = nixosTests.bittorrent;
205   };
207   meta = with lib; {
208     description = "Fast, easy and free BitTorrent client";
209     mainProgram =
210       if (enableQt5 || enableQt6) then
211         "transmission-qt"
212       else if enableGTK3 then
213         "transmission-gtk"
214       else
215         "transmission-cli";
216     longDescription = ''
217       Transmission is a BitTorrent client which features a simple interface
218       on top of a cross-platform back-end.
219       Feature spotlight:
220         * Uses fewer resources than other clients
221         * Native Mac, GTK and Qt GUI clients
222         * Daemon ideal for servers, embedded systems, and headless use
223         * All these can be remote controlled by Web and Terminal clients
224         * Bluetack (PeerGuardian) blocklists with automatic updates
225         * Full encryption, DHT, and PEX support
226     '';
227     homepage = "https://www.transmissionbt.com/";
228     license = with licenses; [
229       gpl2Plus
230       mit
231     ];
232     maintainers = with maintainers; [ astsmtl ];
233     platforms = platforms.unix;
234   };