From a2585fff238949c45d1f4bb4be0ffddb641b4eac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20Min=C3=A1=C5=99?= <mic.liamg@gmail.com>
Date: Tue, 25 Jun 2019 04:23:47 +0200
Subject: [PATCH] reworked patches
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

lincense free -> unfree
enabled parallel build

Signed-off-by: Michal Minář <mic.liamg@gmail.com>
---
 pkgs/applications/misc/megasync/default.nix   | 22 +++++++++----------
 .../misc/megasync/install-megasync.patch      | 21 ++++++++++++++++++
 .../megasync/noinstall-distro-version.patch   | 13 +++++++++++
 3 files changed, 45 insertions(+), 11 deletions(-)
 create mode 100644 pkgs/applications/misc/megasync/install-megasync.patch
 create mode 100644 pkgs/applications/misc/megasync/noinstall-distro-version.patch

diff --git a/pkgs/applications/misc/megasync/default.nix b/pkgs/applications/misc/megasync/default.nix
index c8c49d7b5d71..b3e739864171 100644
--- a/pkgs/applications/misc/megasync/default.nix
+++ b/pkgs/applications/misc/megasync/default.nix
@@ -64,22 +64,22 @@ stdenv.mkDerivation rec {
     wget
   ];
 
-  patchPhase = ''
+  patches = [
+    # Distro and version targets attempt to use lsb_release which is broken
+    # (see issue: https://github.com/NixOS/nixpkgs/issues/22729)
+    ./noinstall-distro-version.patch
+    # megasync target is not part of the install rule thanks to a commented block
+    ./install-megasync.patch
+  ];
+
+  postPatch = ''
     for file in $(find src/ -type f \( -iname configure -o -iname \*.sh  \) ); do
       substituteInPlace "$file" --replace "/bin/bash" "${stdenv.shell}"
     done
-
-    # Distro and version targets attempt to use lsb_release which is broken
-    # (see issue: https://github.com/NixOS/nixpkgs/issues/22729)
-    substituteInPlace src/MEGASync/platform/platform.pri \
-      --replace "INSTALLS += distro" "# INSTALLS += distro"
-
-    # megasync target is not part of the install rule thanks to a commented block
-    sed -i '/#\s*isEmpty(PREFIX)/,/#\s*INSTALLS\s*+=\s*target/s/^\s*#//' \
-      src/MEGASync/MEGASync.pro
   '';
 
   dontUseQmakeConfigure = true;
+  enableParallelBuilding = true;
 
   preConfigure = ''
     cd src/MEGASync/mega
@@ -118,7 +118,7 @@ stdenv.mkDerivation rec {
   meta = with stdenv.lib; {
     description = "Easy automated syncing between your computers and your MEGA Cloud Drive";
     homepage    = https://mega.nz/;
-    license     = licenses.free;
+    license     = licenses.unfree;
     platforms   = [ "i686-linux" "x86_64-linux" ];
     maintainers = [ maintainers.michojel ];
   };
diff --git a/pkgs/applications/misc/megasync/install-megasync.patch b/pkgs/applications/misc/megasync/install-megasync.patch
new file mode 100644
index 000000000000..7d8748528e7f
--- /dev/null
+++ b/pkgs/applications/misc/megasync/install-megasync.patch
@@ -0,0 +1,21 @@
+Index: source/src/MEGASync/MEGASync.pro
+===================================================================
+--- source.orig/src/MEGASync/MEGASync.pro
++++ source/src/MEGASync/MEGASync.pro
+@@ -28,11 +28,11 @@ unix:!macx {
+     TARGET = megasync
+ 
+ #    Uncomment the following if "make install" doesn't copy megasync in /usr/bin directory
+-#    isEmpty(PREFIX) {
+-#        PREFIX = /usr
+-#    }
+-#    target.path = $$PREFIX/bin
+-#    INSTALLS += target
++    isEmpty(PREFIX) {
++        PREFIX = /usr
++    }
++    target.path = $$PREFIX/bin
++    INSTALLS += target
+ }
+ else {
+     TARGET = MEGAsync
diff --git a/pkgs/applications/misc/megasync/noinstall-distro-version.patch b/pkgs/applications/misc/megasync/noinstall-distro-version.patch
new file mode 100644
index 000000000000..bbf100737bc4
--- /dev/null
+++ b/pkgs/applications/misc/megasync/noinstall-distro-version.patch
@@ -0,0 +1,13 @@
+Index: source/src/MEGASync/platform/platform.pri
+===================================================================
+--- source.orig/src/MEGASync/platform/platform.pri
++++ source/src/MEGASync/platform/platform.pri
+@@ -37,7 +37,7 @@ unix:!macx {
+     system(command -v lsb_release): version.commands = lsb_release -rs > $$version.target
+ 	version.files = $$version.target
+ 
+-	INSTALLS += distro version
++	# INSTALLS += distro version
+ 
+     QT += dbus
+     SOURCES += $$PWD/linux/LinuxPlatform.cpp \