gnu: home-services: mail: Add L2md service. v1 APPLIED

Xinglu Chen: 1
 gnu: home-services: mail: Add L2md service.

 1 files changed, 138 insertions(+), 1 deletions(-)
Xinglu Chen <public@yoctocell.xyz> writes:
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/23372/mbox | git am -3
Learn more about email & git

[PATCH] gnu: home-services: mail: Add L2md service. Export this patch

* gnu/home-services/mail.scm: (string-or-list-of-strings?,
list-of-l2md-repos): New procedures.
(<l2md-repo>, <home-l2md-configuration>): New record types.
(serialize-l2md-configuration, l2md-files-service,
l2md-profile-service): New procedures.
(home-l2md-service-type): New service type.
 gnu/home-services/mail.scm | 139 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 138 insertions(+), 1 deletion(-)

diff --git a/gnu/home-services/mail.scm b/gnu/home-services/mail.scm
index a9bbf93..1c7afed 100644
--- a/gnu/home-services/mail.scm
+++ b/gnu/home-services/mail.scm
@@ -11,12 +11,20 @@

  #:use-module (guix packages)
  #:use-module (guix gexp)
  #:use-module (guix diagnostics)
  #:use-module (guix i18n)
  #:use-module ((guix import utils) #:select (flatten))

  #:export (home-isync-service-type



(define (serialize-isync-config field-name val)
  (define (serialize-term term)
@@ -201,3 +209,132 @@ notmuch-hooks} for more information."))
		(extend home-notmuch-extensions)
                (default-value (home-notmuch-configuration))
                (description "Install and configure notmuch.")))

;;; L2md.

(define (string-or-list-of-strings? val)
  (or (string? val) (listof-strings? val)))

(define-configuration/no-serialization l2md-repo
   "The name of the public-inbox repository.")
   "A list of URLs to fetch the public-inbox repository from.")
   (string "")
   "The maildir corresponding to the public-inbox repository.  This is
optional, an external MDA like Procmail can be used instead to filter
the messages, see the @code{pipe} field.")
   (string-or-gexp "")
   "A command to pipe the messages to for further filtering.  This is
mutually exclusive with the @code{maildir} field.")
   (integer 0)
   "The number of messages to import initially, if @code{0}, import all
the messages.")
   (boolean #t)
   "Whether to sync this repository or not."))

(define list-of-l2md-repos? (listof l2md-repo?))

(define-configuration/no-serialization home-l2md-configuration
    (package l2md)
    "The L2md package to use.")
   (integer 180)
   "The number of seconds between each round of fetching Git
   (string "")
   "The maildir to which messages should be delivered.  This can also be
set on a per-list basis using the using the @code{maildir} field in
the @code{<l2md-repo>} record.")
   (string-or-gexp "")
   "A command to pipe the messages to for further filtering.  This is
mutually exclusive with the @code{maildir} field.  This can also be
set on a per-list basis using the @code{<l2md-repo>} record.")
   (string (string-append (getenv "XDG_DATA_HOME") "/public-inbox"))
   "The directory where L2md stores Git repositories and other
   (list-of-l2md-repos '())
   "List of @code{l2md-repo} records, representing the configuration for
a particular public-inbox repository."))

(define (serialize-l2md-configuration config)
  (define (serialize-field field-name val)
    (let ((val (cond
                ((boolean? val) (if val "1" "0"))
                (else (maybe-object->string val)))))
      (if (string= val "")
          (list "\t" (object->snake-case-string field-name) " = " val "\n"))))

  (define (check-maildir-and-pipe maildir pipe record)
    (when (and (string= maildir "") (string= pipe ""))
      (raise (formatted-message
              (G_ "One of `maildir' or `pipe' must not be an empty string in \
  (define (l2md-repo->alist repos)
    (match repos
      (($ <l2md-repo> _ name urls maildir pipe initial-import sync-enabled?)
         (check-maildir-and-pipe maildir pipe 'l2md-repo)
         `(repo ,name
                (,@(map (lambda (url)
                          `(url . ,url))
                        (maybe-list urls))
                 (maildir . ,maildir)
                 (pipe . ,pipe)
                 (initial-import . ,initial-import)
                 (sync-enabled . ,sync-enabled?)))))))

  (match config
    (($ <home-l2md-configuration> _ package period maildir pipe base repos)
       (check-maildir-and-pipe maildir pipe 'home-l2md-configuration)
        #:combine-ini (compose flatten list)
        #:combine-alist append
        #:combine-section-alist cons*
        #:serialize-field serialize-field
           ((period . ,period)
            ,@(optional (not (string= maildir "")) `((maildir . ,maildir)))
            ,@(optional (not (string= pipe "")) `((pipe . ,pipe)))
            (base . ,base)))
          ,@(map l2md-repo->alist repos)))))))

(define (l2md-files-service config)
     ,(apply mixed-text-file
             (serialize-l2md-configuration config)))))

(define (l2md-profile-service config)
  (list (home-l2md-configuration-package config)))

(define home-l2md-service-type
  (service-type (name 'home-l2md)
                 (list (service-extension
                (description "Install and configure L2md.")))

base-commit: 61b9f55e8c28f33492dfe019cac3b4b38a40d996
Xinglu Chen <public@yoctocell.xyz> writes: