projects/guix·blob javascript-team · refs

71 lines · 3.2 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2020, 2021 Marius Bakke <[email protected]>
3;;; Copyright © 2023 Clément Lassieur <[email protected]>
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (gnu build icecat-extension)
21 #:use-module (guix gexp)
22 #:use-module (guix packages)
23 #:use-module (guix build-system trivial)
24 #:export (make-icecat-extension))
25
26(define* (make-icecat-extension pkg #:optional (pkg-output "out"))
27 "Create an Icecat extension from package PKG and return a package that,
28when installed, will make the extension contained in PKG available as an
29Icecat browser extension. PKG-OUTPUT specifies which output of PKG to use."
30 (package
31 (inherit pkg)
32 (location (package-location pkg))
33 (name (string-append (package-name pkg) "-icecat"))
34 (native-inputs '())
35 (inputs '())
36 (propagated-inputs (package-propagated-inputs pkg))
37 (outputs '("out"))
38 (build-system trivial-build-system)
39 (arguments
40 (list
41 #:modules '((guix build utils))
42 #:builder
43 #~(begin
44 (use-modules (guix build utils))
45 (let* ((addon-id #$(assq-ref (package-properties pkg) 'addon-id))
46 (moz-app-id "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}")
47 (search-dir (string-append #$output "/lib/icecat/extensions/"
48 moz-app-id)))
49 ;; Icecat's iterates over `search-dir` for directories. If a
50 ;; directory's name is not a valid add-on ID, it is ignored. See
51 ;; `DirectoryLocation::readAddons()` in XPIProvider.jsm.
52
53 ;; This directory has to be a symlink, because Icecat's
54 ;; `_readLinkFile(aFile)` calls `normalize()` only if `aFile` is a
55 ;; symlink.
56
57 ;; Normalizing is required because Icecat compares the add-on path
58 ;; against its local database to know if there is an extension
59 ;; update. We want the add-on path to be the package store path,
60 ;; so that a path change is detected every time the package is
61 ;; updated. See `updateExistingAddon()` in XPIDatabase.jsm, with
62 ;; our patch `icecat-compare-paths.patch`.
63
64 ;; We don't want the add-on path to be the profile store path,
65 ;; which would change too often. We don't want the add-on path to
66 ;; be hard-coded either because it would never change (but it
67 ;; wouldn't make sense anyway).
68
69 (mkdir-p search-dir)
70 (symlink (in-vicinity (ungexp pkg pkg-output) addon-id)
71 (in-vicinity search-dir addon-id))))))))