Subject: bug#32026: [PATCH v3 07/11] gnu: Add language packs to icecat and icedove.

From: Maxim Cournoyer <[email-masked]>
Date: Fri, 17 Feb 2023 07:55:34 -0500

Fixes <https://issues.guix.gnu.org/32026>.

* gnu/packages/gnuzilla.scm (icecat): Rename to...
(icecat-minimal): ... this.
(icedove: Rename to...
(icedove-minimal): ... this.
(make-mozilla-with-l10n): New procedure.
(icecat, icedove): New variables.

---

Changes in v3:
- Make make-l10n-package more functional, taking inputs as arguments
- Validate the PROJECT argument in make-l10n-package

Changes in v2:
- Do not clear native-inputs and inputs in make-mozilla-with-l10n, for 'guix
shell -D icecat'

 gnu/packages/gnuzilla.scm | 133 ++++++++++++++++++++++++++++----------
 1 file changed, 100 insertions(+), 33 deletions(-)

diff --git a/gnu/packages/gnuzilla.scm b/gnu/packages/gnuzilla.scm
index 3ece3f057c..02493b9aff 100644
--- a/gnu/packages/gnuzilla.scm
+++ b/gnu/packages/gnuzilla.scm
@@ -679,9 +679,9 @@ (define icecat-source
                         "--sort=name"
                         icecat-dir)))))))))
 
-(define-public icecat
+(define-public icecat-minimal
   (package
-    (name "icecat")
+    (name "icecat-minimal")
     (version %icecat-version)
     (source icecat-source)
     (build-system gnu-build-system)
@@ -1303,9 +1303,9 @@ (define icedove-source
                        "--sort=name"
                        #$name))))))))
 
-(define-public icedove
+(define-public icedove-minimal
   (package
-    (name "icedove")
+    (name "icedove-minimal")
     (version %icedove-version)
     (source icedove-source)
     (properties
@@ -1555,35 +1555,6 @@ (define-public icedove
 Thunderbird.  It supports email, news feeds, chat, calendar and contacts.")
     (license license:mpl2.0)))
 
-(define-public icedove/wayland
-  (package
-    (inherit icedove)
-    (name "icedove-wayland")
-    (build-system trivial-build-system)
-    (arguments
-     (list
-      #:modules '((guix build utils))
-      #:builder
-      #~(begin
-          (use-modules (guix build utils))
-          (let* ((exe (string-append #$output "/bin/icedove")))
-            (mkdir-p (dirname exe))
-            (call-with-output-file exe
-              (lambda (port)
-                (format port "#!~a
- MOZ_ENABLE_WAYLAND=1 exec ~a $@"
-                        #$(file-append bash-minimal "/bin/bash")
-                        #$(file-append icedove "/bin/icedove"))))
-            (chmod exe #o555)
-            ;; Provide the manual and .desktop file.
-            (copy-recursively (string-append #$icedove "/share")
-                              (string-append #$output "/share"))
-            (substitute* (string-append #$output
-                                        "/share/applications/icedove.desktop")
-              ((#$icedove) #$output))))))
-    (native-inputs '())
-    (inputs '())))
-
 (define (make-l10n-package project version source locales)
   "Return a package for PROJECT, a symbol (either icecat or icedove), with
 their corresponding VERSION, SOURCE and LOCALES variables."
@@ -1706,6 +1677,102 @@ (define-public icecat-l10n
 (define-public icedove-l10n
   (make-l10n-package 'icedove %icedove-version icedove-source %icedove-locales))
 
+;;; This hack exists because there's no way to configure extra extension
+;;; search paths for IceCat or Icedove.  The global extensions directory is
+;;; constructed relatively to the executable file name.
+(define (make-mozilla-with-l10n project base l10n-package)
+  "Return a package definition for PROJECT (a symbol such as 'icecat or
+'icedove) that combines the BASE package with L10N-PACKAGE."
+
+  (unless (member project '(icecat icedove))
+    (error "only icecat or icedove components are currently supported"))
+
+  (let ((name (symbol->string project))
+        (icecat? (eq? 'icecat project)))
+    (package
+      (inherit base)
+      (name (symbol->string project))
+      (build-system trivial-build-system)
+      (arguments
+       (list
+        #:modules '((guix build union)
+                    (guix build utils))
+        #:builder
+        #~(begin
+            (use-modules (guix build union)
+                         (guix build utils))
+
+            (union-build #$output (list #$base #$l10n-package)
+                         #:create-all-directories? #t)
+
+            (define* (expose name #:optional (proc copy-file)
+                             #:key (source #$base))
+              (let ((dest (string-append #$output "/" name)))
+                (mkdir-p (dirname dest))
+                (proc (string-append source "/" name) dest)))
+
+            (let ((wrapper (string-append "lib/" #$name "/" #$name))
+                  (real-binary (string-append "lib/" #$name "/." #$name
+                                              "-real"))
+                  (desktop-file (string-append "share/applications/"
+                                               #$name ".desktop")))
+              ;; Copy wrapper file.
+              (delete-file (string-append #$output "/" wrapper))
+              (expose wrapper)
+
+              ;; Recreate bin symlink.
+              (delete-file (string-append #$output "/bin/" #$name))
+              (symlink (string-append #$output "/" wrapper)
+                       (string-append #$output "/bin/" #$name))
+
+              ;; Copy actual binary.
+              (delete-file (string-append #$output "/" real-binary))
+              (expose real-binary)
+
+              ;; Copy desktop file.
+              (delete-file (string-append #$output "/" desktop-file))
+              (expose desktop-file)
+
+              ;; Adjust the references in the desktop file and wrapper.
+              (substitute* (list (string-append #$output "/" desktop-file)
+                                 (string-append #$output "/" wrapper))
+                ((#$base) #$output)))))))))
+
+(define-public icecat
+  (make-mozilla-with-l10n 'icecat icecat-minimal icecat-l10n))
+
+(define-public icedove
+  (make-mozilla-with-l10n 'icedove icedove-minimal icedove-l10n))
+
+(define-public icedove/wayland
+  (package
+    (inherit icedove)
+    (name "icedove-wayland")
+    (build-system trivial-build-system)
+    (arguments
+     (list
+      #:modules '((guix build utils))
+      #:builder
+      #~(begin
+          (use-modules (guix build utils))
+          (let* ((exe (string-append #$output "/bin/icedove")))
+            (mkdir-p (dirname exe))
+            (call-with-output-file exe
+              (lambda (port)
+                (format port "#!~a
+ MOZ_ENABLE_WAYLAND=1 exec ~a $@"
+                        #$(file-append bash-minimal "/bin/bash")
+                        #$(file-append icedove "/bin/icedove"))))
+            (chmod exe #o555)
+            ;; Provide the manual and .desktop file.
+            (copy-recursively (string-append #$icedove "/share")
+                              (string-append #$output "/share"))
+            (substitute* (string-append #$output
+                                        "/share/applications/icedove.desktop")
+              ((#$icedove) #$output))))))
+    (native-inputs '())
+    (inputs '())))
+
 (define-public firefox-decrypt
   (package
     (name "firefox-decrypt")
-- 
2.39.1