;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès ;;; Copyright © 2014, 2015 Mark H Weaver ;;; Copyright © 2016, 2017, 2018, 2020 Efraim Flashner ;;; Copyright © 2016, 2017 Nikita ;;; Copyright © 2017, 2018, 2019, 2020 Tobias Geerinckx-Rice ;;; Copyright © 2017, 2018, 2019 Eric Bavier ;;; Copyright © 2017 Rutger Helling ;;; Copyright © 2018 Ricardo Wurmus ;;; Copyright © 2020 Vincent Legoll ;;; Copyright © 2020 Brice Waegeneire ;;; Copyright © 2020 André Batista ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu packages tor) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix gexp) #:use-module (guix monads) #:use-module (guix packages) #:use-module (guix utils) #:use-module (guix store) #:use-module (guix download) #:use-module (guix git-download) #:use-module (guix build-system cargo) #:use-module (guix build-system go) #:use-module (guix build-system gnu) #:use-module (guix build-system python) #:use-module (guix build-system trivial) #:use-module (gnu packages) #:use-module (gnu packages admin) #:use-module (gnu packages assembly) #:use-module (gnu packages audio) #:use-module (gnu packages autotools) #:use-module (gnu packages base) #:use-module (gnu packages bash) #:use-module (gnu packages check) #:use-module (gnu packages compression) #:use-module (gnu packages cups) #:use-module (gnu packages databases) #:use-module (gnu packages fontutils) #:use-module (gnu packages gl) #:use-module (gnu packages glib) #:use-module (gnu packages gnome) #:use-module (gnu packages golang) #:use-module (gnu packages gtk) #:use-module (gnu packages icu4c) #:use-module (gnu packages image) #:use-module (gnu packages kerberos) #:use-module (gnu packages libcanberra) #:use-module (gnu packages libevent) #:use-module (gnu packages libffi) #:use-module (gnu packages linux) #:use-module (gnu packages llvm) #:use-module (gnu packages node) #:use-module (gnu packages nss) #:use-module (gnu packages pcre) #:use-module (gnu packages perl) #:use-module (gnu packages pkg-config) #:use-module (gnu packages pulseaudio) #:use-module (gnu packages python) #:use-module (gnu packages python-crypto) #:use-module (gnu packages python-web) #:use-module (gnu packages python-xyz) #:use-module (gnu packages qt) #:use-module (gnu packages readline) #:use-module (gnu packages rsync) ; for httpse #:use-module (gnu packages rust) #:use-module (gnu packages rust-apps) #:use-module (gnu packages sqlite) #:use-module (gnu packages tls) #:use-module (gnu packages video) #:use-module (gnu packages vim) ; for xxd #:use-module (gnu packages w3m) #:use-module (gnu packages xdisorg) #:use-module (gnu packages xiph) #:use-module (gnu packages xorg) #:use-module (gnu packages xml) ; for httpse #:use-module (ice-9 match) #:use-module ((srfi srfi-1) #:hide (zip))) (define-public tor (package (name "tor") (version "0.4.3.6") (source (origin (method url-fetch) (uri (string-append "https://dist.torproject.org/tor-" version ".tar.gz")) (sha256 (base32 "0qmcrkjip0ywq77232m73pjwqiaj0q2klwklqlpbw575shvhcbba")))) (build-system gnu-build-system) (arguments `(#:configure-flags (list "--enable-lzma" "--enable-zstd"))) (native-inputs `(("pkg-config" ,pkg-config) ("python" ,python))) ; for tests (inputs `(("libevent" ,libevent) ("libseccomp" ,libseccomp) ("openssl" ,openssl) ("xz" ,xz) ("zlib" ,zlib) ("zstd" ,zstd "lib"))) (home-page "https://www.torproject.org/") (synopsis "Anonymous network router to improve privacy on the Internet") (description "Tor protects you by bouncing your communications around a distributed network of relays run by volunteers all around the world: it prevents somebody watching your Internet connection from learning what sites you visit, and it prevents the sites you visit from learning your physical location. Tor works with many of your existing applications, including web browsers, instant messaging clients, remote login, and other applications based on the TCP protocol. This package is the full featured @code{tor} which is needed for running relays, bridges or directory authorities. If you just want to access the Tor network or to setup an onion service you may install @code{tor-client} instead.") (license license:bsd-3))) (define-public tor-client (package (inherit tor) (name "tor-client") (arguments (substitute-keyword-arguments (package-arguments tor) ((#:configure-flags flags) (append flags '("--disable-module-relay"))))) (synopsis "Client to the anonymous Tor network") (description "Tor protects you by bouncing your communications around a distributed network of relays run by volunteers all around the world: it prevents somebody watching your Internet connection from learning what sites you visit, and it prevents the sites you visit from learning your physical location. Tor works with many of your existing applications, including web browsers, instant messaging clients, remote login, and other applications based on the TCP protocol. To @code{torify} applications (to take measures to ensure that an application, which has not been designed for use with Tor such as ssh, will use only Tor for internet connectivity, and also ensures that there are no leaks from DNS, UDP or the application layer) you need to install @code{torsocks}. This package only provides a client to the Tor Network."))) (define-public torsocks (package (name "torsocks") (version "2.3.0") (source (origin (method url-fetch) (uri (string-append "https://people.torproject.org/~dgoulet/" "torsocks/torsocks-" version ".tar.xz")) (sha256 (base32 "08inrkap29gikb6sdmb58z43hw4abwrfw7ny40c4xzdkss0vkwdr")))) (build-system gnu-build-system) (inputs `(("libcap" ,libcap))) (arguments `(#:phases (modify-phases %standard-phases (add-after 'build 'absolutize (lambda* (#:key inputs #:allow-other-keys) (substitute* "src/bin/torsocks" (("getcap=.*") (string-append "getcap=" (which "getcap") "\n"))) #t))))) (home-page "https://www.torproject.org/") (synopsis "Use socks-friendly applications with Tor") (description "Torsocks allows you to use most socks-friendly applications in a safe way with Tor. It ensures that DNS requests are handled safely and explicitly rejects UDP traffic from the application you're using.") ;; All the files explicitly say "version 2 only". (license license:gpl2))) (define-public privoxy (package (name "privoxy") (version "3.0.28") (source (origin (method url-fetch) (uri (string-append "mirror://sourceforge/ijbswa/Sources/" version "%20%28stable%29/privoxy-" version "-stable-src.tar.gz")) (sha256 (base32 "0jl2yav1qzqnaqnnx8i6i53ayckkimcrs3l6ryvv7bda6v08rmxm")))) (build-system gnu-build-system) (arguments '(;; The default 'sysconfdir' is $out/etc; change that to ;; $out/etc/privoxy. #:configure-flags (list (string-append "--sysconfdir=" (assoc-ref %outputs "out") "/etc/privoxy") "--localstatedir=/var") #:tests? #f ; no test suite #:phases (modify-phases %standard-phases (add-after 'unpack 'patch-default-logging (lambda _ (with-fluids ((%default-port-encoding "ISO-8859-1")) ;; Do not create /var/run nor /var/log/privoxy/logfile. (substitute* "GNUmakefile.in" (("(logfile \\|\\| exit )1" _ match) (string-append match "0")) (("(\\$\\(DESTDIR\\)\\$\\(SHARE_DEST\\)) \\\\" _ match) match) ((".*\\$\\(LOG_DEST\\) \\$\\(DESTDIR\\)\\$\\(PID_DEST\\).*") "")) ;; Disable logging in the default configuration to allow for ;; non-root users using it as is. (substitute* "config" (("^logdir") "#logdir") (("^logfile") "#logfile"))) #t))))) (inputs `(("w3m" ,w3m) ("pcre" ,pcre) ("zlib" ,zlib))) (native-inputs `(("autoconf" ,autoconf) ("automake" ,automake))) (home-page "https://www.privoxy.org") (synopsis "Web proxy with advanced filtering capabilities for enhancing privacy") (description "Privoxy is a non-caching web proxy with advanced filtering capabilities for enhancing privacy, modifying web page data and HTTP headers, controlling access, and removing ads and other obnoxious Internet junk. Privoxy has a flexible configuration and can be customized to suit individual needs and tastes. It has application for both stand-alone systems and multi-user networks.") (license license:gpl2+))) (define-public onionshare (package (name "onionshare") (version "2.2") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/micahflee/onionshare") (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 (base32 "0m8ygxcyp3nfzzhxs2dfnpqwh1vx0aws44lszpnnczz4fks3a5j4")))) (build-system python-build-system) (arguments `(#:phases (modify-phases %standard-phases (add-after 'unpack 'fix-install-path (lambda* (#:key outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (onionshare (string-append out "/share/onionshare"))) (substitute* '("setup.py" "onionshare/common.py") (("sys.prefix,") (string-append "'" out "',"))) (substitute* "setup.py" ;; For the nautilus plugin. (("/usr/share/nautilus") "share/nautilus")) (substitute* "install/org.onionshare.OnionShare.desktop" (("/usr") out)) #t))) (delete 'check) (add-before 'strip 'check ;; After all the patching we run the tests after installing. (lambda _ (setenv "HOME" "/tmp") ; Some tests need a writable homedir (invoke "pytest" "tests/") #t))))) (native-inputs `(("python-pytest" ,python-pytest))) (inputs `(("python-pycrypto" ,python-pycrypto) ("python-flask" ,python-flask) ("python-flask-httpauth" ,python-flask-httpauth) ("python-nautilus" ,python-nautilus) ("python-sip" ,python-sip) ("python-stem" ,python-stem) ("python-pysocks" ,python-pysocks) ("python-pyqt" ,python-pyqt))) (home-page "https://onionshare.org/") (synopsis "Securely and anonymously share files") (description "OnionShare is a tool for securely and anonymously sending and receiving files using Tor onion services. It works by starting a web server directly on your computer and making it accessible as an unguessable Tor web address that others can load in a Tor-enabled web browser to download files from you, or upload files to you. It doesn't require setting up a separate server, using a third party file-sharing service, or even logging into an account.") ;; Bundled, minified jquery is expat licensed. (license (list license:gpl3+ license:expat)))) (define-public nyx (package (name "nyx") (version "2.1.0") (source (origin (method url-fetch) (uri (pypi-uri name version)) (sha256 (base32 "02rrlllz2ci6i6cs3iddyfns7ang9a54jrlygd2jw1f9s6418ll8")))) (build-system python-build-system) (inputs `(("python-stem" ,python-stem))) (arguments `(#:phases (modify-phases %standard-phases (add-after 'install 'install-man-page (lambda* (#:key outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (man (string-append out "/share/man"))) (install-file "nyx.1" (string-append man "/man1")) #t))) (add-after 'install 'install-sample-configuration (lambda* (#:key outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (doc (string-append out "/share/doc/" ,name "-" ,version))) (install-file "web/nyxrc.sample" doc) #t)))) ;; XXX The tests seem to require more of a real terminal than the build ;; environment provides: ;; _curses.error: setupterm: could not find terminal ;; With TERM=linux, the tests try to move the cursor and still fail: ;; _curses.error: cbreak() returned ERR #:tests? #f)) (home-page "https://nyx.torproject.org/") (synopsis "Tor relay status monitor") (description "Nyx monitors the performance of relays participating in the @uref{https://www.torproject.org/, Tor anonymity network}. It displays this information visually and in real time, using a curses-based terminal interface. This makes Nyx well-suited for remote shell connections and servers without a graphical display. It's like @command{top} for Tor, providing detailed statistics and status reports on: @enumerate @item connections (with IP address, hostname, fingerprint, and consensus data), @item bandwidth, processor, and memory usage, @item the relay's current configuration, @item logged events, @item and much more. @end enumerate Potential client and exit connections are scrubbed of sensitive information.") (license license:gpl3+))) (define-public obfs4 (package (name "obfs4") (version "0.0.11") (source (origin (method git-fetch) (uri (git-reference (url "https://git.torproject.org/pluggable-transports/obfs4.git") (commit (string-append "obfs4proxy-" version)))) (file-name (git-file-name name version)) (sha256 (base32 "1y2kjwrk64l1h8b87m4iqsanib5rn68gzkdri1vd132qrlypycjn")))) (build-system go-build-system) (arguments '(#:import-path "git.torproject.org/pluggable-transports/obfs4.git" #:tests? #f ;; No test files #:phases (modify-phases %standard-phases (replace 'build (lambda* (#:key outputs configure-flags #:allow-other-keys) (let ((out (assoc-ref outputs "out"))) (copy-recursively "src/git.torproject.org/pluggable-transports/obfs4.git" "src/gitlab.com/yawning/obfs4.git" #:log (%make-void-port "w")) (with-directory-excursion "src/git.torproject.org/pluggable-transports/obfs4.git/obfs4proxy" (invoke "go" "build" "-ldflags" "-s")) #t))) (replace 'install (lambda* (#:key outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (srcdir "src/git.torproject.org/pluggable-transports/obfs4.git") (bindir (string-append out "/bin")) (sharedir (string-append out "/share/")) (docdir (string-append sharedir "/doc")) (mandir (string-append out "/man/man1"))) (mkdir-p mandir) (mkdir-p bindir) (mkdir-p docdir) (with-directory-excursion (string-append srcdir "/obfs4proxy") (copy-file "obfs4proxy" (string-append bindir "/obfs4proxy"))) (with-directory-excursion (string-append srcdir "/doc") (copy-file "obfs4proxy.1" (string-append mandir "/obfs4proxy.1")) (copy-file "obfs4-spec.txt" (string-append docdir "/obfs4-spec.txt"))) #t)))))) (propagated-inputs `(("go-torproject-org-ptlib" ,go-torproject-org-ptlib) ;; Currently uses this, but the readme on github is pointing ;; users to start relying on x/crypto/ed25519 instead. ("go-github-com-agl-ed25519" ,go-github-com-agl-ed25519) ("go-github-com-dchest-siphash" ,go-github-com-dchest-siphash) ("go-github-com-dchest-uniuri" ,go-github-com-dchest-uniuri) ("go-github-com-dsnet-compress" ,go-github-com-dsnet-compress) ("go-schwanenlied-me-yawning-bsaes" ,go-schwanenlied-me-yawning-bsaes) ("go-gitlab-com-yawning-utls" ,go-gitlab-com-yawning-utls) ("go-golang-org-x-net" ,go-golang-org-x-net) ("go-golang-org-x-crypto" ,go-golang-org-x-crypto) ("go-golang-org-x-text" ,go-golang-org-x-text))) (home-page "https://git.torproject.org/pluggable-transports/obfs4.git") (synopsis "Obfs4 implements an obfuscation protocol") (description "This is a look-like nothing obfuscation protocol that incorporates ideas and concepts from Philipp Winter's ScrambleSuit protocol. The obfs naming was chosen primarily because it was shorter, in terms of protocol ancestery obfs4 is much closer to ScrambleSuit than obfs2/obfs3.") (license license:gpl3+))) (define* (computed-origin-method gexp-promise hash-algo hash #:optional (name "source") #:key (system (%current-system)) (guile (default-guile))) "Return a derivation that executes the G-expression that results from forcing GEXP-PROMISE." (mlet %store-monad ((guile (package->derivation guile system))) (gexp->derivation (or name "computed-origin") (force gexp-promise) #:graft? #f ;nothing to graft #:system system #:guile-for-build guile))) ;; Fonts for TorBrowser. Avoid downloading 4Gb+ git repo on ;; https://github.com/googlei18n/noto-fonts.git to use just a handful. ;; Use the fonts on TorBrowser package. (define torbrowser-fonts (package (name "torbrowser-fonts") (version "9.5.1") (source (origin (method url-fetch) (uri (string-append "https://dist.torproject.org/torbrowser/" version "/tor-browser-linux64-" version "_en-US.tar.xz")) (sha256 (base32 "18xv8pv2j55f78n4d7cz24zwhqlcxkpq8nbanl754k2k0s1w34dd")))) (build-system trivial-build-system) (native-inputs `(("tar" ,tar) ("xz" ,xz))) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let ((src (assoc-ref %build-inputs "source")) (src-dir "tor-browser_en-US/Browser/fonts") (install-dir (string-append %output "/fonts")) (tar (assoc-ref %build-inputs "tar")) (xz (assoc-ref %build-inputs "xz"))) (mkdir-p install-dir) (format #t "Untaring torbrowser ball ...~%") (invoke (string-append tar "/bin/tar") "-xf" src "-C" install-dir "--strip-components=3" (string-append "--use-compress-program=" xz "/bin/xz") src-dir) #t)))) (home-page "https://github.com/googlei18n/noto-fonts") (synopsis "TorBrowser bundled fonts") (description "Free fonts bundled with TorBrowser. Includes a subset of Noto, Arimo, Cousine, Tinos and STIX fonts.") (license license:silofl1.1))) (define %torbrowser-version "68.10.0esr-9.5-1") (define %torbrowser-build-id "20200709000000") ;must be of the form YYYYMMDDhhmmss ;; (Un)fortunatly TorBrowser has it's own reproducible build system - RBM - which ;; automates the build process for them and compiles TorBrowser from a range of ;; repositories and produces a range of tarballs for different architectures and ;; locales. So we need to cherry-pick what is needed for guix and produce our own ;; tarball. See https://gitweb.torproject.org/builders/tor-browser-build.git/projects/\ ;; {tor-browser,firefox}/{build,config} for the rationale applied here. See also ;; the Hacking on TorBrowser document for a high level introduction at ;; https://trac.torproject.org/projects/tor/wiki/doc/TorBrowser/Hacking). ;; ;; TODO: Import langpacks. (define torbrowser-source (let* ((torbrowser-commit "75c2bb720d4ceb76231e8ecc3455754bf05ba19b") (torbrowser-version %torbrowser-version) (upstream-torbrowser-source (origin (method git-fetch) (uri (git-reference (url "https://git.torproject.org/tor-browser.git") (commit torbrowser-commit))) (file-name (git-file-name "tor-browser" torbrowser-version)) (sha256 (base32 "19sk46k2bqa72il46pdl534nk2g3fi6l7m7kbglddccxv19ck0k4")))) (torbrowser-build-commit "e94ba3a7677f7051a14b2304427ec8393a450fdc") (torbrowser-build-version "9.5") (upstream-torbrowser-build-source (origin (method git-fetch) (uri (git-reference (url "https://git.torproject.org/builders/tor-browser-build.git") (commit torbrowser-build-commit))) (file-name (git-file-name "tor-browser-build" torbrowser-build-version)) (sha256 (base32 "1jgkrsckcjgr1lgcwahzdrcasmpghs2ppz6w80fya89pa5d6r0gv")))) (torbutton-commit "ebe2bedab44e38f18c7968bd327d99eef7660f34") (torbutton-version "9.5") (upstream-torbutton-source (origin (method git-fetch) (uri (git-reference (url "https://git.torproject.org/torbutton.git") (commit torbutton-commit))) (file-name (git-file-name "torbutton" torbutton-version)) (sha256 (base32 "03xdyszab1a8j98xv6440v4lq58jkfqgmhxc2a62qz8q085d2x83")))) (tor-launcher-commit "b4838d339a84c5ebebd91a0ba6b22d44ecda97b1") (tor-launcher-version "0.2.21") (upstream-tor-launcher-source (origin (method git-fetch) (uri (git-reference (url "https://git.torproject.org/tor-launcher.git") (commit tor-launcher-commit))) (file-name (git-file-name "tor-launcher" tor-launcher-version)) (sha256 (base32 "0xxwyw1j6dkm2a24kg1564k701p5ikfzs1f9n0gflvlzz9427haf")))) (https-everywhere-version "2020.5.20") (upstream-https-everywhere-source (origin (method url-fetch) (uri (string-append "https://github.com/EFForg/https-everywhere/archive/" https-everywhere-version ".tar.gz")) (sha256 (base32 "027lga3z0a4d7s95id861das7g0k29p7pqh9xd77jm87f7w4l763")))) (noscript-xpi-version "11.0.34") (upstream-noscript-xpi (origin (method url-fetch) (uri (string-append "https://secure.informaction.com/download/releases/noscript-" noscript-xpi-version ".xpi")) (sha256 (base32 "0y45925ms2bk9d42zbgwcdb2sif8kqlbaflkz15q08gi7vgki6km"))))) ;; Now we bundle the grabbed sources. (origin (method computed-origin-method) (file-name (string-append "torbrowser-" %torbrowser-version ".tar.xz")) (sha256 #f) (uri (delay (with-imported-modules '((guix build utils)) #~(begin (use-modules (guix build utils)) (let ((torbrowser-dir (string-append "torbrowser-" #$torbrowser-version)) (torbutton-dir "toolkit/torproject/torbutton") (tor-launcher-dir "browser/extensions/tor-launcher") (tbb-scripts-dir "tbb-scripts") (https-everywhere "https-everywhere.tar.gz") (noscript-xpi "noscript.xpi")) (set-path-environment-variable "PATH" '("bin") (list #+(canonical-package bash) #+(canonical-package xz) #+(canonical-package tar))) (format #t "Copying torbrowser source to writable path ...~%") (force-output) (copy-recursively #+upstream-torbrowser-source torbrowser-dir #:log (%make-void-port "w")) (with-directory-excursion torbrowser-dir (format #t "Copying torbutton source to torbrowser...~%") (force-output) (make-file-writable torbutton-dir) (copy-recursively #+upstream-torbutton-source torbutton-dir #:log (%make-void-port "w")) (format #t "Copying tor-launcher source to torbrowser...~%") (force-output) (copy-recursively #+upstream-tor-launcher-source tor-launcher-dir #:log (%make-void-port "w")) (format #t "Copying tor-browser-build source to torbrowser...~%") (force-output) (mkdir tbb-scripts-dir) (copy-recursively #+upstream-torbrowser-build-source tbb-scripts-dir #:log (%make-void-port "w")) (format #t "Copying https-everywhere source to torbrowser...~%") (force-output) (copy-file #+upstream-https-everywhere-source https-everywhere) (format #t "Copying noscript xpi to torbrowser...~%") (force-output) (copy-file #+upstream-noscript-xpi "noscript.xpi")) (invoke "tar" "cvfa" #$output ;; Avoid non-determinism in the archive. "--mtime=@315619200" ; 1980-01-02 UTC "--owner=root:0" "--group=root:0" "--sort=name" torbrowser-dir) #t)))))))) (define-public torbrowser-unbundle (package (name "torbrowser-unbundle") (version %torbrowser-version) (source torbrowser-source) (build-system gnu-build-system) (inputs `(("alsa-lib" ,alsa-lib) ("bzip2" ,bzip2) ("cups" ,cups) ("dbus-glib" ,dbus-glib) ("ffmpeg" ,ffmpeg) ("freetype" ,freetype) ("gdk-pixbuf" ,gdk-pixbuf) ("glib" ,glib) ("gtk+" ,gtk+) ("gtk+-2" ,gtk+-2) ("graphite2" ,graphite2) ("harfbuzz" ,harfbuzz) ("icu4c" ,icu4c) ("libcanberra" ,libcanberra) ("libgnome" ,libgnome) ("libjpeg-turbo" ,libjpeg-turbo) ("libogg" ,libogg) ;; ("libtheora" ,libtheora) ; wants theora-1.2, not yet released ("libvorbis" ,libvorbis) ("libxft" ,libxft) ("libevent" ,libevent) ("libxinerama" ,libxinerama) ("libxscrnsaver" ,libxscrnsaver) ("libxcomposite" ,libxcomposite) ("libxt" ,libxt) ("libffi" ,libffi) ("libvpx" ,libvpx) ("mesa" ,mesa) ("mit-krb5" ,mit-krb5) ;; See ;; and related comments in the 'remove-bundled-libraries' phase. ;; UNBUNDLE-ME! ("nspr" ,nspr) ;; UNBUNDLE-ME! ("nss" ,nss) ("obfs4" ,obfs4) ("pango" ,pango) ("pixman" ,pixman) ("pulseaudio" ,pulseaudio) ("shared-mime-info" ,shared-mime-info) ("sqlite" ,sqlite) ("startup-notification" ,startup-notification) ("tor" ,tor-client) ("unzip" ,unzip) ("zip" ,zip) ("zlib" ,zlib))) (native-inputs `(("autoconf" ,autoconf-2.13) ("cargo" ,rust "cargo") ("clang" ,clang) ("libxml2" ,libxml2) ; for https-e ("libxslt" ,libxslt) ; for https-e ("llvm" ,llvm) ("openssl" ,openssl) ; For hash+sig on https-everywhere ("patch" ,(canonical-package patch)) ("torbrowser-start-tor-browser.patch" ,(search-patch "torbrowser-start-tor-browser.patch")) ("torbrowser-start-tor-browser.desktop.patch" ,(search-patch "torbrowser-start-tor-browser.desktop.patch")) ("perl" ,perl) ("pkg-config" ,pkg-config) ("python" ,python) ("python2" ,python-2.7) ("python2-pysqlite" ,python2-pysqlite) ("nasm" ,nasm) ; XXX FIXME: only needed on x86_64 and i686 ("node" ,node) ("rsync" ,rsync) ; for https-e build ("rust" ,rust) ("rust-cbindgen" ,rust-cbindgen) ("tar" ,tar) ; for untaring extensions ("torbrowser-fonts" ,torbrowser-fonts) ("util-linux" ,util-linux) ; for getopt on https-everywhere build ("which" ,which) ("xxd" ,xxd) ; for https-everywhere build ("yasm" ,yasm))) (arguments `(#:tests? #f ; Some tests are autodone by mach on build fase. ;; XXX: There are RUNPATH issues such as ;; $prefix/lib/icecat-31.6.0/plugin-container NEEDing libmozalloc.so, ;; which is not in its RUNPATH, but they appear to be harmless in ;; practice somehow. See . #:validate-runpath? #f #:imported-modules ,%cargo-utils-modules ;for `generate-all-checksums' #:modules ((ice-9 ftw) (ice-9 rdelim) (ice-9 regex) (ice-9 match) (srfi srfi-34) (srfi srfi-35) (rnrs bytevectors) (rnrs io ports) (guix elf) (guix build gremlin) (guix build utils) (sxml simple) ,@%gnu-build-system-modules) #:phases (modify-phases %standard-phases (add-after 'unpack 'unpack-extensions (lambda* (#:key inputs native-inputs #:allow-other-keys) (let ((https-everywhere-archive "https-everywhere.tar.gz") (https-everywhere-srcdir "https-everywhere-src") (bash (which "bash"))) (setenv "SHELL" bash) (mkdir https-everywhere-srcdir) (invoke "tar" "xf" https-everywhere-archive "--strip-components=1" "-C" https-everywhere-srcdir)) #t)) (add-after 'unpack-extensions 'apply-guix-specific-patches (lambda* (#:key inputs native-inputs #:allow-other-keys) (let ((patch (string-append (assoc-ref (or native-inputs inputs) "patch") "/bin/patch"))) (for-each (match-lambda ((label . file) (when (and (string-prefix? "torbrowser-" label) (string-suffix? ".patch" label)) (format #t "applying '~a'...~%" file) (invoke patch "--force" "--no-backup-if-mismatch" "-p1" "--input" file)))) (or native-inputs inputs))) #t)) ;; On mach build system this is done on configure. (delete 'bootstrap) (add-after 'patch-source-shebangs 'patch-cargo-checksums (lambda _ (use-modules (guix build cargo-utils)) (let ((null-hash "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")) (substitute* '("Cargo.lock" "gfx/wr/Cargo.lock") (("(\"checksum .* = )\".*\"" all name) (string-append name "\"" null-hash "\""))) (generate-all-checksums "third_party/rust")) #t)) (add-after 'build 'neutralize-store-references (lambda _ ;; Mangle the store references to compilers & other build tools in ;; about:buildconfig, reducing TorBrowser's closure significant. ;; The resulting files are saved in lib/firefox/omni.ja (substitute* "objdir/dist/bin/chrome/toolkit/content/global/buildconfig.html" (((format #f "(~a/)([0-9a-df-np-sv-z]{32})" (regexp-quote (%store-directory))) _ store hash) (string-append store (string-take hash 8) "" (string-drop hash 8)))) #t)) (replace 'configure (lambda* (#:key inputs outputs configure-flags #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (bash (which "bash")) (flags `(,(string-append "--prefix=" out) ,@configure-flags))) (setenv "SHELL" bash) (setenv "AUTOCONF" (string-append (assoc-ref %build-inputs "autoconf") "/bin/autoconf")) (setenv "CONFIG_SHELL" bash) (setenv "PYTHON" (string-append (assoc-ref inputs "python2") "/bin/python")) (setenv "MOZ_BUILD_DATE" ,%torbrowser-build-id) ; avoid timestamp. (setenv "LDFLAGS" (string-append "-Wl,-rpath=" (assoc-ref outputs "out") "/lib/firefox")) (substitute* ".mozconfig" ;; Arch independent builddir. (("(mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj).*" _ m) (string-append m "dir\n")) (("ac_add_options --disable-tor-launcher") "") ;; We won't be building incrementals. (("ac_add_options --enable-signmar") "") (("ac_add_options --enable-verify-mar") "") (("ac_add_options --with-tor-browser-version=dev-build") (string-append "ac_add_options --with-tor-browser-version=org.gnu\n" "ac_add_options --with-unsigned-addon-scopes=app\n" "ac_add_options --enable-pulseaudio\n" "ac_add_options --disable-debug-symbols\n" "ac_add_options --disable-updater\n" "ac_add_options --disable-gconf\n" ;; Other syslibs that can be unbundled? (nss, nspr) "ac_add_options --enable-system-pixman\n" "ac_add_options --enable-system-ffi\n" "ac_add_options --with-system-bz2\n" "ac_add_options --with-system-icu\n" "ac_add_options --with-system-jpeg\n" "ac_add_options --with-system-libevent\n" "ac_add_options --with-system-zlib\n" ;; Without these clang is not found. "ac_add_options --with-clang-path=" (assoc-ref %build-inputs "clang") "/bin/clang\n" "ac_add_options --with-libclang-path=" (assoc-ref %build-inputs "clang") "/lib\n"))) (substitute* "browser/app/profile/000-tor-browser.js" ;; TorBrowser updates are disabled on mozconfig, but let's make sure. (("(pref\\(\"extensions.torbutton.versioncheck_enabled\").*" _ m) (string-append m ",false);\n"))) (substitute* "browser/extensions/tor-launcher/src/defaults/preferences/torlauncher-prefs.js" ;; Not multilingual. See tor-browser/build:141. Currently disabled on ;; tor-launcher, but let's make sure while missing langpacks. (("(pref\\(\"extensions.torlauncher.prompt_for_locale\").*" _ m) (string-append m ", false);\n"))) ;; For user data outside the guix store. (substitute* "xpcom/io/TorFileUtils.cpp" (("ANDROID") "GNUGUIX")) (substitute* "old-configure.in" (("(AC_SUBST\\(TOR_BROWSER_DISABLE_TOR_LAUNCHER\\))" _ m) (string-append m "\n AC_DEFINE(GNUGUIX)\n"))) (format #t "Invoking mach configure ...~%") (invoke "./mach" "configure")) #t)) (add-after 'configure 'build-extensions (lambda* (#:key inputs native-inputs #:allow-other-keys) (let ((bash (which "bash"))) (setenv "SHELL" bash) ;; Python3.6 is hardcoded on these scripts. Using v3.8 appears to ;; be harmless. (with-directory-excursion "https-everywhere-src" (substitute* '("install-dev-dependencies.sh" "make.sh" "hooks/precommit" "test/firefox.sh" "test/manual.sh" "test/script.py" "test/validations.sh" "utils/create_zip.py" "utils/merge-rulesets.py" "utils/setversion.py" "utils/zipfile_deterministic.py") (("python3.6") "python3")) ;; Failing to generate the xpi, but copy-dir appears to be enough. ;; Failing on missing 'wasm'? Not generating rulesets. (invoke "./make.sh"))) #t)) (replace 'build (lambda _ (invoke "./mach" "build"))) ;; TorBrowser just do a stage-package here and copy files to its places. (replace 'install (lambda* (#:key inputs native-inputs outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (applications (string-append out "/share/applications")) (builddir "objdir/dist/firefox") (bindir (string-append out "/bin")) (libdir (string-append out "/lib/firefox")) (extdir (string-append libdir "/browser/extensions")) (tordir (string-append libdir "/TorBrowser/Tor")) (ptdir (string-append tordir "/PluggableTransports")) (tbbscripts-dir "tbb-scripts/projects/tor-browser") (ptconfigsdir (string-append tbbscripts-dir "/Bundle-Data/PTConfigs")) (torbrowser-fonts (or (assoc-ref native-inputs "torbrowser-fonts") (assoc-ref inputs "torbrowser-fonts"))) (obfs4bin (string-append (assoc-ref inputs "obfs4") "/bin/obfs4proxy")) (torbin (string-append (assoc-ref inputs "tor") "/bin/tor")) (tbb-start-script (string-append tbbscripts-dir "/RelativeLink/start-tor-browser")) (tbb-desktop (string-append tbbscripts-dir "/RelativeLink/start-tor-browser.desktop")) (tbbdocs-in (string-append tbbscripts-dir "/Bundle-Data/Docs")) (tbbdocs-out (string-append libdir "/TorBrowser/Docs")) (tordata-in (string-append tbbscripts-dir "/Bundle-Data/linux/Data")) (tordata-out (string-append libdir "/TorBrowser/Data")) (noscript-id "{73a6fe31-595d-460b-a920-fcc0f8843232}") (httpse-id "https-everywhere-eff@eff.org")) ;; Stage-package (format #t "Staging package ...~%") (invoke "./mach" "build" "stage-package") ;; Now we start moving files to its default paths. (format #t "Deleting spurious files ...~%") ;; TorBrowser doesn't use those. ;; See: tor-browser-build.git/projects/firefox/build:167 (with-directory-excursion builddir (for-each (lambda (file) (if (file-exists? file) (delete-file file) (display (string-append "Warning: file " file " not found! Skipping...\n")))) '("firefox-bin" "libfreeblpriv3.chk" "libnssdbm3.chk" "libsoftokn3.chk" "fonts/TwemojiMozilla.ttf"))) (rmdir (string-append builddir "/fonts")) (format #t "Creating install dirs ...~%") (mkdir-p libdir) (mkdir bindir) (mkdir-p applications) (mkdir-p tordir) (mkdir-p ptdir) (mkdir-p tordata-out) (mkdir-p tbbdocs-out) (mkdir-p extdir) (format #t "Copying files to install dirs ...~%") (copy-recursively builddir (string-append libdir "/") #:log (%make-void-port "w")) (copy-file tbb-start-script (string-append libdir "/start-tor-browser")) (chmod (string-append libdir "/start-tor-browser") #o555) (copy-file tbb-desktop (string-append libdir "/start-tor-browser.desktop")) (chmod (string-append libdir "/start-tor-browser.desktop") #o555) (install-file tbb-desktop applications) (with-directory-excursion (string-append libdir "/browser/chrome/icons/default") (for-each (lambda (file) (let* ((size (string-filter char-numeric? file)) (icons (string-append out "/share/icons/hicolor/" size "x" size "/apps"))) (mkdir-p icons) (copy-file file (string-append icons "/torbrowser.png")))) '("default16.png" "default32.png" "default48.png" "default64.png" "default128.png"))) (format #t "Linking start-tor-browser script ...~%") (symlink (string-append libdir "/start-tor-browser") (string-append bindir "/start-tor-browser")) (format #t "Copying fonts to install dirs ...~%") (copy-recursively torbrowser-fonts (string-append libdir "/") #:log (%make-void-port "w")) (format #t "Linking store tor binary ...~%") (symlink torbin (string-append tordir "/tor")) (format #t "Linking store obfs4 binary ...~%") (symlink obfs4bin (string-append ptdir "/obfs4proxy")) (format #t "Copying Bundle-Data to default path ...~%") (with-directory-excursion tordata-in (for-each (lambda (file) (copy-recursively file (string-append tordata-out "/" file) #:log (%make-void-port "w"))) '("Browser" "fontconfig" "Tor"))) (copy-file (string-append ptconfigsdir "/linux/torrc-defaults-appendix") (string-append tordata-out "/Tor/torrc-defaults-appendix")) (copy-file (string-append ptconfigsdir "/bridge_prefs.js") (string-append tordata-out "/Browser/bridge-prefs-js-appendix")) (format #t "Copying licenses and changelog to default path ...~%") (copy-recursively tbbdocs-in (string-append tbbdocs-out "/") #:log (%make-void-port "w")) (format #t "Copying noscript ...~%") (copy-file "noscript.xpi" (string-append extdir "/" noscript-id ".xpi")) (format #t "Copying https-everywhere ...~%") (if (file-exists? "https-everywhere-src/pkg/https-everywhere-2020.5.20~pre-eff.xpi") (copy-file "https-everywhere-src/pkg/https-everywhere-2020.5.20~pre-eff.xpi" (string-append extdir "/" httpse-id ".xpi")) (copy-recursively "https-everywhere-src/pkg/xpi-eff" (string-append extdir "/" httpse-id) #:log (%make-void-port "w")))) #t))))) (home-page "https://www.torproject.org") (synopsis "Anonymous browser derived from Mozilla Firefox") (description "TorBrowser is the Tor Project version of Firefox browser. It is the only recommended way to anonymously browse the web that is supported by the project. It modifies Firefox in order to avoid many know application level attacks on the privacy of Tor users. WARNING: This is not the official TorBrowser and is currently on testing. Use at your own risk and please report back on guix channels if you find any issues.") (license license:mpl2.0))) ;and others, see toolkit/content/license.html