From d25e92102d1e8d6dbd8b5d34f749650331df87f4 Mon Sep 17 00:00:00 2001 From: Louis Bettens Date: Sat, 14 Nov 2020 22:43:49 +0100 Subject: [PATCH 1/3] onionshare: 2.2 -> 2.3 --- .../networking/onionshare/default.nix | 106 +++++++------ .../networking/onionshare/fix-paths-gui.patch | 37 +++++ .../networking/onionshare/fix-paths.patch | 144 +++--------------- 3 files changed, 123 insertions(+), 164 deletions(-) create mode 100644 pkgs/applications/networking/onionshare/fix-paths-gui.patch diff --git a/pkgs/applications/networking/onionshare/default.nix b/pkgs/applications/networking/onionshare/default.nix index 77d08692f625..f33259fafeeb 100644 --- a/pkgs/applications/networking/onionshare/default.nix +++ b/pkgs/applications/networking/onionshare/default.nix @@ -1,30 +1,33 @@ { lib, buildPythonApplication, - stdenv, substituteAll, fetchFromGitHub, isPy3k, flask, flask-httpauth, + flask-socketio, stem, + psutil, pyqt5, pycrypto, - pysocks, - pytest, + pyside2, + pytestCheckHook, + qrcode, qt5, requests, + unidecode, tor, obfs4, }: let - version = "2.2"; + version = "2.3"; src = fetchFromGitHub { owner = "micahflee"; repo = "onionshare"; rev = "v${version}"; - sha256 = "0m8ygxcyp3nfzzhxs2dfnpqwh1vx0aws44lszpnnczz4fks3a5j4"; + sha256 = "sha256-CyL9J3ADxs1QAVaWz9HepwSwgZ98Z5uO2fdplOvnU1E="; }; meta = with lib; { description = "Securely and anonymously send and receive files"; @@ -51,63 +54,76 @@ let maintainers = with maintainers; [ lourkeur ]; }; - common = buildPythonApplication { - pname = "onionshare-common"; - inherit version meta src; - - disable = !isPy3k; - propagatedBuildInputs = [ - flask - flask-httpauth - stem - pyqt5 - pycrypto - pysocks - requests - ]; - buildInputs = [ - tor - obfs4 - ]; - +in rec { + onionshare = buildPythonApplication { + pname = "onionshare"; + inherit version meta; + src = "${src}/cli"; patches = [ + # hardcode store paths of dependencies (substituteAll { src = ./fix-paths.patch; inherit tor obfs4; inherit (tor) geoip; }) ]; - postPatch = "substituteInPlace onionshare/common.py --subst-var-by common $out"; + disable = !isPy3k; + propagatedBuildInputs = [ + flask + flask-httpauth + flask-socketio + stem + psutil + pycrypto + requests + unidecode + ]; - doCheck = false; - }; -in -{ - onionshare = stdenv.mkDerivation { - pname = "onionshare"; - inherit version meta; + buildInputs = [ + tor + obfs4 + ]; - dontUnpack = true; + checkInputs = [ + pytestCheckHook + ]; - inherit common; - installPhase = '' - mkdir -p $out/bin - cp $common/bin/onionshare -t $out/bin + preCheck = '' + # Tests use the home directory + export HOME="$(mktemp -d)" ''; }; - onionshare-gui = stdenv.mkDerivation { + + onionshare-gui = buildPythonApplication { pname = "onionshare-gui"; inherit version meta; + src = "${src}/desktop/src"; + patches = [ + # hardcode store paths of dependencies + (substituteAll { + src = ./fix-paths-gui.patch; + inherit tor obfs4; + inherit (tor) geoip; + }) + ]; + + disable = !isPy3k; + propagatedBuildInputs = [ + onionshare + pyqt5 + pyside2 + psutil + qrcode + ]; nativeBuildInputs = [ qt5.wrapQtAppsHook ]; - dontUnpack = true; - - inherit common; - installPhase = '' - mkdir -p $out/bin - cp $common/bin/onionshare-gui -t $out/bin - wrapQtApp $out/bin/onionshare-gui + preFixup = '' + wrapQtApp $out/bin/onionshare ''; + + doCheck = false; + + pythonImportsCheck = [ "onionshare" ]; }; } diff --git a/pkgs/applications/networking/onionshare/fix-paths-gui.patch b/pkgs/applications/networking/onionshare/fix-paths-gui.patch new file mode 100644 index 000000000000..cdc2e3d47dd8 --- /dev/null +++ b/pkgs/applications/networking/onionshare/fix-paths-gui.patch @@ -0,0 +1,37 @@ + +--- a/onionshare/gui_common.py ++++ b/onionshare/gui_common.py +@@ -376,29 +376,10 @@ class GuiCommon: + } + + def get_tor_paths(self): +- if self.common.platform == "Linux": +- tor_path = shutil.which("tor") +- obfs4proxy_file_path = shutil.which("obfs4proxy") +- prefix = os.path.dirname(os.path.dirname(tor_path)) +- tor_geo_ip_file_path = os.path.join(prefix, "share/tor/geoip") +- tor_geo_ipv6_file_path = os.path.join(prefix, "share/tor/geoip6") +- elif self.common.platform == "Windows": +- base_path = self.get_resource_path("tor") +- tor_path = os.path.join(base_path, "Tor", "tor.exe") +- obfs4proxy_file_path = os.path.join(base_path, "Tor", "obfs4proxy.exe") +- tor_geo_ip_file_path = os.path.join(base_path, "Data", "Tor", "geoip") +- tor_geo_ipv6_file_path = os.path.join(base_path, "Data", "Tor", "geoip6") +- elif self.common.platform == "Darwin": +- base_path = self.get_resource_path("tor") +- tor_path = os.path.join(base_path, "tor") +- obfs4proxy_file_path = os.path.join(base_path, "obfs4proxy.exe") +- tor_geo_ip_file_path = os.path.join(base_path, "geoip") +- tor_geo_ipv6_file_path = os.path.join(base_path, "geoip6") +- elif self.common.platform == "BSD": +- tor_path = "/usr/local/bin/tor" +- tor_geo_ip_file_path = "/usr/local/share/tor/geoip" +- tor_geo_ipv6_file_path = "/usr/local/share/tor/geoip6" +- obfs4proxy_file_path = "/usr/local/bin/obfs4proxy" ++ tor_path = "@tor@/bin/tor" ++ tor_geo_ip_file_path = "@geoip@/share/tor/geoip" ++ tor_geo_ipv6_file_path = "@geoip@/share/tor/geoip6" ++ obfs4proxy_file_path = "@obfs4@/bin/obfs4proxy" + + return ( + tor_path, diff --git a/pkgs/applications/networking/onionshare/fix-paths.patch b/pkgs/applications/networking/onionshare/fix-paths.patch index ddd0c75334bb..a290dd884104 100644 --- a/pkgs/applications/networking/onionshare/fix-paths.patch +++ b/pkgs/applications/networking/onionshare/fix-paths.patch @@ -1,68 +1,31 @@ -diff --git a/onionshare/common.py b/onionshare/common.py -index 3373462..7fd245b 100644 ---- a/onionshare/common.py -+++ b/onionshare/common.py -@@ -87,66 +87,16 @@ class Common(object): - ), - "share", - ) -- if not os.path.exists(prefix): -- # While running tests during stdeb bdist_deb, look 3 directories up for the share folder -- prefix = os.path.join( -- os.path.dirname( -- os.path.dirname(os.path.dirname(os.path.dirname(prefix))) -- ), -- "share", -- ) -- -- elif self.platform == "BSD" or self.platform == "Linux": -- # Assume OnionShare is installed systemwide in Linux, since we're not running in dev mode -- prefix = os.path.join(sys.prefix, "share/onionshare") -- -- elif getattr(sys, "frozen", False): -- # Check if app is "frozen" -- # https://pythonhosted.org/PyInstaller/#run-time-information -- if self.platform == "Darwin": -- prefix = os.path.join(sys._MEIPASS, "share") -- elif self.platform == "Windows": -- prefix = os.path.join(os.path.dirname(sys.executable), "share") -+ else: -+ prefix = "@common@/share/onionshare" - - return os.path.join(prefix, filename) - +--- a/onionshare_cli/common.py ++++ b/onionshare_cli/common.py +@@ -86,33 +86,10 @@ class Common: + return path + def get_tor_paths(self): - if self.platform == "Linux": -- tor_path = "/usr/bin/tor" -- tor_geo_ip_file_path = "/usr/share/tor/geoip" -- tor_geo_ipv6_file_path = "/usr/share/tor/geoip6" -- obfs4proxy_file_path = "/usr/bin/obfs4proxy" +- tor_path = shutil.which("tor") +- if not tor_path: +- raise CannotFindTor() +- obfs4proxy_file_path = shutil.which("obfs4proxy") +- prefix = os.path.dirname(os.path.dirname(tor_path)) +- tor_geo_ip_file_path = os.path.join(prefix, "share/tor/geoip") +- tor_geo_ipv6_file_path = os.path.join(prefix, "share/tor/geoip6") - elif self.platform == "Windows": -- base_path = os.path.join( -- os.path.dirname(os.path.dirname(self.get_resource_path(""))), "tor" -- ) -- tor_path = os.path.join(os.path.join(base_path, "Tor"), "tor.exe") -- obfs4proxy_file_path = os.path.join( -- os.path.join(base_path, "Tor"), "obfs4proxy.exe" -- ) -- tor_geo_ip_file_path = os.path.join( -- os.path.join(os.path.join(base_path, "Data"), "Tor"), "geoip" -- ) -- tor_geo_ipv6_file_path = os.path.join( -- os.path.join(os.path.join(base_path, "Data"), "Tor"), "geoip6" -- ) +- base_path = self.get_resource_path("tor") +- tor_path = os.path.join(base_path, "Tor", "tor.exe") +- obfs4proxy_file_path = os.path.join(base_path, "Tor", "obfs4proxy.exe") +- tor_geo_ip_file_path = os.path.join(base_path, "Data", "Tor", "geoip") +- tor_geo_ipv6_file_path = os.path.join(base_path, "Data", "Tor", "geoip6") - elif self.platform == "Darwin": -- base_path = os.path.dirname( -- os.path.dirname(os.path.dirname(self.get_resource_path(""))) -- ) -- tor_path = os.path.join(base_path, "Resources", "Tor", "tor") -- tor_geo_ip_file_path = os.path.join(base_path, "Resources", "Tor", "geoip") -- tor_geo_ipv6_file_path = os.path.join( -- base_path, "Resources", "Tor", "geoip6" -- ) -- obfs4proxy_file_path = os.path.join( -- base_path, "Resources", "Tor", "obfs4proxy" -- ) +- tor_path = shutil.which("tor") +- if not tor_path: +- raise CannotFindTor() +- obfs4proxy_file_path = shutil.which("obfs4proxy") +- prefix = os.path.dirname(os.path.dirname(tor_path)) +- tor_geo_ip_file_path = os.path.join(prefix, "share/tor/geoip") +- tor_geo_ipv6_file_path = os.path.join(prefix, "share/tor/geoip6") - elif self.platform == "BSD": - tor_path = "/usr/local/bin/tor" - tor_geo_ip_file_path = "/usr/local/share/tor/geoip" @@ -72,63 +35,6 @@ index 3373462..7fd245b 100644 + tor_geo_ip_file_path = "@geoip@/share/tor/geoip" + tor_geo_ipv6_file_path = "@geoip@/share/tor/geoip6" + obfs4proxy_file_path = "@obfs4@/bin/obfs4proxy" - + return ( tor_path, -diff --git a/setup.py b/setup.py -index 9af72fc..53ca47b 100644 ---- a/setup.py -+++ b/setup.py -@@ -70,41 +70,41 @@ classifiers = [ - ] - data_files = [ - ( -- os.path.join(sys.prefix, "share/applications"), -+ "share/applications", - ["install/org.onionshare.OnionShare.desktop"], - ), - ( -- os.path.join(sys.prefix, "share/icons/hicolor/scalable/apps"), -+ "share/icons/hicolor/scalable/apps", - ["install/org.onionshare.OnionShare.svg"], - ), - ( -- os.path.join(sys.prefix, "share/metainfo"), -+ "share/metainfo", - ["install/org.onionshare.OnionShare.appdata.xml"], - ), -- (os.path.join(sys.prefix, "share/onionshare"), file_list("share")), -- (os.path.join(sys.prefix, "share/onionshare/images"), file_list("share/images")), -- (os.path.join(sys.prefix, "share/onionshare/locale"), file_list("share/locale")), -+ ( "share/onionshare", file_list("share")), -+ ( "share/onionshare/images", file_list("share/images")), -+ ( "share/onionshare/locale", file_list("share/locale")), - ( -- os.path.join(sys.prefix, "share/onionshare/templates"), -+ "share/onionshare/templates", - file_list("share/templates"), - ), - ( -- os.path.join(sys.prefix, "share/onionshare/static/css"), -+ "share/onionshare/static/css", - file_list("share/static/css"), - ), - ( -- os.path.join(sys.prefix, "share/onionshare/static/img"), -+ "share/onionshare/static/img", - file_list("share/static/img"), - ), - ( -- os.path.join(sys.prefix, "share/onionshare/static/js"), -+ "share/onionshare/static/js", - file_list("share/static/js"), - ), - ] - if not platform.system().endswith("BSD") and platform.system() != "DragonFly": - data_files.append( - ( -- "/usr/share/nautilus-python/extensions/", -+ "share/nautilus-python/extensions/", - ["install/scripts/onionshare-nautilus.py"], - ) - ) From 58e767c037be91c420a0370e2d7f33bed5719947 Mon Sep 17 00:00:00 2001 From: Louis Bettens Date: Mon, 28 Dec 2020 11:19:37 +0100 Subject: [PATCH 2/3] onionshare: allow using nix run --- pkgs/applications/networking/onionshare/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/networking/onionshare/default.nix b/pkgs/applications/networking/onionshare/default.nix index f33259fafeeb..a695ad7ecde8 100644 --- a/pkgs/applications/networking/onionshare/default.nix +++ b/pkgs/applications/networking/onionshare/default.nix @@ -56,7 +56,7 @@ let in rec { onionshare = buildPythonApplication { - pname = "onionshare"; + pname = "onionshare-cli"; inherit version meta; src = "${src}/cli"; patches = [ @@ -95,7 +95,7 @@ in rec { }; onionshare-gui = buildPythonApplication { - pname = "onionshare-gui"; + pname = "onionshare"; inherit version meta; src = "${src}/desktop/src"; patches = [ From 9fd6ee224a161afde7c0ae650ed543efc4e3e778 Mon Sep 17 00:00:00 2001 From: Louis Bettens Date: Tue, 23 Feb 2021 08:47:52 +0100 Subject: [PATCH 3/3] onionshare: 2.3 -> 2.3.1 --- pkgs/applications/networking/onionshare/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/networking/onionshare/default.nix b/pkgs/applications/networking/onionshare/default.nix index a695ad7ecde8..124ee9a20ead 100644 --- a/pkgs/applications/networking/onionshare/default.nix +++ b/pkgs/applications/networking/onionshare/default.nix @@ -22,12 +22,12 @@ }: let - version = "2.3"; + version = "2.3.1"; src = fetchFromGitHub { owner = "micahflee"; repo = "onionshare"; rev = "v${version}"; - sha256 = "sha256-CyL9J3ADxs1QAVaWz9HepwSwgZ98Z5uO2fdplOvnU1E="; + sha256 = "sha256-H09x3OF6l1HLHukGPvV2rZUjW9fxeKKMZkKbY9a2m9I="; }; meta = with lib; { description = "Securely and anonymously send and receive files";