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