all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Carlo Zancanaro <carlo@zancanaro.id.au>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel <guix-devel@gnu.org>
Subject: Re: Services can now have a default value
Date: Sat, 13 May 2017 20:39:37 +1000	[thread overview]
Message-ID: <87bmqx6nx2.fsf@zancanaro.id.au> (raw)
In-Reply-To: <8737d1nxbd.fsf@zancanaro.id.au>


[-- Attachment #1.1: Type: text/plain, Size: 982 bytes --]


On Fri, Apr 21 2017, Carlo Zancanaro wrote:
> I'll have a go at it later today and see what I can come up with. (I'm
> not very familiar with guile/scheme libraries, but I have played around
> a fair bit with macros.)

Well, it's been a lot longer than "later today", but better late than
never, I guess!

I've attached two patches, one of which is the definition of
define-service-type, and the other which is me changing the
exim-service-type definition to use it.

I made a decision to not try to generate a define-configuration form,
and instead just generate an "old-style" define-record-type for the
configuration. That's mostly just because I don't know how to write
something that works with define-configuration and it felt more
complicated to me. If someone else wants to do that (or help me to
understand it) I'd be supportive.

I'm not really promoting this as something that should be merged at the
moment, but I'm mostly just offering it as food for thought.

Carlo


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-services-Add-define-service-type.patch --]
[-- Type: text/x-diff, Size: 2446 bytes --]

From da085158b30ae983cdaaf172ba2fb97b40d3207d Mon Sep 17 00:00:00 2001
From: Carlo Zancanaro <carlo@zancanaro.id.au>
Date: Sat, 13 May 2017 20:20:27 +1000
Subject: [PATCH 1/2] services: Add `define-service-type`.

* gnu/services.scm (id, define-service-type): New macros.
---
 gnu/services.scm | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/gnu/services.scm b/gnu/services.scm
index 5c314748d..837e75568 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -50,6 +50,8 @@
             service-type-extend
             service-type-default-value
 
+            define-service-type
+
             service
             service?
             service-kind
@@ -154,6 +156,37 @@
 
 (set-record-type-printer! <service-type> write-service-type)
 
