2023-07-02 17:57:43 +00:00
{ stdenv
, lib
, fetchFromGitHub
, cmake
, pkg-config
, python3
, openssl
, curl
, libevent
, inotify-tools
, systemd
, zlib
, pcre
, libb64
, libutp
, libdeflate
2023-07-02 18:12:10 +00:00
, utf8cpp
, fmt
, libpsl
2023-07-02 17:57:43 +00:00
, miniupnpc
, dht
, libnatpmp
, libiconv
2023-10-05 08:46:46 +00:00
, Foundation
2023-07-02 17:57:43 +00:00
# Build options
, enableGTK3 ? false
, gtkmm3
, xorg
, wrapGAppsHook
, enableQt ? false
, qt5
, nixosTests
, enableSystemd ? lib . meta . availableOn stdenv . hostPlatform systemd
, enableDaemon ? true
, enableCli ? true
, installLib ? false
, apparmorRulesFromClosure
} :
2023-10-05 08:44:04 +00:00
stdenv . mkDerivation ( finalAttrs : {
2023-07-02 17:57:43 +00:00
pname = " t r a n s m i s s i o n " ;
2023-08-31 01:06:16 +00:00
version = " 4 . 0 . 4 " ;
2023-07-02 17:57:43 +00:00
src = fetchFromGitHub {
owner = " t r a n s m i s s i o n " ;
repo = " t r a n s m i s s i o n " ;
2023-10-05 08:44:04 +00:00
rev = finalAttrs . version ;
2023-08-31 01:06:16 +00:00
hash = " s h a 2 5 6 - S z 3 + 5 V v f O g E T 1 a i o r m E n B O r F + y N 7 9 t i S Q v j L A o G q T L w = " ;
2023-07-02 17:57:43 +00:00
fetchSubmodules = true ;
} ;
outputs = [ " o u t " " a p p a r m o r " ] ;
cmakeFlags =
let
mkFlag = opt : if opt then " O N " else " O F F " ;
in
[
" - D E N A B L E _ M A C = O F F " # requires xcodebuild
" - D E N A B L E _ G T K = ${ mkFlag enableGTK3 } "
" - D E N A B L E _ Q T = ${ mkFlag enableQt } "
" - D E N A B L E _ D A E M O N = ${ mkFlag enableDaemon } "
" - D E N A B L E _ C L I = ${ mkFlag enableCli } "
" - D I N S T A L L _ L I B = ${ mkFlag installLib } "
] ++ lib . optionals stdenv . isDarwin [
# Transmission sets this to 10.13 if not explicitly specified, see https://github.com/transmission/transmission/blob/0be7091eb12f4eb55f6690f313ef70a66795ee72/CMakeLists.txt#L7-L16.
" - D C M A K E _ O S X _ D E P L O Y M E N T _ T A R G E T = ${ stdenv . hostPlatform . darwinMinVersion } "
] ;
2023-07-02 18:12:10 +00:00
postPatch = ''
# Clean third-party libraries to ensure system ones are used.
# Excluding gtest since it is hardcoded to vendored version. The rest of the listed libraries are not packaged.
pushd third-party
for f in * ; do
if [ [ ! $ f = ~ googletest | wildmat | fast_float | wide-integer | jsonsl ] ] ; then
rm - r " $ f "
fi
done
popd
rm \
cmake/FindFmt.cmake \
cmake/FindUtfCpp.cmake
# Upstream uses different config file name.
substituteInPlace CMakeLists . txt - - replace ' find_package ( UtfCpp ) ' ' find_package ( utf8cpp ) '
'' ;
2023-07-02 17:57:43 +00:00
nativeBuildInputs = [
pkg-config
cmake
python3
]
++ lib . optionals enableGTK3 [ wrapGAppsHook ]
++ lib . optionals enableQt [ qt5 . wrapQtAppsHook ]
;
buildInputs = [
curl
2023-07-02 18:12:10 +00:00
dht
fmt
2023-07-02 17:57:43 +00:00
libb64
libdeflate
2023-07-02 18:12:10 +00:00
libevent
2023-07-02 17:57:43 +00:00
libnatpmp
2023-07-02 18:12:10 +00:00
libpsl
libutp
miniupnpc
openssl
pcre
utf8cpp
zlib
2023-07-02 17:57:43 +00:00
]
++ lib . optionals enableQt [ qt5 . qttools qt5 . qtbase ]
++ lib . optionals enableGTK3 [ gtkmm3 xorg . libpthreadstubs ]
++ lib . optionals enableSystemd [ systemd ]
++ lib . optionals stdenv . isLinux [ inotify-tools ]
2023-10-05 08:46:46 +00:00
++ lib . optionals stdenv . isDarwin [ libiconv Foundation ] ;
2023-07-02 17:57:43 +00:00
postInstall = ''
mkdir $ apparmor
cat > $ apparmor/bin.transmission-daemon < < EOF
include <tunables/global>
$ out/bin/transmission-daemon {
include <abstractions/base>
include <abstractions/nameservice>
include <abstractions/ssl_certs>
include " ${ apparmorRulesFromClosure { name = " t r a n s m i s s i o n - d a e m o n " ; } ( [
2023-07-02 18:12:10 +00:00
curl libevent openssl pcre zlib libdeflate libpsl libnatpmp miniupnpc
2023-07-02 17:57:43 +00:00
] ++ lib . optionals enableSystemd [ systemd ]
++ lib . optionals stdenv . isLinux [ inotify-tools ]
) } "
r @ { PROC } /sys/kernel/random/uuid ,
r @ { PROC } /sys/vm/overcommit_memory ,
r @ { PROC } / @ { pid } /environ ,
r @ { PROC } / @ { pid } /mounts ,
rwk /tmp/tr_session_id_ * ,
r $ out/share/transmission/web /* * ,
include <local/bin.transmission-daemon>
}
EOF
'' ;
2023-09-23 10:56:23 +00:00
passthru . tests = {
2023-09-23 11:27:17 +00:00
apparmor = nixosTests . transmission_4 ; # starts the service with apparmor enabled
2023-09-23 10:56:23 +00:00
smoke-test = nixosTests . bittorrent ;
} ;
2023-07-02 17:57:43 +00:00
meta = {
description = " A f a s t , e a s y a n d f r e e B i t T o r r e n t c l i e n t " ;
2023-09-23 10:54:30 +00:00
mainProgram = if enableQt then " t r a n s m i s s i o n - q t " else if enableGTK3 then " t r a n s m i s s i o n - g t k " else " t r a n s m i s s i o n - c l i " ;
2023-07-02 17:57:43 +00:00
longDescription = ''
Transmission is a BitTorrent client which features a simple interface
on top of a cross-platform back-end .
Feature spotlight :
* Uses fewer resources than other clients
* Native Mac , GTK and Qt GUI clients
* Daemon ideal for servers , embedded systems , and headless use
* All these can be remote controlled by Web and Terminal clients
* Bluetack ( PeerGuardian ) blocklists with automatic updates
* Full encryption , DHT , and PEX support
'' ;
homepage = " h t t p : / / w w w . t r a n s m i s s i o n b t . c o m / " ;
license = with lib . licenses ; [ gpl2Plus mit ] ;
maintainers = with lib . maintainers ; [ astsmtl ] ;
platforms = lib . platforms . unix ;
} ;
2023-10-05 08:44:04 +00:00
} )