projects/guix·blob javascript-team · refs

938 lines · 41.2 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2013, 2015 Andreas Enge <[email protected]>
3;;; Copyright © 2013-2022 Ludovic Courtès <[email protected]>
4;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Mark H Weaver <[email protected]>
5;;; Copyright © 2015 Sou Bunnbu <[email protected]>
6;;; Copyright © 2016, 2017, 2018, 2019, 2021 Efraim Flashner <[email protected]>
7;;; Copyright © 2016 Alex Griffin <[email protected]>
8;;; Copyright © 2017, 2023, 2024 Clément Lassieur <[email protected]>
9;;; Copyright © 2017, 2018 Nikita <[email protected]>
10;;; Copyright © 2017, 2018, 2020 Tobias Geerinckx-Rice <[email protected]>
11;;; Copyright © 2018, 2020 Ricardo Wurmus <[email protected]>
12;;; Copyright © 2019 Ivan Petkov <[email protected]>
13;;; Copyright © 2020 Oleg Pykhalov <[email protected]>
14;;; Copyright © 2020 Jakub Kądziołka <[email protected]>
15;;; Copyright © 2019, 2020 Adrian Malacoda <[email protected]>
16;;; Copyright © 2020-2023 Jonathan Brielmaier <[email protected]>
17;;; Copyright © 2020, 2022 Marius Bakke <[email protected]>
18;;; Copyright © 2021 Brice Waegeneire <[email protected]>
19;;; Copyright © 2021 Maxime Devos <[email protected]>
20;;; Copyright © 2021, 2022, 2023 Maxim Cournoyer <[email protected]>
21;;; Copyright © 2021 Baptiste Strazzul <[email protected]>
22;;; Copyright © 2022 SeerLite <[email protected]>
23;;; Copyright © 2024 Aleksandr Vityazev <[email protected]>
24;;; Copyright © 2020, 2021, 2024 André Batista <[email protected]>
25;;;
26;;; This file is part of GNU Guix.
27;;;
28;;; GNU Guix is free software; you can redistribute it and/or modify it
29;;; under the terms of the GNU General Public License as published by
30;;; the Free Software Foundation; either version 3 of the License, or (at
31;;; your option) any later version.
32;;;
33;;; GNU Guix is distributed in the hope that it will be useful, but
34;;; WITHOUT ANY WARRANTY; without even the implied warranty of
35;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36;;; GNU General Public License for more details.
37;;;
38;;; You should have received a copy of the GNU General Public License
39;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
40
41(define-module (gnu packages tor-browsers)
42 #:use-module ((guix licenses) #:prefix license:)
43 #:use-module (gnu packages assembly)
44 #:use-module (gnu packages base)
45 #:use-module (gnu packages bash)
46 #:use-module (gnu packages browser-extensions)
47 #:use-module (gnu packages compression)
48 #:use-module (gnu packages cups)
49 #:use-module (gnu packages freedesktop)
50 #:use-module (gnu packages fontutils)
51 #:use-module (gnu packages gl)
52 #:use-module (gnu packages glib)
53 #:use-module (gnu packages gnome)
54 #:use-module (gnu packages golang-web)
55 #:use-module (gnu packages gtk)
56 #:use-module (gnu packages hunspell)
57 #:use-module (gnu packages icu4c)
58 #:use-module (gnu packages image)
59 #:use-module (gnu packages kerberos)
60 #:use-module (gnu packages libcanberra)
61 #:use-module (gnu packages libevent)
62 #:use-module (gnu packages libffi)
63 #:use-module (gnu packages linux)
64 #:use-module (gnu packages llvm)
65 #:use-module (gnu packages m4)
66 #:use-module (gnu packages node)
67 #:use-module (gnu packages nss)
68 #:use-module (gnu packages pciutils)
69 #:use-module (gnu packages perl)
70 #:use-module (gnu packages pkg-config)
71 #:use-module (gnu packages pulseaudio)
72 #:use-module (gnu packages python)
73 #:use-module (gnu packages rust)
74 #:use-module (gnu packages rust-apps)
75 #:use-module (gnu packages tor)
76 #:use-module (gnu packages video)
77 #:use-module (gnu packages xdisorg)
78 #:use-module (gnu packages xorg)
79 #:use-module (gnu packages)
80 #:use-module (guix build-system cargo)
81 #:use-module (guix build-system copy)
82 #:use-module (guix build-system gnu)
83 #:use-module (guix build-system mozilla)
84 #:use-module (guix download)
85 #:use-module (guix gexp)
86 #:use-module (guix git-download)
87 #:use-module (guix hg-download)
88 #:use-module (guix packages)
89 #:use-module (ice-9 regex)
90 #:use-module (guix utils))
91
92;; See browser/locales/l10n-changesets.json for the commit.
93(define firefox-locales
94 (let ((commit "412690f1368e37f70af57eecabb93497167eb9ba")
95 (revision "2"))
96 (package
97 (name "firefox-locales")
98 (version (git-version "0.0.0" revision commit))
99 (source
100 (origin
101 (method git-fetch)
102 (uri (git-reference
103 (url "https://github.com/mozilla-l10n/firefox-l10n")
104 (commit commit)))
105 (file-name (git-file-name name version))
106 (sha256
107 (base32
108 "15614g94zdk3n1nnx5jy622zryv2ydd5cmn4pidwrl07g1f3xxxa"))))
109 (build-system copy-build-system)
110 (home-page "https://github.com/mozilla-l10n/firefox-l10n")
111 (synopsis "Firefox Locales")
112 (description "This package contains localized messages for all
113Firefox locales.")
114 (license license:mpl2.0))))
115
116;; We copy the official build id, which is defined at
117;; tor-browser-build/rbm.conf (browser_release_date).
118(define %torbrowser-build-date "20260928083000")
119
120;; To find the last version, look at https://www.torproject.org/download/.
121(define %torbrowser-version "15.0.24")
122
123;; To find the last Firefox version, browse
124;; https://archive.torproject.org/tor-package-archive/torbrowser/<%torbrowser-version>
125;; There should be only one archive that starts with
126;; "src-firefox-tor-browser-".
127(define %torbrowser-firefox-version "140.17.0esr-15.0-1-build4")
128
129;; See tor-browser-build/rbm.conf for the list.
130(define %torbrowser-locales (list "ar" "be" "bg" "ca" "cs" "da" "de" "el" "es-ES" "fa"
131 "fi" "fr" "ga-IE" "he" "hu" "id" "is" "it" "ja" "ka"
132 "ko" "lt" "mk" "ms" "my" "nb-NO" "nl" "pl" "pt-BR"
133 "pt-PT" "ro" "ru" "sq" "sv-SE" "th" "tr" "uk" "vi"
134 "zh-CN" "zh-TW"))
135
136;; See tor-browser-build/projects/translation/config.
137(define torbrowser-translation-base
138 (origin
139 (method git-fetch)
140 (uri (git-reference
141 (url "https://gitlab.torproject.org/tpo/translation.git")
142 (commit "c62d7c244409d6d6ca37cd7f4819260ffc3cf60b")))
143 (file-name "translation-base-browser")
144 (sha256
145 (base32
146 "0gasp5gx4zc603yjhxi5rhagjq5pswvyxdgin75ax5p76bkaypcp"))))
147
148;; See tor-browser-build/projects/translation/config.
149(define torbrowser-translation-specific
150 (origin
151 (method git-fetch)
152 (uri (git-reference
153 (url "https://gitlab.torproject.org/tpo/translation.git")
154 (commit "8cae94965791def3a7e63a1acb9e998ce8133de9")))
155 (file-name "translation-tor-browser")
156 (sha256
157 (base32
158 "03dhx4zlawmymp3v7fv9mr9nywpryblha3iz344s7riwk7iv8ivl"))))
159
160(define torbrowser-assets
161 ;; This is a prebuilt Torbrowser from which we take the assets we need.
162 (package
163 (name "torbrowser-assets")
164 (version %torbrowser-version)
165 (source
166 (origin
167 (method url-fetch)
168 (uri
169 (string-append
170 "https://archive.torproject.org/tor-package-archive/torbrowser/"
171 version "/tor-browser-linux-x86_64-" version ".tar.xz"))
172 (sha256
173 (base32
174 "016n0nc1vj66x236aqlx1yffs36zq2ajry343lxbbb72xfvfygmh"))))
175 (arguments
176 (list
177 #:install-plan
178 ''(("Browser" "." #:include-regexp
179 ("^\\./TorBrowser/Data/Tor/torrc-defaults"
180 "^\\./fonts/")))))
181 (build-system copy-build-system)
182 (home-page "https://www.torproject.org")
183 (synopsis "Tor Browser assets")
184 (description "This package contains fonts and configuration files for Tor
185Browser.")
186 (license license:silofl1.1)))
187
188;;; A LLD wrapper that can be used as a (near) drop-in replacement to GNU ld.
189(define lld-as-ld-wrapper-19
190 (make-lld-wrapper lld-19 #:lld-as-ld? #t))
191
192(define* (make-torbrowser #:key
193 moz-app-name
194 moz-app-remotingname
195 branding-directory
196 translation-base
197 translation-specific
198 assets
199 locales
200 build-date
201 base-browser-version)
202 (package
203 (name "torbrowser")
204 (version %torbrowser-version)
205 (source
206 (origin
207 (method url-fetch)
208 (uri
209 (string-append
210 "https://archive.torproject.org/tor-package-archive/torbrowser/"
211 version "/src-firefox-tor-browser-" %torbrowser-firefox-version
212 ".tar.xz"))
213 (sha256
214 (base32
215 "17qnisicbr6rvlc7kaxjjinif1jkvh8fnivj47aq36lj3jdac5y2"))))
216 (build-system mozilla-build-system)
217 (inputs
218 (list lyrebird
219 firefox-locales
220 tor-client
221 alsa-lib
222 bash-minimal ;for wrap-program
223 cups
224 dbus-glib
225 gdk-pixbuf
226 glib
227 gtk+
228 cairo
229 pango
230 freetype
231 libcanberra
232 libgnome
233 libjpeg-turbo
234 libpng-apng-next
235 libwebp
236 libxft
237 libevent
238 libxinerama
239 libxscrnsaver
240 libxcomposite
241 libxt
242 libffi
243 ;; See <https://bugzilla.mozilla.org/show_bug.cgi?id=1962139>
244 ffmpeg-6
245 libvpx
246 icu4c-76
247 pixman
248 pulseaudio
249 mesa
250 pciutils
251 mit-krb5
252 hunspell
253 libnotify
254 nspr
255 nss-rapid
256 shared-mime-info
257 eudev
258 unzip
259 zip
260 zlib))
261 (native-inputs
262 (append
263 (list
264 rust
265 `(,rust "cargo")
266 rust-cbindgen-0.28
267 lld-as-ld-wrapper-19 ; for cargo rustc
268 llvm-19
269 clang-19
270 perl
271 node-lts
272 python-wrapper
273 yasm
274 pkg-config
275 m4
276 which)
277 (if (target-x86?) (list nasm) '())))
278 (arguments
279 (list
280 #:tests? #f ;not worth the cost
281
282 ;; Some dynamic lib was determined at runtime, so rpath check may fail.
283 #:validate-runpath? #f
284
285 #:configure-flags
286 #~(list
287 "--without-relative-data-dir" ;store is read-only
288 "--disable-base-browser-update"
289 ;; Default is "default", which is the same as "nightly".
290 "--enable-update-channel=release"
291 ;; This is useless right now but it might be used in the future.
292 ;; (See nsAppFileLocationProvider.cpp.)
293 (string-append "--with-user-appdir=." #$moz-app-name)
294 (string-append "--with-branding=" #$branding-directory)
295 (string-append "--prefix=" #$output)
296 (string-append "--with-base-browser-version="
297 #$base-browser-version)
298
299 "--enable-application=browser"
300 "--with-distribution-id=org.gnu"
301 "--enable-geckodriver"
302 ;; Do not require addons in the global app or system directories to
303 ;; be signed by Mozilla.
304 "--with-unsigned-addon-scopes=app,system"
305 "--allow-addon-sideload"
306
307 "--enable-pulseaudio"
308
309 "--disable-tests"
310 "--disable-updater"
311 "--disable-crashreporter"
312 ;; The --disable-eme option is not available on aarch64.
313 #$(if (target-aarch64?) "" "--disable-eme")
314
315 ;; Building with debugging symbols takes ~5GiB, so disable it.
316 "--disable-debug"
317 "--disable-debug-symbols"
318
319 "--enable-rust-simd"
320 "--enable-release"
321 "--enable-optimize"
322 "--enable-strip"
323 "--disable-elf-hack"
324
325 ;; Clang is needed to build Stylo, Mozilla's new CSS engine. We must
326 ;; specify the clang paths manually, because otherwise the Mozilla
327 ;; build system looks in the directories returned by llvm-config
328 ;; --bindir and llvm-config --libdir, which return paths in the llvm
329 ;; package where clang is not found.
330 (string-append "--with-clang-path="
331 (search-input-file %build-inputs "bin/clang"))
332 (string-append "--with-libclang-path="
333 (dirname (search-input-file %build-inputs
334 "lib/libclang.so")))
335
336 ;; TODO: Add support for wasm sandboxed libraries.
337 "--without-wasm-sandboxed-libraries"
338
339 ;; Avoid bundled libraries.
340 "--with-system-jpeg" ;must be libjpeg-turbo
341 "--with-system-png" ;must be libpng-apng
342 "--with-system-webp"
343 "--with-system-zlib"
344 "--with-system-libevent"
345 "--with-system-libvpx"
346 "--with-system-icu"
347 "--with-system-nspr"
348 "--with-system-nss"
349 "--with-system-ffi"
350
351 "--enable-system-pixman"
352 )
353
354 #:imported-modules %cargo-utils-modules ;for `generate-all-checksums'
355
356 #:modules `((ice-9 ftw)
357 (ice-9 match)
358 (srfi srfi-1)
359 (srfi srfi-26)
360 (rnrs bytevectors)
361 (rnrs io ports)
362 (guix elf)
363 (guix build gremlin)
364 ,@%default-gnu-imported-modules)
365 #:phases
366 #~(modify-phases %standard-phases
367 (add-after 'unpack 'apply-guix-specific-patches
368 (lambda _
369 (for-each
370 (lambda (file) (invoke "patch" "--force" "-p1" "-i" file))
371 '(#$(local-file
372 (search-patch "torbrowser-compare-paths.patch"))
373 #$(local-file
374 (search-patch
375 "torbrowsers-add-store-to-rdd-allowlist.patch"))
376 #$(local-file
377 (search-patch "torbrowser-use-system-wide-dir.patch"))))))
378 (add-after 'apply-guix-specific-patches 'remove-bundled-libraries
379 (lambda _
380 ;; Remove bundled libraries that we don't use, since they may
381 ;; contain unpatched security flaws, they waste disk space and
382 ;; memory, and may cause confusion.
383 (for-each (lambda (file)
384 (format #t "deleting '~a'...~%" file)
385 (delete-file-recursively file))
386 '( ;; FIXME: Removing the bundled icu breaks configure.
387 ;; * The bundled icu headers are used in some places.
388 ;; * The version number is taken from the bundled copy.
389 ;;"intl/icu"
390 ;;
391 ;; FIXME: A script from the bundled nspr is used.
392 ;;"nsprpub"
393 ;;
394 ;; FIXME: Some of the bundled NSS sources are used
395 ;; to build netwerk/socket/neqo_glue.
396 ;;"security/nss"
397 ;;
398 "modules/freetype2"
399 ;; "media/libjpeg" ; needed for now, because media/libjpeg/moz.build is referenced from config/external/moz.build
400 "modules/zlib"
401 "ipc/chromium/src/third_party/libevent"
402 "media/libvpx"
403 ;; UNBUNDLE-ME! "media/libtremor"
404 "media/libwebp"
405 "js/src/ctypes/libffi"
406 ;; 800Mo of unused tests.
407 "testing/web-platform"
408 ))))
409 (add-after 'remove-bundled-libraries 'fix-ffmpeg-runtime-linker
410 (lambda* (#:key inputs #:allow-other-keys)
411 ;; Arrange to load libavcodec.so by its absolute file name.
412 (substitute* "dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp"
413 (("libavcodec\\.so")
414 (search-input-file inputs "lib/libavcodec.so")))))
415
416 (add-after 'fix-ffmpeg-runtime-linker 'fix-zucchini
417 (lambda _
418 ;; This option breaks the configure phase.
419 (substitute* "browser/config/mozconfigs/base-browser"
420 (("ac_add_options --disable-zucchini") ""))))
421 (add-after 'patch-source-shebangs 'patch-cargo-checksums
422 (lambda _
423 (use-modules (guix build cargo-utils))
424 (let ((null-hash "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"))
425 (for-each (lambda (file)
426 (format #t "patching checksums in ~a~%" file)
427 (substitute* file
428 (("^checksum = \".*\"")
429 (string-append "checksum = \"" null-hash "\""))))
430 (find-files "." "Cargo.lock$"))
431 (for-each generate-all-checksums
432 '("services"
433 "js"
434 "third_party/rust"
435 "dom/media"
436 "dom/webauthn"
437 "toolkit"
438 "gfx"
439 "storage"
440 "modules"
441 "xpcom/rust"
442 "media"
443 "mozglue/static/rust"
444 "netwerk"
445 "remote"
446 "intl"
447 "servo"
448 "security/manager/ssl"
449 "build")))))
450 (add-after 'patch-cargo-checksums 'remove-cargo-frozen-flag
451 (lambda _
452 ;; Remove --frozen flag from cargo invocation, otherwise it'll
453 ;; complain that it's not able to change Cargo.lock.
454 ;; https://bugzilla.mozilla.org/show_bug.cgi?id=1726373
455 (substitute* "build/RunCbindgen.py"
456 (("args.append\\(\"--frozen\"\\)") "pass"))))
457 (delete 'bootstrap)
458 (add-before 'configure 'setenv
459 (lambda _
460 (setenv "CONFIG_SHELL" (which "bash"))
461 ;; Use Clang, Clang is 2x faster than GCC
462 (setenv "AR" "llvm-ar")
463 (setenv "NM" "llvm-nm")
464 (setenv "CC" "clang")
465 (setenv "CXX" "clang++")
466 ;; Install location is prefix/lib/$MOZ_APP_NAME. Also
467 ;; $MOZ_APP_NAME is the executable name. Default is
468 ;; "firefox".
469 (setenv "MOZ_APP_NAME" #$moz-app-name)
470 ;; WM_CLASS (default is "$MOZ_APP_NAME-$MOZ_UPDATE_CHANNEL").
471 (setenv "MOZ_APP_REMOTINGNAME" #$moz-app-remotingname)
472 ;; Persistent state directory for the build system (default is
473 ;; $HOME/.mozbuild).
474 (setenv "MOZBUILD_STATE_PATH"
475 (in-vicinity (getcwd) ".mozbuild"))
476 (setenv "MOZ_CHROME_MULTILOCALE"
477 (string-join (list #$@locales)))
478 ;; Make build reproducible.
479 (setenv "MOZ_BUILD_DATE" #$build-date)))
480 (add-before 'configure 'mozconfig
481 (lambda* (#:key configure-flags #:allow-other-keys)
482 (let ((arch (cond (#$(target-arm32?) "arm")
483 (#$(target-aarch64?) "aarch64")
484 (#$(target-x86-32?) "i686")
485 (#$(target-x86-64?) "x86_64"))))
486 (with-output-to-file "mozconfig"
487 (lambda ()
488 (format #t ". $topsrcdir/mozconfig-linux-~a~%" arch)
489 (for-each (lambda (flag)
490 (format #t "ac_add_options ~a~%" flag))
491 configure-flags))))))
492 ;; See tor-browser-build/projects/common/browser-localization.
493 (add-before 'configure 'copy-firefox-locales
494 (lambda _
495 (let ((l10ncentral ".mozbuild/l10n-central")
496 (ff-locales #$(this-package-input "firefox-locales")))
497 (mkdir-p l10ncentral)
498 (for-each
499 (lambda (lang)
500 (copy-recursively (string-append ff-locales "/" lang)
501 (in-vicinity l10ncentral lang)))
502 (list #$@locales)))))
503 (add-after 'copy-firefox-locales 'copy-basebrowser-locales
504 (lambda _
505 (let ((l10ncentral ".mozbuild/l10n-central"))
506 ;; Temporary copy so that we can use ‘mv’ to mimic
507 ;; tor-browser-build/projects/common/browser-localization
508 (copy-recursively #$translation-base
509 "translation-base-browser")
510 (for-each
511 (lambda (lang)
512 (system
513 (format
514 #f (string-join
515 '("mv"
516 "translation-base-browser/~a/base-browser.ftl"
517 "~a/~a/toolkit/toolkit/global/"))
518 lang l10ncentral lang)))
519 (list #$@locales)))))
520 (add-after 'copy-basebrowser-locales 'copy-torbrowser-locales
521 (lambda _
522 (let ((l10ncentral ".mozbuild/l10n-central"))
523 ;; Temporary copy so that we can use ‘mv’ to mimic
524 ;; tor-browser-build/projects/common/browser-localization
525 (copy-recursively #$translation-specific
526 "translation-tor-browser")
527 (for-each
528 (lambda (lang)
529 (system
530 (format
531 #f (string-join
532 '("mv"
533 "translation-tor-browser/~a/tor-browser.ftl"
534 "~a/~a/toolkit/toolkit/global/"))
535 lang l10ncentral lang))
536 (mkdir-p (string-append l10ncentral "/" lang
537 "/" #$branding-directory))
538 (system
539 (format
540 #f (string-join
541 '("mv"
542 "translation-tor-browser/~a/branding/brand.ftl"
543 "~a/~a/~a/"))
544 lang l10ncentral lang #$branding-directory))
545 (system
546 (format
547 #f (string-join
548 '("mv"
549 "translation-tor-browser/~a/brand.properties"
550 "~a/~a/~a/"))
551 lang l10ncentral lang #$branding-directory))
552 (mkdir-p (string-append "toolkit/torbutton/chrome/locale/"
553 lang))
554 (system
555 (format
556 #f (string-join
557 '("mv"
558 "translation-tor-browser/~a/*.properties"
559 "toolkit/torbutton/chrome/locale/~a/"))
560 lang lang))
561 (let ((port (open-file "toolkit/torbutton/jar.mn" "a")))
562 (format port "% locale torbutton ~a %locale/~a/~%"
563 lang lang)
564 (format port " locale/~a/ (chrome/locale/~a/*)~%"
565 lang lang)
566 (close port)))
567 (list #$@locales)))))
568 (replace 'configure
569 (lambda _
570 (invoke "./mach" "configure")))
571 (add-before 'build 'fix-addons-placeholder
572 (lambda _
573 (substitute*
574 "toolkit/locales/en-US/toolkit/about/aboutAddons.ftl"
575 (("addons.mozilla.org") "gnuzilla.gnu.org"))))
576 (replace 'build
577 (lambda* (#:key (make-flags '()) (parallel-build? #t)
578 #:allow-other-keys)
579 (apply invoke "./mach" "build"
580 ;; mach will use a wide parallel build if possible by
581 ;; default, so reign it in if requested.
582 `(,(string-append
583 "-j" (number->string (if parallel-build?
584 (parallel-job-count)
585 1)))
586 ,@make-flags))))
587 ;; See tor-browser-build/projects/firefox/build.
588 (add-after 'build 'build-locales
589 (lambda _
590 (system (string-join '("./mach package-multi-locale --locales"
591 "en-US $MOZ_CHROME_MULTILOCALE")))))
592 (add-after 'build-locales 'neutralise-store-references
593 (lambda _
594 ;; Mangle the store references to compilers & other build tools in
595 ;; about:buildconfig, reducing IceCat's closure by 1 GiB on x86-64.
596 (let* ((obj-dir (match (scandir "." (cut string-prefix? "obj-" <>))
597 ((dir) dir)))
598 (file (string-append
599 obj-dir
600 "/dist/bin/chrome/toolkit/content/global/buildconfig.html")))
601 (substitute* file
602 (("[0-9a-df-np-sv-z]{32}" hash)
603 (string-append (string-take hash 8)
604 "<!-- Guix: not a runtime dependency -->"
605 (string-drop hash 8)))))))
606 (replace 'install
607 (lambda* (#:key outputs #:allow-other-keys)
608 (invoke "./mach" "install")
609 ;; The geckodriver binary is not installed by the above, for some
610 ;; reason. Use 'find-files' to avoid having to deal with the
611 ;; system/architecture-specific file name.
612 (install-file (first (find-files "." "geckodriver"))
613 (string-append #$output "/bin"))))
614 (add-after 'install 'remove-duplicate-bin
615 (lambda* (#:key outputs #:allow-other-keys)
616 (delete-file (string-append #$output "/lib/"
617 #$moz-app-name "/"
618 #$moz-app-name "-bin"))))
619 (add-after 'install 'wrap-program
620 (lambda* (#:key inputs #:allow-other-keys)
621 (let* ((gtk #$(this-package-input "gtk+"))
622 (gtk-share (string-append gtk "/share"))
623 (fonts.conf (format #f "~a/lib/~a/fonts/fonts.conf"
624 #$output #$moz-app-name))
625 (ld-libs '#$(cons
626 (file-append
627 (this-package-input "libcanberra")
628 "/lib/gtk-3.0/modules")
629 (map (lambda (label)
630 (file-append (this-package-input label) "/lib"))
631 '("libpng-apng"
632 "libxscrnsaver"
633 "mesa"
634 "pciutils"
635 "mit-krb5"
636 "eudev"
637 "pulseaudio"
638 ;; For the integration of native notifications
639 ;; (same reason as icedove)
640 "libnotify")))))
641 (wrap-program (format #f "~a/lib/~a/~a"
642 #$output #$moz-app-name #$moz-app-name)
643 `("XDG_DATA_DIRS" prefix (,gtk-share))
644 ;; The following line is commented out because the icecat
645 ;; package on guix has been observed to be unstable when
646 ;; using wayland, and the bundled extensions stop working.
647 ;; `("MOZ_ENABLE_WAYLAND" = ("1"))
648 `("LD_LIBRARY_PATH" prefix ,ld-libs)
649 `("FONTCONFIG_FILE" prefix (,fonts.conf))))))
650 (add-after 'wrap-program 'install-desktop-entry
651 (lambda _
652 (let ((apps (in-vicinity #$output "share/applications")))
653 (mkdir-p apps)
654 (make-desktop-entry-file
655 (string-append apps "/" #$moz-app-name ".desktop")
656 #:name #$moz-app-remotingname
657 #:exec (format #f "~a/bin/~a %u" #$output #$moz-app-name)
658 #:categories '("Network" "WebBrowser" "Security")
659 #:startup-w-m-class #$moz-app-remotingname
660 #:icon #$moz-app-name))))
661 (add-after 'install-desktop-entry 'install-icons
662 (lambda* (#:key inputs #:allow-other-keys)
663 (for-each
664 (lambda (size)
665 (let ((oldpath (string-append
666 #$branding-directory "/default" size ".png"))
667 (newpath (string-append
668 #$output "/share/icons/hicolor/" size "x"
669 size "/apps/" #$moz-app-name ".png")))
670 (mkdir-p (dirname newpath))
671 (copy-file oldpath newpath)))
672 '("16" "22" "24" "32" "48" "64" "128" "256"))))
673 (add-after 'install 'deploy-fonts
674 (lambda* (#:key inputs #:allow-other-keys)
675 (let ((lib (string-append #$output "/lib/" #$moz-app-name)))
676 ;; Fonts
677 (delete-file-recursively (in-vicinity lib "fonts"))
678 (copy-recursively (in-vicinity #$assets "fonts")
679 (in-vicinity lib "fonts"))
680 (substitute* (in-vicinity lib "fonts/fonts.conf")
681 (("<dir prefix=\"cwd\">fonts</dir>")
682 (format #f "<dir>~a</dir>" (in-vicinity lib "fonts")))))))
683 (add-after 'deploy-fonts 'deploy-tor-assets
684 (lambda* (#:key inputs #:allow-other-keys)
685 (let ((lib (in-vicinity #$output "lib/torbrowser"))
686 (tor #$(this-package-input "tor-client")))
687 ;; TorBrowser/Data/Tor/torrc-defaults
688 (copy-recursively (in-vicinity #$assets "TorBrowser")
689 (in-vicinity lib "TorBrowser"))
690 (substitute*
691 (in-vicinity lib "TorBrowser/Data/Tor/torrc-defaults")
692 (("exec ./TorBrowser/Tor/PluggableTransports/lyrebird")
693 (string-append
694 "exec " (search-input-file inputs "bin/lyrebird"))))
695 ;; The geoip and geoip6 files are in the same directory as
696 ;; torrc-defaults. (See TorProcess.sys.mjs.)
697 (mkdir-p (in-vicinity lib "TorBrowser/Data/Tor"))
698 (copy-file (in-vicinity tor "share/tor/geoip6")
699 (in-vicinity lib "TorBrowser/Data/Tor/geoip6"))
700 (copy-file (in-vicinity tor "share/tor/geoip")
701 (in-vicinity lib "TorBrowser/Data/Tor/geoip")))))
702 (add-after 'install 'autoconfig
703 (lambda* (#:key inputs #:allow-other-keys)
704 (let ((lib (string-append #$output "/lib/" #$moz-app-name))
705 (config-file (string-append #$moz-app-name ".cfg")))
706 (with-output-to-file (in-vicinity
707 lib "defaults/pref/autoconfig.js")
708 (lambda ()
709 (format #t "// first line must be a comment~%")
710 (format #t "pref(~s, ~s);~%"
711 "general.config.filename" config-file)
712 (format #t "pref(~s, ~a);~%"
713 "general.config.obscure_value" "0")))
714 (with-output-to-file (in-vicinity lib config-file)
715 (lambda ()
716 (format #t "// first line must be a comment~%")
717 ;; Required for Guix packaged extensions
718 ;; SCOPE_PROFILE=1, SCOPE_APPLICATION=4, SCOPE_SYSTEM=8
719 ;; Default is 5.
720 (format #t "pref(~s, ~a);~%"
721 "extensions.enabledScopes" "13")
722 ;; Add-ons panel (see settings.js in Icecat source).
723 (format #t "pref(~s, ~s);~%"
724 "extensions.getAddons.search.browseURL"
725 "https://gnuzilla.gnu.org/mozzarella")
726 (format #t "pref(~s, ~s);~%"
727 "extensions.getAddons.get.url"
728 "https://gnuzilla.gnu.org/mozzarella")
729 (format #t "pref(~s, ~s);~%"
730 "extensions.getAddons.link.url"
731 "https://gnuzilla.gnu.org/mozzarella")
732 (format #t "pref(~s, ~s);~%"
733 "extensions.getAddons.discovery.api_url"
734 "https://gnuzilla.gnu.org/mozzarella")
735 (format #t "pref(~s, ~s);~%"
736 "extensions.getAddons.langpacks.url"
737 "https://gnuzilla.gnu.org/mozzarella")
738 (format #t "pref(~s, ~s);~%"
739 "lightweightThemes.getMoreURL"
740 "https://gnuzilla.gnu.org/mozzarella"))))))
741 (add-after 'autoconfig 'autoconfig-tor
742 (lambda* (#:key inputs #:allow-other-keys)
743 (let ((lib (in-vicinity #$output "lib/torbrowser"))
744 (config-file (string-append #$moz-app-name ".cfg")))
745 (let ((port (open-file (in-vicinity lib config-file) "a")))
746 (format port "pref(~s, ~s);~%"
747 "extensions.torlauncher.torrc-defaults_path"
748 (in-vicinity
749 lib "TorBrowser/Data/Tor/torrc-defaults"))
750 (format port "pref(~s, ~s);~%"
751 "extensions.torlauncher.tor_path"
752 (search-input-file inputs "bin/tor"))
753 (close port))))))))
754 (propagated-inputs
755 (list noscript/icecat))
756 (native-search-paths
757 (list (search-path-specification
758 (variable "ICECAT_SYSTEM_DIR")
759 (separator #f) ;single entry
760 (files '("lib/icecat")))))
761 (supported-systems (list "x86_64-linux" "i686-linux"
762 "aarch64-linux" "armhf-linux"))
763 (home-page "https://www.torproject.org")
764 (synopsis "Anonymous browser derived from Mozilla Firefox")
765 (description
766 "Tor Browser is the Tor Project version of Firefox browser. It is the
767only recommended way to anonymously browse the web that is supported by the
768project. It modifies Firefox in order to avoid many known application level
769attacks on the privacy of Tor users.")
770 (license license:mpl2.0))) ;And others, see
771 ;toolkit/content/license.html
772
773(define-public torbrowser
774 (make-torbrowser #:moz-app-name "torbrowser"
775 #:moz-app-remotingname "Tor Browser"
776 #:branding-directory "browser/branding/tb-release"
777 #:translation-base torbrowser-translation-base
778 #:translation-specific torbrowser-translation-specific
779 #:assets torbrowser-assets
780 #:locales %torbrowser-locales
781 #:build-date %torbrowser-build-date
782 #:base-browser-version %torbrowser-version))
783
784
785;; See tor-browser-build/rbm.conf for the list.
786(define %mullvadbrowser-locales (list "ar" "da" "de" "es-ES" "fa" "fi" "fr" "it"
787 "ja" "ko" "my" "nb-NO" "nl" "pl" "pt-BR"
788 "ru" "sv-SE" "th" "tr" "zh-CN" "zh-TW"))
789
790;; We copy the official build id, which can be found there:
791;; https://cdn.mullvad.net/browser/update_responses/update_1/release.
792(define %mullvadbrowser-build-date "20260928083000")
793
794;; To find the last version, look at
795;; https://mullvad.net/en/download/browser/linux.
796(define %mullvadbrowser-version "15.0.24")
797
798;; To find the last Firefox version, browse
799;; https://archive.torproject.org/tor-package-archive/mullvadbrowser/<%mullvadbrowser-version>
800;; There should be only one archive that starts with
801;; "src-firefox-mullvad-browser-".
802(define %mullvadbrowser-firefox-version "140.17.0esr-15.0-1-build2")
803
804;; See tor-browser-build/projects/translation/config.
805(define mullvadbrowser-translation-base
806 (origin
807 (method git-fetch)
808 (uri (git-reference
809 (url "https://gitlab.torproject.org/tpo/translation.git")
810 (commit "c62d7c244409d6d6ca37cd7f4819260ffc3cf60b")))
811 (file-name "translation-base-browser")
812 (sha256
813 (base32
814 "0gasp5gx4zc603yjhxi5rhagjq5pswvyxdgin75ax5p76bkaypcp"))))
815
816;; See tor-browser-build/projects/translation/config.
817(define mullvadbrowser-translation-specific
818 (origin
819 (method git-fetch)
820 (uri (git-reference
821 (url "https://gitlab.torproject.org/tpo/translation.git")
822 (commit "7ccb76bc67daa5d88da4a1e3ae0021b19bc55c4b")))
823 (file-name "translation-mullvad-browser")
824 (sha256
825 (base32
826 "0a8h46iq3zvc2b0l59y8w628vs21gfh1nz9079hdz5nkpjzk28gi"))))
827
828(define mullvadbrowser-assets
829 ;; This is a prebuilt Mullvad Browser from which we take the assets we need.
830 (package
831 (name "mullvadbrowser-assets")
832 (version %mullvadbrowser-version)
833 (source
834 (origin
835 (method url-fetch)
836 (uri
837 (string-append
838 "https://archive.torproject.org/tor-package-archive/mullvadbrowser/"
839 version "/mullvad-browser-linux-x86_64-" version ".tar.xz"))
840 (sha256
841 (base32
842 "1skgqmylpbdpdp4vl96frfs51i3j7r67sdhgcn0awjvxddknb9dw"))))
843 (arguments
844 (list
845 #:install-plan
846 ''(("Browser" "." #:include-regexp
847 ("^\\./fonts/"
848 "^\\./fontconfig/fonts.conf"
849 ;; Mullvad Browser Extension
850 "^\\./distribution/extensions/\\{d19a89b9-76c1-4a61-bcd4-49e8de916403\\}.xpi"
851 )))))
852 (build-system copy-build-system)
853 (home-page "https://www.torproject.org")
854 (synopsis "Mullvad Browser assets")
855 (description "This package contains fonts and configuration files for
856Mullvad Browser.")
857 (license license:silofl1.1)))
858
859(define mullvadbrowser-base
860 (make-torbrowser #:moz-app-name "mullvadbrowser"
861 #:moz-app-remotingname "Mullvad Browser"
862 #:branding-directory "browser/branding/mb-release"
863 #:translation-base mullvadbrowser-translation-base
864 #:translation-specific mullvadbrowser-translation-specific
865 #:assets mullvadbrowser-assets
866 #:locales %mullvadbrowser-locales
867 #:build-date %mullvadbrowser-build-date
868 #:base-browser-version %mullvadbrowser-version))
869
870(define-public mullvadbrowser
871 (package
872 (inherit mullvadbrowser-base)
873 (name "mullvadbrowser")
874 (version %mullvadbrowser-version)
875 (source
876 (origin
877 (method url-fetch)
878 (uri
879 (string-append
880 "https://archive.torproject.org/tor-package-archive/mullvadbrowser/"
881 version "/src-firefox-mullvad-browser-"
882 %mullvadbrowser-firefox-version ".tar.xz"))
883 (sha256
884 (base32
885 "0j4kl4kzdm68mj20b0571l6jsygmchp85gwx16z9lbkk47l95csl"))))
886 (arguments
887 (substitute-keyword-arguments arguments
888 ((#:phases phases)
889 #~(modify-phases #$phases
890 (add-after 'unpack 'ublock-private-allowed
891 (lambda _
892 (substitute* "toolkit/components/extensions/Extension.sys.mjs"
893 ;; The code that gives the correct permission only applies
894 ;; to distribution add-ons (see installDistributionAddon()
895 ;; in XPIProvider.jsm).
896 (("this.isNoScript")
897 (format #f "this.isNoScript || this.id === ~s"
898 "[email protected]")))))
899 ;; See tor-browser-build/projects/firefox/build.
900 (replace 'copy-torbrowser-locales
901 (lambda _
902 (for-each
903 (lambda (lang)
904 (system
905 (format #f "cp -Lr ~a/~a .mozbuild/l10n-central/"
906 #$mullvadbrowser-translation-specific lang)))
907 (list #$@%mullvadbrowser-locales))))
908 (add-before 'build 'fix-profiles
909 ;; Otherwise the profile would change every time the install
910 ;; location changes, that is: at every package update. These
911 ;; values are already the default values for Icecat and Tor
912 ;; Browser.
913 (lambda _
914 (substitute* "browser/moz.configure"
915 (("\"MOZ_DEDICATED_PROFILES\", True")
916 "\"MOZ_DEDICATED_PROFILES\", False")
917 (("\"MOZ_BLOCK_PROFILE_DOWNGRADE\", True")
918 "\"MOZ_BLOCK_PROFILE_DOWNGRADE\", False"))))
919 (add-after 'deploy-fonts 'deploy-extension
920 (lambda _
921 (let ((lib (in-vicinity #$output "lib/mullvadbrowser")))
922 ;; Mullvad Browser Extension (FIXME: package it)
923 (copy-recursively
924 (in-vicinity #$mullvadbrowser-assets "distribution")
925 (in-vicinity lib "distribution")))))
926 (delete 'deploy-tor-assets)
927 (delete 'autoconfig-tor)))))
928 (inputs
929 (modify-inputs inputs
930 (delete lyrebird)))
931 (propagated-inputs
932 (modify-inputs propagated-inputs
933 (append ublock-origin/icecat)))
934 (home-page "https://mullvad.net/en/browser")
935 (synopsis "Privacy-focused web browser")
936 (description "Mullvad Browser is a privacy-focused web browser developed
937in collaboration between Mullvad VPN and the Tor Project. It’s produced to
938minimize tracking and fingerprinting.")))