gnu: home-services: web-browsers: Add IceCat service. v1 APPLIED

Xinglu Chen: 1
 gnu: home-services: web-browsers: Add IceCat service.

 1 files changed, 193 insertions(+), 0 deletions(-)
> I will add some additional fixes. :)
Saw your changes, good job!)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~abcdw/rde-devel/patches/22626/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] gnu: home-services: web-browsers: Add IceCat service. Export this patch

* gnu/home-services/web-browsers.scm: New file.
IceCat belongs to the (gnu packages gnuzilla) module, but I think it
makes more sense to put all the web browsers in the same module.
 gnu/home-services/web-browsers.scm | 193 +++++++++++++++++++++++++++++
 1 file changed, 193 insertions(+)
 create mode 100644 gnu/home-services/web-browsers.scm

diff --git a/gnu/home-services/web-browsers.scm b/gnu/home-services/web-browsers.scm
new file mode 100644
index 0000000..08a7417
--- /dev/null
+++ b/gnu/home-services/web-browsers.scm
@@ -0,0 +1,193 @@
(define-module (gnu home-services web-browsers)
  #:use-module (gnu home-services)
  #:use-module (gnu home-services-utils)
  #:use-module (gnu home-services files)
  #:use-module (gnu services configuration)
  #:use-module (gnu packages gnuzilla)
  #:use-module (guix packages)
  #:use-module (guix gexp)
  #:use-module (guix diagnostics)
  #:use-module (guix i18n)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-1)

  #:export (home-icecat-service-type

;;; Commentary:
;;; Web browser related services.
;;; Code:

;;; IceCat.
;;; (icecat-configuration
;;;    (profiles
;;;     (list (icecat-profile
;;;            (default? #t)
;;;            (name "default")
;;;            (id 0)
;;;            (settings '((browser.urlbar.shortcuts.history . #t)
;;;                        (browser.fullscreen.autohide . #t)))
;;;            (user-chrome "\
;;; #TabsToolbar { visibility: collapse !important; }")
;;;            (user-content "\
;;; :root{ scrollbar-width: none !important; }"))
;;;           (icecat-profile
;;;            (default? #f)
;;;            (name "github")
;;;            (id 1)
;;;            (settings '((browser.urlbar.shortcuts.bookmarks . #f)
;;;                        (browser.fullscreen.autohide . #t)))))))

(define %icecat-config-path "mozilla/icecat")
(define (listof-icecat-profile? val)
  (listof icecat-profile?))

(define-configuration icecat-profile
    (boolean #f)
    "Whether or not this is the default profile for IceCat.")
   "The name of this IceCat profile.  This name will show up in the
@uref{about:profiles} page, and it has to be unique for each
   "The profile id assigned to this profile.  This has to be unique to
each @code{icecat-profile}.")
   (alist '())
   "An association list of options to set in this profile.  These are
options you can see in the @uref{about:config} page.  The key of the
pair can be a string or a symbol, and the value can be a string,
symbol, boolean, or number.")
   (string "")
   "Custom user chrome CSS.  See @uref{https://www.userchrome.org/} for
details on how to customize the look and feel of IceCat.")
   (string "")
   "Custom user content CSS.")

;; TODO: Extensions.
(define-configuration icecat-configuration
    (package icecat)
    "The IceCat package to use.")
   (listof-icecat-profile '())
   "List of IceCat profiles.")

(define (icecat-profile-service config)
  (list (icecat-configuration-package config)))

(define (icecat-files-service config)
  (define (serialize-field key val)
    (let ((val (cond
                ((boolean? val) => boolean->true-or-false)
                (else val))))
      (format #f "user_pref(\"~a\", ~a);\n" key val)))

  (define (serialize-settings settings)
    (generic-serialize-alist string-append serialize-field settings))

  (define (check-duplicate-field field-name fields)
    (let loop ((acc '())
               (fields fields))
       ((null? fields) #t)
       (else (let ((head (first fields)))
               (if (member head acc)
                   (raise (formatted-message
                           (G_ "`icecat-configuration' cannot contain \
`icecat-profile's with duplicate ~as: `~a'")
                           field-name head))
                   (loop (cons head acc) (rest fields))))))))

  (define (check-only-one-default defaults)
    (if (= (length (filter identity defaults)) 1)
        (raise (formatted-message
                (G_ "Only one `icecat-profile' in `icecat-configuration' can \
be the default profile.")))))

  ;; Return a list where the first element is a list of alists
  ;; representing the content of profiles.ini, and the rest of the
  ;; elements is a containing the content of the config files
  ;; (user.js, userChrome.css, userContent.css)
  (define (serialize-profiles profiles)
    (match profiles
      (($ <icecat-profile> location default? name id
                           settings user-chrome user-content)
       (let ((profile-path (if default? "default" name))
             (file-name (string-append "icecat-" name "-profile")))
          (compose not null?)
          `(((,(format #f "Profile~a" id)
              ((default . ,(if default? 1 0))
               (is-relative . 1)
               (name . ,(string-capitalize name))
               (path . ,profile-path))))
            ,(optional (not (null? settings))
                        (format #f "~a/~a/user.js"
                                %icecat-config-path profile-path)
                         (string-append file-name "-settings")
                         (serialize-settings settings))))
            ,(optional (not (string=? user-chrome ""))
                        (format #f "~a/~a/chrome/userChrome.css"
                                %icecat-config-path profile-path)
                         (string-append file-name "-user-chrome")
            ,(optional (not (string=? user-content ""))
                        (format #f "~a/~a/chrome/userContent.css"
                                %icecat-config-path profile-path)
                         (string-append file-name "-user-content")

  (match config
    (($ <icecat-configuration> location package profiles)
       (check-only-one-default (map icecat-profile-default? profiles))
       (check-duplicate-field "name" (map icecat-profile-name profiles))
       (check-duplicate-field "id" (map icecat-profile-id profiles))
       (let* ((configs (map serialize-profiles profiles))
              (profile-ini (append '((General
                                      ((start-with-last-profile . 1))))
                                   (append-map first configs))))
         (define (serialize-field key val)
           (let ((val (cond
                       ((boolean? val) (if val 1 0))
                       (else val))))
             (format #f "~a=~a\n" (object->camel-case-string key 'upper) val)))
         `((,(format #f "~a/profiles.ini" %icecat-config-path)
               #:serialize-field serialize-field
               #:fields profile-ini)))
           ,@(flatten (map rest configs))))))))

(define home-icecat-service-type
  (service-type (name 'home-icecat)
                 (list (service-extension

base-commit: ee8140d920f15aa68434b10617379d3a3bafd3e1