guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Services can now have a default value


From: Carlo Zancanaro
Subject: Re: Services can now have a default value
Date: Sat, 13 May 2017 20:39:37 +1000
User-agent: mu4e 0.9.18; emacs 25.1.1

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

From da085158b30ae983cdaaf172ba2fb97b40d3207d Mon Sep 17 00:00:00 2001
From: Carlo Zancanaro <address@hidden>
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

From 69c471d4ebe6a24fe11e6488f93616a7afb4467a Mon Sep 17 00:00:00 2001
From: Carlo Zancanaro <address@hidden>
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: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]