~abcdw/rde-devel

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
            icecat-configuration
            icecat-profile))

;;; 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
  (default?
    (boolean #f)
    "Whether or not this is the default profile for IceCat.")
  (name
   (string)
   "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
@code{icecat-profile}.")
  (id
   (integer)
   "The profile id assigned to this profile.  This has to be unique to
each @code{icecat-profile}.")
  (settings
   (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.")
  (user-chrome
   (string "")
   "Custom user chrome CSS.  See @uref{https://www.userchrome.org/} for
details on how to customize the look and feel of IceCat.")
  (user-content
   (string "")
   "Custom user content CSS.")
  (no-serialization))

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

(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))
      (cond
       ((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)
        #t
        (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")))
         (filter
          (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))
                       (list
                        (format #f "~a/~a/user.js"
                                %icecat-config-path profile-path)
                        (mixed-text-file
                         (string-append file-name "-settings")
                         (serialize-settings settings))))
            ,(optional (not (string=? user-chrome ""))
                       (list
                        (format #f "~a/~a/chrome/userChrome.css"
                                %icecat-config-path profile-path)
                        (mixed-text-file
                         (string-append file-name "-user-chrome")
                         user-chrome)))
            ,(optional (not (string=? user-content ""))
                       (list
                        (format #f "~a/~a/chrome/userContent.css"
                                %icecat-config-path profile-path)
                        (mixed-text-file
                         (string-append file-name "-user-content")
                         user-content)))))))))

  (match config
    (($ <icecat-configuration> location package profiles)
     (begin
       (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)
            ,(mixed-text-file
              "icecat-profile-ini"
              (generic-serialize-ini-config
               #:serialize-field serialize-field
               #:fields profile-ini)))
           ,@(flatten (map rest configs))))))))

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

base-commit: ee8140d920f15aa68434b10617379d3a3bafd3e1
-- 
2.31.1