+(define-syntax-rule (id ctx parts ...)
+  "Assemble PARTS into a raw (unhygienic)  identifier."
+  (datum->syntax ctx (symbol-append (if (symbol? parts)
+                                        parts
+                                        (syntax->datum parts)) ...)))
+
+(define-syntax define-service-type
+  (lambda (stx)
+    (syntax-case stx (extensions configuration)
+      ((define-service-type service-name
+         (extensions exts ...)
+         (configuration (fields tail ...) ...))
+       (with-syntax (((field-accessors ...)
+                      (map (lambda (field)
+                             (id #'stx #'service-name '-configuration- field))
+                           #'(fields ...))))
+         #`(begin
+             (define #,(id #'stx #'service-name '-service-type)
+               (service-type
+                (name 'service-name)
+                (extensions exts ...)))
+             (define-record-type* #,(id #'stx '< #'service-name '-configuration>)
+               #,(id #'stx #'service-name '-configuration)
+               #,(id #'stx 'make- #'service-name '-configuration)
+               #,(id #'stx #'service-name '-configuration?)
+               (fields field-accessors tail ...) ...)
+             (define-syntax-rule (#,(id #'stx #'service-name '-service) config (... ...))
+               (service
+                #,(id #'stx #'service-name '-service-type)
+                (#,(id #'stx #'service-name '-configuration) config (... ...))))))))))
+
 ;; Services of a given type.
 (define-record-type <service>
   (make-service type value)
-- 
2.12.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.3: 0002-services-Change-exim-service-type-to-use-define-serv.patch --]
[-- Type: text/x-diff, Size: 2435 bytes --]

From 69c471d4ebe6a24fe11e6488f93616a7afb4467a Mon Sep 17 00:00:00 2001
From: Carlo Zancanaro <carlo@zancanaro.id.au>
Date: Sat, 13 May 2017 20:27:15 +1000
Subject: [PATCH 2/2] services: Change exim-service-type to use
 define-service-type.

* gnu/services/mail.scm: Refactor code to use define-service-type.
---
 gnu/services/mail.scm | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/gnu/services/mail.scm b/gnu/services/mail.scm
index 6305f06f8..ebc7e3d9e 100644
--- a/gnu/services/mail.scm
+++ b/gnu/services/mail.scm
@@ -1693,14 +1693,6 @@ accept from local for any relay
 ;;; Exim.
 ;;;
 
-(define-record-type* <exim-configuration> exim-configuration
-  make-exim-configuration
-  exim-configuration?
-  (package       exim-configuration-package ;<package>
-                 (default exim))
-  (config-file   exim-configuration-config-file ;file-like
-                 (default #f)))
-
 (define %exim-accounts
   (list (user-group
          (name "exim")
@@ -1752,15 +1744,16 @@ exim_group = exim
            (zero? (system* #$(file-append package "/bin/exim")
                            "-bV" "-C" #$(exim-computed-config-file package config-file))))))))
 
-(define exim-profile
-  (compose list exim-configuration-package))
-
-(define exim-service-type
-  (service-type
-   (name 'exim)
-   (extensions
-    (list (service-extension shepherd-root-service-type exim-shepherd-service)
-          (service-extension account-service-type (const %exim-accounts))
-          (service-extension activation-service-type exim-activation)
-          (service-extension profile-service-type exim-profile)
-          (service-extension mail-aliases-service-type (const '()))))))
+(define (exim-profile config)
+  (call-with-values (lambda () (exim-configuration-package config)) list))
+
+(define-service-type exim
+  (extensions (list
+               (service-extension shepherd-root-service-type exim-shepherd-service)
+               (service-extension account-service-type (const %exim-accounts))
+               (service-extension activation-service-type exim-activation)
+               (service-extension profile-service-type exim-profile)
+               (service-extension mail-aliases-service-type (const '()))))
+  (configuration
+   (package       (default exim))
+   (config-file   (default #f))))
-- 
2.12.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

  parent reply	other threads:[~2017-05-13 10:39 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-15 22:51 Services can now have a default value Ludovic Courtès
2017-04-15 23:11 ` ng0
2017-04-17 11:56   ` Ricardo Wurmus
2017-04-19 23:22     ` ng0
2017-04-20  8:53       ` Ricardo Wurmus
2017-04-20  9:09         ` ng0
2017-04-23 10:23           ` Ricardo Wurmus
2017-04-17 11:58 ` Ricardo Wurmus
2017-04-19 14:42 ` Carlo Zancanaro
2017-04-19 15:18   ` ng0
2017-04-19 21:20   ` Ludovic Courtès
     [not found]     ` <8737d32abz.fsf@zancanaro.id.au>
2017-04-20  8:42       ` Ludovic Courtès
2017-04-20 10:19         ` Carlo Zancanaro
2017-04-21 22:04           ` Ludovic Courtès
2017-04-21 23:41             ` Carlo Zancanaro
2017-04-22  0:46               ` We need an RFC procedure [Re: Services can now have a default value] ng0
2017-04-22  7:12                 ` Ricardo Wurmus
2017-04-22 10:08                   ` ng0
2017-04-22 22:55                     ` Ludovic Courtès
2017-04-23 10:13                       ` Ricardo Wurmus
2017-04-23 12:02                         ` ng0
2017-04-27 13:29                         ` Ludovic Courtès
2017-04-27 16:37                           ` Petter
2017-05-02 12:42                             ` Ludovic Courtès
2017-05-22 21:23                               ` Ricardo Wurmus
2017-05-22 22:45                                 ` Leo Famulari
2017-04-23 11:52                       ` ng0
2017-05-13 10:39               ` Carlo Zancanaro [this message]
2017-05-13 22:53                 ` Services can now have a default value Carlo Zancanaro
2017-05-15 12:48                   ` Ludovic Courtès
2017-04-22 14:46             ` Christopher Allan Webber
2017-04-22 14:59               ` Jan Nieuwenhuizen
2017-04-22 22:57               ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bmqx6nx2.fsf@zancanaro.id.au \
    --to=carlo@zancanaro.id.au \
    --cc=guix-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.