~abcdw/rde-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
4 2

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

Details
Message ID
<779d0bb1dece869a7e596a07325564bad3ed1b15.1624004814.git.public@yoctocell.xyz>
DKIM signature
pass
Download raw message
Patch: +138 -1
* 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
	    home-isync-configuration

            home-notmuch-service-type
	    home-notmuch-configuration
            home-notmuch-extension))
            home-notmuch-extension

            home-l2md-service-type
            home-l2md-configuration
            l2md-repo))

(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
  (name
   (string)
   "The name of the public-inbox repository.")
  (urls
   (string-or-list-of-strings)
   "A list of URLs to fetch the public-inbox repository from.")
  (maildir
   (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.")
  (pipe
   (string-or-gexp "")
   "A command to pipe the messages to for further filtering.  This is
mutually exclusive with the @code{maildir} field.")
  (initial-import
   (integer 0)
   "The number of messages to import initially, if @code{0}, import all
the messages.")
  (sync-enabled?
   (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
    (package l2md)
    "The L2md package to use.")
  (period
   (integer 180)
   "The number of seconds between each round of fetching Git
repositories.")
  (maildir
   (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.")
  (pipe
   (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.")
  (base
   (string (string-append (getenv "XDG_DATA_HOME") "/public-inbox"))
   "The directory where L2md stores Git repositories and other
metadata.")
  (repos
   (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 \
`~a'.")
              record))))
  
  (define (l2md-repo->alist repos)
    (match repos
      (($ <l2md-repo> _ name urls maildir pipe initial-import sync-enabled?)
       (begin
         (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)
     (begin
       (check-maildir-and-pipe maildir pipe 'home-l2md-configuration)
       (generic-serialize-git-ini-config
        #:combine-ini (compose flatten list)
        #:combine-alist append
        #:combine-section-alist cons*
        #:serialize-field serialize-field
        #:fields
        `((general
           ((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)
  `(("l2mdconfig"
     ,(apply mixed-text-file
             "l2md-config"
             (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)
                (extensions
                 (list (service-extension
                        home-files-service-type
                        l2md-files-service)
                       (service-extension
                        home-profile-service-type
                        l2md-profile-service)))
                (description "Install and configure L2md.")))

base-commit: 61b9f55e8c28f33492dfe019cac3b4b38a40d996
-- 
2.32.0
Details
Message ID
<875yy73872.fsf@trop.in>
In-Reply-To
<779d0bb1dece869a7e596a07325564bad3ed1b15.1624004814.git.public@yoctocell.xyz> (view parent)
DKIM signature
missing
Download raw message
Xinglu Chen <public@yoctocell.xyz> writes:

> * 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
>  	    home-isync-configuration
>  
>              home-notmuch-service-type
>  	    home-notmuch-configuration
> -            home-notmuch-extension))
> +            home-notmuch-extension
> +
> +            home-l2md-service-type
> +            home-l2md-configuration
> +            l2md-repo))
>  
>  (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
> +  (name
> +   (string)
> +   "The name of the public-inbox repository.")
> +  (urls
> +   (string-or-list-of-strings)
> +   "A list of URLs to fetch the public-inbox repository from.")
> +  (maildir
> +   (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.")
> +  (pipe
> +   (string-or-gexp "")
> +   "A command to pipe the messages to for further filtering.  This is
> +mutually exclusive with the @code{maildir} field.")
> +  (initial-import
> +   (integer 0)
> +   "The number of messages to import initially, if @code{0}, import all
> +the messages.")
> +  (sync-enabled?
> +   (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
> +    (package l2md)
> +    "The L2md package to use.")
> +  (period
> +   (integer 180)
> +   "The number of seconds between each round of fetching Git
> +repositories.")
> +  (maildir
> +   (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.")
> +  (pipe
> +   (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.")
> +  (base
> +   (string (string-append (getenv "XDG_DATA_HOME") "/public-inbox"))
XDG_DATA_HOME is for statitc assets, XDG_STATE_HOME (Guix Home's xdg
extension) is a way to go for state-related entities.

We can't use getenv inside Guix Home client-code, because the value
generated from home-environment definition MUST NOT depend on the
evaluation environment.  It is important on its own, but will become
much more important once we will implement ability to "include"
home-environments into operating-system by using special system service
for that.

The value itself can use environment variables, because it will be
evaluated later, in users environment and it's ok.  It should be
something like "$XDG_STATE_HOME/l2md" or "~/.l2md"
in case software doesn't support env var expansion.
> +   "The directory where L2md stores Git repositories and other
> +metadata.")
> +  (repos
> +   (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)
It's good, but not very necessary to do such strict compile-time checks,
we can help user to generate correct configuration, but it's ok if he
can get incorrect one.
> +    (when (and (string= maildir "") (string= pipe ""))
> +      (raise (formatted-message
> +              (G_ "One of `maildir' or `pipe' must not be an empty string in \
> +`~a'.")
> +              record))))
> +  
> +  (define (l2md-repo->alist repos)
> +    (match repos
> +      (($ <l2md-repo> _ name urls maildir pipe initial-import sync-enabled?)
> +       (begin
> +         (check-maildir-and-pipe maildir pipe 'l2md-repo)
The user can set a global value.
> +         `(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)
> +     (begin
> +       (check-maildir-and-pipe maildir pipe 'home-l2md-configuration)
The user can set per-repo value.
> +       (generic-serialize-git-ini-config
> +        #:combine-ini (compose flatten list)
> +        #:combine-alist append
> +        #:combine-section-alist cons*
> +        #:serialize-field serialize-field
> +        #:fields
> +        `((general
> +           ((period . ,period)
> +            ,@(optional (not (string= maildir "")) `((maildir . ,maildir)))
> +            ,@(optional (not (string= pipe "")) `((pipe . ,pipe)))
It may be better to use maybe-string instead of string and #f as a
default value to make it clear, when the value is not set, it also will
simplify the check: (not maildir).
> +            (base . ,base)))
> +          ,@(map l2md-repo->alist repos)))))))
> +
> +(define (l2md-files-service config)
> +  `(("l2mdconfig"
It would be cool to ask upstream to support XDG_CONFIG_HOME.
> +     ,(apply mixed-text-file
> +             "l2md-config"
> +             (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)
> +                (extensions
> +                 (list (service-extension
> +                        home-files-service-type
> +                        l2md-files-service)
> +                       (service-extension
> +                        home-profile-service-type
> +                        l2md-profile-service)))
What do you think about adding a shepherd service? (With ability to
toggle it and maybe its autostart).
> +                (description "Install and configure L2md.")))
>
> base-commit: 61b9f55e8c28f33492dfe019cac3b4b38a40d996

Thank you for the service, I applied the patch with removed getenv call.
Details
Message ID
<87eecvzhqj.fsf@yoctocell.xyz>
In-Reply-To
<875yy73872.fsf@trop.in> (view parent)
DKIM signature
pass
Download raw message
On Mon, Jun 21 2021, Andrew Tropin wrote:

>> +(define-configuration/no-serialization home-l2md-configuration
>> +  (package
>> +    (package l2md)
>> +    "The L2md package to use.")
>> +  (period
>> +   (integer 180)
>> +   "The number of seconds between each round of fetching Git
>> +repositories.")
>> +  (maildir
>> +   (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.")
>> +  (pipe
>> +   (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.")
>> +  (base
>> +   (string (string-append (getenv "XDG_DATA_HOME") "/public-inbox"))
> XDG_DATA_HOME is for statitc assets, XDG_STATE_HOME (Guix Home's xdg
> extension) is a way to go for state-related entities.
>
> We can't use getenv inside Guix Home client-code, because the value
> generated from home-environment definition MUST NOT depend on the
> evaluation environment.  It is important on its own, but will become
> much more important once we will implement ability to "include"
> home-environments into operating-system by using special system service
> for that.
>
> The value itself can use environment variables, because it will be
> evaluated later, in users environment and it's ok.  It should be
> something like "$XDG_STATE_HOME/l2md" or "~/.l2md"
> in case software doesn't support env var expansion.

Good point, I am not sure if it supports reading environment variables,
but I will look into it.

>> +   "The directory where L2md stores Git repositories and other
>> +metadata.")
>> +  (repos
>> +   (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)
> It's good, but not very necessary to do such strict compile-time checks,
> we can help user to generate correct configuration, but it's ok if he
> can get incorrect one.
>> +    (when (and (string= maildir "") (string= pipe ""))
>> +      (raise (formatted-message
>> +              (G_ "One of `maildir' or `pipe' must not be an empty string in \
>> +`~a'.")
>> +              record))))
>> +  
>> +  (define (l2md-repo->alist repos)
>> +    (match repos
>> +      (($ <l2md-repo> _ name urls maildir pipe initial-import sync-enabled?)
>> +       (begin
>> +         (check-maildir-and-pipe maildir pipe 'l2md-repo)
> The user can set a global value.
>> +         `(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)
>> +     (begin
>> +       (check-maildir-and-pipe maildir pipe 'home-l2md-configuration)
> The user can set per-repo value.

Yeah, good catch, probably no need to include the check.

>> +       (generic-serialize-git-ini-config
>> +        #:combine-ini (compose flatten list)
>> +        #:combine-alist append
>> +        #:combine-section-alist cons*
>> +        #:serialize-field serialize-field
>> +        #:fields
>> +        `((general
>> +           ((period . ,period)
>> +            ,@(optional (not (string= maildir "")) `((maildir . ,maildir)))
>> +            ,@(optional (not (string= pipe "")) `((pipe . ,pipe)))
> It may be better to use maybe-string instead of string and #f as a
> default value to make it clear, when the value is not set, it also will
> simplify the check: (not maildir).

Using ‘maybe-string’ is probably better, but it doesn’t really make the
check much easier, the default value will 'disabled, so I will have to
use ‘eq?’ to check it.

>> +            (base . ,base)))
>> +          ,@(map l2md-repo->alist repos)))))))
>> +
>> +(define (l2md-files-service config)
>> +  `(("l2mdconfig"
> It would be cool to ask upstream to support XDG_CONFIG_HOME.

Yeah, that would be nice.

>> +     ,(apply mixed-text-file
>> +             "l2md-config"
>> +             (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)
>> +                (extensions
>> +                 (list (service-extension
>> +                        home-files-service-type
>> +                        l2md-files-service)
>> +                       (service-extension
>> +                        home-profile-service-type
>> +                        l2md-profile-service)))
> What do you think about adding a shepherd service? (With ability to
> toggle it and maybe its autostart).

That would be a good idea.

>> +                (description "Install and configure L2md.")))
>>
>> base-commit: 61b9f55e8c28f33492dfe019cac3b4b38a40d996
>
> Thank you for the service, I applied the patch with removed getenv call.

You are welcome, thanks for applying!
Details
Message ID
<87czsf70bw.fsf@trop.in>
In-Reply-To
<87eecvzhqj.fsf@yoctocell.xyz> (view parent)
DKIM signature
missing
Download raw message
Xinglu Chen <public@yoctocell.xyz> writes:

> On Mon, Jun 21 2021, Andrew Tropin wrote:
>
>>> +(define-configuration/no-serialization home-l2md-configuration
>>> +  (package
>>> +    (package l2md)
>>> +    "The L2md package to use.")
>>> +  (period
>>> +   (integer 180)
>>> +   "The number of seconds between each round of fetching Git
>>> +repositories.")
>>> +  (maildir
>>> +   (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.")
>>> +  (pipe
>>> +   (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.")
>>> +  (base
>>> +   (string (string-append (getenv "XDG_DATA_HOME") "/public-inbox"))
>> XDG_DATA_HOME is for statitc assets, XDG_STATE_HOME (Guix Home's xdg
>> extension) is a way to go for state-related entities.
>>
>> We can't use getenv inside Guix Home client-code, because the value
>> generated from home-environment definition MUST NOT depend on the
>> evaluation environment.  It is important on its own, but will become
>> much more important once we will implement ability to "include"
>> home-environments into operating-system by using special system service
>> for that.
>>
>> The value itself can use environment variables, because it will be
>> evaluated later, in users environment and it's ok.  It should be
>> something like "$XDG_STATE_HOME/l2md" or "~/.l2md"
>> in case software doesn't support env var expansion.
>
> Good point, I am not sure if it supports reading environment variables,
> but I will look into it.
>
It's is. I checked and updated the value.
>>> +   "The directory where L2md stores Git repositories and other
>>> +metadata.")
>>> +  (repos
>>> +   (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)
>> It's good, but not very necessary to do such strict compile-time checks,
>> we can help user to generate correct configuration, but it's ok if he
>> can get incorrect one.
>>> +    (when (and (string= maildir "") (string= pipe ""))
>>> +      (raise (formatted-message
>>> +              (G_ "One of `maildir' or `pipe' must not be an empty string in \
>>> +`~a'.")
>>> +              record))))
>>> +  
>>> +  (define (l2md-repo->alist repos)
>>> +    (match repos
>>> +      (($ <l2md-repo> _ name urls maildir pipe initial-import sync-enabled?)
>>> +       (begin
>>> +         (check-maildir-and-pipe maildir pipe 'l2md-repo)
>> The user can set a global value.
>>> +         `(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)
>>> +     (begin
>>> +       (check-maildir-and-pipe maildir pipe 'home-l2md-configuration)
>> The user can set per-repo value.
>
> Yeah, good catch, probably no need to include the check.
>
>>> +       (generic-serialize-git-ini-config
>>> +        #:combine-ini (compose flatten list)
>>> +        #:combine-alist append
>>> +        #:combine-section-alist cons*
>>> +        #:serialize-field serialize-field
>>> +        #:fields
>>> +        `((general
>>> +           ((period . ,period)
>>> +            ,@(optional (not (string= maildir "")) `((maildir . ,maildir)))
>>> +            ,@(optional (not (string= pipe "")) `((pipe . ,pipe)))
>> It may be better to use maybe-string instead of string and #f as a
>> default value to make it clear, when the value is not set, it also will
>> simplify the check: (not maildir).
>
> Using ‘maybe-string’ is probably better, but it doesn’t really make the
> check much easier, the default value will 'disabled, so I will have to
> use ‘eq?’ to check it.
>
By maybe-string I mean (or (string? x) (not x)), not maybe-string from
configuration module. The default value will be #f.
>>> +            (base . ,base)))
>>> +          ,@(map l2md-repo->alist repos)))))))
>>> +
>>> +(define (l2md-files-service config)
>>> +  `(("l2mdconfig"
>> It would be cool to ask upstream to support XDG_CONFIG_HOME.
>
> Yeah, that would be nice.
>
>>> +     ,(apply mixed-text-file
>>> +             "l2md-config"
>>> +             (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)
>>> +                (extensions
>>> +                 (list (service-extension
>>> +                        home-files-service-type
>>> +                        l2md-files-service)
>>> +                       (service-extension
>>> +                        home-profile-service-type
>>> +                        l2md-profile-service)))
>> What do you think about adding a shepherd service? (With ability to
>> toggle it and maybe its autostart).
>
> That would be a good idea.
>
>>> +                (description "Install and configure L2md.")))
>>>
>>> base-commit: 61b9f55e8c28f33492dfe019cac3b4b38a40d996
>>
>> Thank you for the service, I applied the patch with removed getenv call.
>
> You are welcome, thanks for applying!
Sure ;)
Details
Message ID
<87mtris4i4.fsf@yoctocell.xyz>
In-Reply-To
<87czsf70bw.fsf@trop.in> (view parent)
DKIM signature
pass
Download raw message
On Mon, Jun 21 2021, Andrew Tropin wrote:

> Xinglu Chen <public@yoctocell.xyz> writes:
>
>> On Mon, Jun 21 2021, Andrew Tropin wrote:
>>
>>>> +(define-configuration/no-serialization home-l2md-configuration
>>>> +  (package
>>>> +    (package l2md)
>>>> +    "The L2md package to use.")
>>>> +  (period
>>>> +   (integer 180)
>>>> +   "The number of seconds between each round of fetching Git
>>>> +repositories.")
>>>> +  (maildir
>>>> +   (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.")
>>>> +  (pipe
>>>> +   (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.")
>>>> +  (base
>>>> +   (string (string-append (getenv "XDG_DATA_HOME") "/public-inbox"))
>>> XDG_DATA_HOME is for statitc assets, XDG_STATE_HOME (Guix Home's xdg
>>> extension) is a way to go for state-related entities.
>>>
>>> We can't use getenv inside Guix Home client-code, because the value
>>> generated from home-environment definition MUST NOT depend on the
>>> evaluation environment.  It is important on its own, but will become
>>> much more important once we will implement ability to "include"
>>> home-environments into operating-system by using special system service
>>> for that.
>>>
>>> The value itself can use environment variables, because it will be
>>> evaluated later, in users environment and it's ok.  It should be
>>> something like "$XDG_STATE_HOME/l2md" or "~/.l2md"
>>> in case software doesn't support env var expansion.
>>
>> Good point, I am not sure if it supports reading environment variables,
>> but I will look into it.
>>
>
> It's is. I checked and updated the value.

OK, great!

>>>> +   "The directory where L2md stores Git repositories and other
>>>> +metadata.")
>>>> +  (repos
>>>> +   (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)
>>> It's good, but not very necessary to do such strict compile-time checks,
>>> we can help user to generate correct configuration, but it's ok if he
>>> can get incorrect one.
>>>> +    (when (and (string= maildir "") (string= pipe ""))
>>>> +      (raise (formatted-message
>>>> +              (G_ "One of `maildir' or `pipe' must not be an empty string in \
>>>> +`~a'.")
>>>> +              record))))
>>>> +  
>>>> +  (define (l2md-repo->alist repos)
>>>> +    (match repos
>>>> +      (($ <l2md-repo> _ name urls maildir pipe initial-import sync-enabled?)
>>>> +       (begin
>>>> +         (check-maildir-and-pipe maildir pipe 'l2md-repo)
>>> The user can set a global value.
>>>> +         `(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)
>>>> +     (begin
>>>> +       (check-maildir-and-pipe maildir pipe 'home-l2md-configuration)
>>> The user can set per-repo value.
>>
>> Yeah, good catch, probably no need to include the check.
>>
>>>> +       (generic-serialize-git-ini-config
>>>> +        #:combine-ini (compose flatten list)
>>>> +        #:combine-alist append
>>>> +        #:combine-section-alist cons*
>>>> +        #:serialize-field serialize-field
>>>> +        #:fields
>>>> +        `((general
>>>> +           ((period . ,period)
>>>> +            ,@(optional (not (string= maildir "")) `((maildir . ,maildir)))
>>>> +            ,@(optional (not (string= pipe "")) `((pipe . ,pipe)))
>>> It may be better to use maybe-string instead of string and #f as a
>>> default value to make it clear, when the value is not set, it also will
>>> simplify the check: (not maildir).
>>
>> Using ‘maybe-string’ is probably better, but it doesn’t really make the
>> check much easier, the default value will 'disabled, so I will have to
>> use ‘eq?’ to check it.
>>
> By maybe-string I mean (or (string? x) (not x)), not maybe-string from
> configuration module. The default value will be #f.

The point of ‘maybe-string’ is to make the field optional, which is what
we want in this case.  While using #f as the default value does make the
check slightly simplier, I think it’s better to keep things consistent
for the user.
Reply to thread Export thread (mbox)