Subject: [PATCH 2/2] gnu: Add output in ‘make-icecat-extension’ for each Firefox variant.

From: Clément Lassieur <[email-masked]>
Date: Sun, 7 Jan 2024 01:05:16 +0100

* gnu/build/icecat-extension.scm (make-icecat-extension)[arguments]: Loop
through all variants and for each variant, symlink the add-on there, and in
the main output too.
* gnu/packages/tor.scm (torbrowser)[arguments]: Add a 'fix-system-dir' phase
so that the system directory is not shared between variants.
[propagated-inputs]: Propagate only the "torbrowser" output of
noscript/icecat.
[native-search-paths]: Use TORBROWSER_SYSTEM_DIR instead of inheriting from
the icecat package.

Change-Id: I409bae5c317e98d1bd308eb64a66f1ce1a304bcc
---
 gnu/build/icecat-extension.scm | 28 +++++++++++++++++++---------
 gnu/packages/tor.scm           | 11 ++++++++++-
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/gnu/build/icecat-extension.scm b/gnu/build/icecat-extension.scm
index 9013ab0fac05..b5d44e3b5559 100644
--- a/gnu/build/icecat-extension.scm
+++ b/gnu/build/icecat-extension.scm
@@ -34,7 +34,7 @@ (define* (make-icecat-extension pkg #:optional (pkg-output "out"))
     (native-inputs '())
     (inputs '())
     (propagated-inputs (package-propagated-inputs pkg))
-    (outputs '("out"))
+    (outputs '("out" "icecat" "torbrowser"))
     (build-system trivial-build-system)
     (arguments
      (list
@@ -61,11 +61,21 @@ (define* (make-icecat-extension pkg #:optional (pkg-output "out"))
           ;; which would change too often.  We don't want the add-on path to
           ;; be hard-coded either because it would never change (but it
           ;; wouldn't make sense anyway).
-          (let* ((addon-id #$(assq-ref (package-properties pkg) 'addon-id))
-                 (moz-app-id "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}")
-                 (search-dir (string-append #$output "/lib/icecat/extensions/"
-                                            moz-app-id)))
-
-            (mkdir-p search-dir)
-            (symlink (in-vicinity (ungexp pkg pkg-output) addon-id)
-                     (in-vicinity search-dir addon-id))))))))
+          (for-each
+           (lambda (variant)
+             (let* ((addon-id #$(assq-ref (package-properties pkg) 'addon-id))
+                    (moz-app-id "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}")
+                    (search-dir
+                     (lambda (out)
+                       (string-append (assoc-ref %outputs out) "/lib/" variant
+                                      "/extensions/" moz-app-id)))
+                    (symlink-addon
+                     (lambda (out)
+                       (mkdir-p (search-dir out))
+                       (symlink (in-vicinity (ungexp pkg pkg-output) addon-id)
+                                (in-vicinity (search-dir out) addon-id)))))
+               (symlink-addon variant)
+               ;; Symlink to the main output so that a user can install the
+               ;; add-on for all of the Firefox variants at once.
+               (symlink-addon "out")))
+           (cdr '#$outputs)))))))
diff --git a/gnu/packages/tor.scm b/gnu/packages/tor.scm
index b81944ee6b96..c46f48a808da 100644
--- a/gnu/packages/tor.scm
+++ b/gnu/packages/tor.scm
@@ -563,6 +563,10 @@ (define-public torbrowser
            #$flags))
        ((#:phases phases)
         #~(modify-phases #$phases
+            (add-after 'apply-guix-specific-patches 'fix-system-dir
+              (lambda _
+                (substitute* "toolkit/xre/nsXREDirProvider.cpp"
+                  (("ICECAT_SYSTEM_DIR") "TORBROWSER_SYSTEM_DIR"))))
             (add-before 'configure 'setenv
               (lambda _
                 (setenv "CONFIG_SHELL" (which "bash"))
@@ -758,7 +762,12 @@ (define-public torbrowser
                tor-client
                torbrowser-assets)))
     (propagated-inputs
-     (list noscript/icecat))
+     (list `(,noscript/icecat "torbrowser")))
+    (native-search-paths
+     (list (search-path-specification
+            (variable "TORBROWSER_SYSTEM_DIR")
+            (separator #f)              ;single entry
+            (files '("lib/torbrowser")))))
     (home-page "https://www.torproject.org")
     (synopsis "Anonymous browser derived from Mozilla Firefox")
     (description
-- 
2.41.0