about summary refs log tree commit diff
path: root/pkgs/applications/blockchains/bisq-desktop
diff options
context:
space:
mode:
authorEmmanuel Rosa <emmanuelrosa@protonmail.com>2021-07-17 11:27:31 +0700
committerEmmanuel Rosa <emmanuelrosa@protonmail.com>2021-08-11 02:26:33 +0700
commitc82be07e04db4fbe5599aaaefe0d541b58541b42 (patch)
tree7d5839ae043844978b2937d76d6e38fc7c770eda /pkgs/applications/blockchains/bisq-desktop
parent6cb0749fb13c9e9e45a5dfeb8a02d4073cecc1e5 (diff)
bisq-desktop: utilize the built-in Tor handling
Bisq comes with an embedded Tor binary (provided by a third party), but we don't use it in this package because it's build for a FHS-abiding Linux distro; Meaning, Tor won't execute because it tried to load libraries from standard locations.

To address this problem, the Nix package launches an ephemeral Tor instance for Bisq. The approach works, but it does mean having to manage the tor process, something which is already handled well by Bisq.

This change modifies the Bisq Jar archive such that it launches the Tor binary from Nixpkgs, allowing Bisq to manage Tor as it does on other Linux distros and operating systems.

In a nutshell, when Bisq is launched it extracts a copy of the tor binary from its Jar file and saves it in the Bisq data directory. It is then executed from there. Since Nix doesn't know that Bisq has a runtime dependency on Tor, this change modifies the launcher script to contain a reference to Tor, thus convincing Nix that Tor is a runtime dependency.
Diffstat (limited to 'pkgs/applications/blockchains/bisq-desktop')
-rw-r--r--pkgs/applications/blockchains/bisq-desktop/default.nix51
1 files changed, 24 insertions, 27 deletions
diff --git a/pkgs/applications/blockchains/bisq-desktop/default.nix b/pkgs/applications/blockchains/bisq-desktop/default.nix
index 700bedf17cec5..9c8f0363e58ac 100644
--- a/pkgs/applications/blockchains/bisq-desktop/default.nix
+++ b/pkgs/applications/blockchains/bisq-desktop/default.nix
@@ -8,42 +8,29 @@
 , openjdk11
 , dpkg
 , writeScript
-, coreutils
 , bash
 , tor
-, psmisc
+, gnutar
+, zip
+, xz
 }:
 
 let
   bisq-launcher = writeScript "bisq-launcher" ''
     #! ${bash}/bin/bash
 
-    # Setup a temporary Tor instance
-    TMPDIR=$(${coreutils}/bin/mktemp -d)
-    CONTROLPORT=$(${coreutils}/bin/shuf -i 9100-9499 -n 1)
-    SOCKSPORT=$(${coreutils}/bin/shuf -i 9500-9999 -n 1)
-    ${coreutils}/bin/head -c 1024 < /dev/urandom > $TMPDIR/cookie
+    # This is just a comment to convince Nix that Tor is a
+    # runtime dependency; The Tor binary is in a *.jar file,
+    # whereas Nix only scans for hashes in uncompressed text.
+    # ${bisq-tor}
 
-    ${tor}/bin/tor --SocksPort $SOCKSPORT --ControlPort $CONTROLPORT \
-      --ControlPortWriteToFile $TMPDIR/port --CookieAuthFile $TMPDIR/cookie \
-      --CookieAuthentication 1 >$TMPDIR/tor.log --RunAsDaemon 1
-
-    torpid=$(${psmisc}/bin/fuser $CONTROLPORT/tcp)
-
-    echo Temp directory: $TMPDIR
-    echo Tor PID: $torpid
-    echo Tor control port: $CONTROLPORT
-    echo Tor SOCKS port: $SOCKSPORT
-    echo Tor log: $TMPDIR/tor.log
-    echo Bisq log file: $TMPDIR/bisq.log
+    JAVA_TOOL_OPTIONS="-XX:MaxRAM=4g" bisq-desktop-wrapped "$@"
+  '';
 
-    JAVA_TOOL_OPTIONS="-XX:MaxRAM=4g" bisq-desktop-wrapped \
-      --torControlCookieFile=$TMPDIR/cookie \
-      --torControlUseSafeCookieAuth \
-      --torControlPort $CONTROLPORT "$@" > $TMPDIR/bisq.log
+  bisq-tor = writeScript "bisq-tor" ''
+    #! ${bash}/bin/bash
 
-    echo Bisq exited. Killing Tor...
-    kill $torpid
+    exec ${tor}/bin/tor "$@"
   '';
 in
 stdenv.mkDerivation rec {
@@ -55,7 +42,7 @@ stdenv.mkDerivation rec {
     sha256 = "0crry5k7crmrqn14wxiyrnhk09ac8a9ksqrwwky7jsnyah0bx5k4";
   };
 
-  nativeBuildInputs = [ makeWrapper copyDesktopItems dpkg ];
+  nativeBuildInputs = [ makeWrapper copyDesktopItems imagemagick dpkg gnutar zip xz ];
 
   desktopItems = [
     (makeDesktopItem {
@@ -72,6 +59,16 @@ stdenv.mkDerivation rec {
     dpkg -x $src .
   '';
 
+  buildPhase = ''
+    # Replace the embedded Tor binary (which is in a Tar archive)
+    # with one from Nixpkgs.
+
+    mkdir -p native/linux/x64/
+    cp ${bisq-tor} ./tor
+    tar -cJf native/linux/x64/tor.tar.xz tor
+    zip -r opt/bisq/lib/app/desktop-${version}-all.jar native
+  '';
+
   installPhase = ''
     runHook preInstall
 
@@ -86,7 +83,7 @@ stdenv.mkDerivation rec {
 
     for n in 16 24 32 48 64 96 128 256; do
       size=$n"x"$n
-      ${imagemagick}/bin/convert opt/bisq/lib/Bisq.png -resize $size bisq.png
+      convert opt/bisq/lib/Bisq.png -resize $size bisq.png
       install -Dm644 -t $out/share/icons/hicolor/$size/apps bisq.png
     done;