From 1edfaa4a0d23be205588a05979a11e7c9af10a11 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Milan=20P=C3=A4ssler?= <mil@nyantec.com>
Date: Sat, 19 Dec 2020 17:15:22 +0100
Subject: [PATCH] libtorrentRasterbar-2_0_x: init at 2.0.1

---
 .../libtorrent-rasterbar/2.0/default.nix      | 47 +++++++++++++++++++
 pkgs/top-level/all-packages.nix               |  9 +++-
 pkgs/top-level/python-packages.nix            |  5 +-
 3 files changed, 58 insertions(+), 3 deletions(-)
 create mode 100644 pkgs/development/libraries/libtorrent-rasterbar/2.0/default.nix

diff --git a/pkgs/development/libraries/libtorrent-rasterbar/2.0/default.nix b/pkgs/development/libraries/libtorrent-rasterbar/2.0/default.nix
new file mode 100644
index 000000000000..e9c59ed97e82
--- /dev/null
+++ b/pkgs/development/libraries/libtorrent-rasterbar/2.0/default.nix
@@ -0,0 +1,47 @@
+{ stdenv, fetchFromGitHub, cmake
+, zlib, boost, openssl, python, ncurses, SystemConfiguration
+}:
+
+let
+  version = "2.0.1";
+
+  # Make sure we override python, so the correct version is chosen
+  boostPython = boost.override { enablePython = true; inherit python; };
+
+in stdenv.mkDerivation {
+  pname = "libtorrent-rasterbar";
+  inherit version;
+
+  src = fetchFromGitHub {
+    owner = "arvidn";
+    repo = "libtorrent";
+    rev = "v${version}";
+    sha256 = "04ppw901babkfkis89pyb8kiyn39kb21k1s838xjq5ghbral1b1c";
+    fetchSubmodules = true;
+  };
+
+  nativeBuildInputs = [ cmake ];
+
+  buildInputs = [ boostPython openssl zlib python ncurses ]
+    ++ stdenv.lib.optionals stdenv.isDarwin [ SystemConfiguration ];
+
+  postInstall = ''
+    moveToOutput "include" "$dev"
+    moveToOutput "lib/${python.libPrefix}" "$python"
+  '';
+
+  outputs = [ "out" "dev" "python" ];
+
+  cmakeFlags = [
+    "-Dpython-bindings=on"
+  ];
+
+  meta = with stdenv.lib; {
+    homepage = "https://libtorrent.org/";
+    description = "A C++ BitTorrent implementation focusing on efficiency and scalability";
+    license = licenses.bsd3;
+    maintainers = [ maintainers.phreedom ];
+    broken = stdenv.isDarwin;
+    platforms = platforms.unix;
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 4cdf4ec16500..d0ffd9d20d2e 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -3333,7 +3333,7 @@ in
 
   deluge-2_x = callPackage ../applications/networking/p2p/deluge/2 {
     pythonPackages = python3Packages;
-    libtorrentRasterbar = libtorrentRasterbar.override { python = python3; };
+    libtorrentRasterbar = libtorrentRasterbar-1_2_x.override { python = python3; };
   };
   deluge-1_x = callPackage ../applications/networking/p2p/deluge/1 {
     pythonPackages = python2Packages;
@@ -14674,13 +14674,18 @@ in
 
   libtomcrypt = callPackage ../development/libraries/libtomcrypt { };
 
+  libtorrentRasterbar-2_0_x = callPackage ../development/libraries/libtorrent-rasterbar/2.0 {
+    inherit (darwin.apple_sdk.frameworks) SystemConfiguration;
+    python = python3;
+  };
+
   libtorrentRasterbar-1_2_x = callPackage ../development/libraries/libtorrent-rasterbar/1.2 {
     inherit (darwin.apple_sdk.frameworks) SystemConfiguration;
   };
 
   libtorrentRasterbar-1_1_x = callPackage ../development/libraries/libtorrent-rasterbar/1.1 { };
 
-  libtorrentRasterbar = libtorrentRasterbar-1_2_x;
+  libtorrentRasterbar = libtorrentRasterbar-2_0_x;
 
   # this is still the new version of the old API
   libtoxcore-new = callPackage ../development/libraries/libtoxcore/new-api.nix { };
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index be2cca02f76a..33711b7d4ed7 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -3514,7 +3514,10 @@ in {
 
   libtmux = callPackage ../development/python-modules/libtmux { };
 
-  libtorrentRasterbar = (toPythonModule (pkgs.libtorrentRasterbar.override { inherit python; })).python;
+  libtorrentRasterbar = if isPy27 then
+    (toPythonModule (pkgs.libtorrentRasterbar-1_2_x.override { inherit python; })).python
+  else
+    (toPythonModule (pkgs.libtorrentRasterbar.override { inherit python; })).python;
 
   libusb1 = callPackage ../development/python-modules/libusb1 { inherit (pkgs) libusb1; };