From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carlo Zancanaro Subject: Re: Services can now have a default value Date: Sat, 13 May 2017 20:39:37 +1000 Message-ID: <87bmqx6nx2.fsf@zancanaro.id.au> References: <87shl9qo7h.fsf@gnu.org> <877f2go3wn.fsf@zancanaro.id.au> <877f2gksbs.fsf@gnu.org> <8737d32abz.fsf@zancanaro.id.au> <87bmrr4ghh.fsf@gnu.org> <874lxjnzyx.fsf@zancanaro.id.au> <87bmrp8lk6.fsf@gnu.org> <8737d1nxbd.fsf@zancanaro.id.au> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9USl-0003f5-Q7 for guix-devel@gnu.org; Sat, 13 May 2017 06:39:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9USg-0001To-6t for guix-devel@gnu.org; Sat, 13 May 2017 06:39:51 -0400 In-reply-to: <8737d1nxbd.fsf@zancanaro.id.au> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-services-Add-define-service-type.patch Content-Transfer-Encoding: quoted-printable From=20da085158b30ae983cdaaf172ba2fb97b40d3207d Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro 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. =2D-- gnu/services.scm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/gnu/services.scm b/gnu/services.scm index 5c314748d..837e75568 100644 =2D-- a/gnu/services.scm +++ b/gnu/services.scm @@ -50,6 +50,8 @@ service-type-extend service-type-default-value =20 + define-service-type + service service? service-kind @@ -154,6 +156,37 @@ =20 (set-record-type-printer! write-service-type) =20 +(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- fie= ld)) + #'(fields ...)))) + #`(begin + (define #,(id #'stx #'service-name '-service-type) + (service-type + (name 'service-name) + (extensions exts ...))) + (define-record-type* #,(id #'stx '< #'service-name '-configur= ation>) + #,(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) co= nfig (... ...)) + (service + #,(id #'stx #'service-name '-service-type) + (#,(id #'stx #'service-name '-configuration) config (... .= ..)))))))))) + ;; Services of a given type. (define-record-type (make-service type value) =2D-=20 2.12.2 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-services-Change-exim-service-type-to-use-define-serv.patch Content-Transfer-Encoding: quoted-printable From=2069c471d4ebe6a24fe11e6488f93616a7afb4467a Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro 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. =2D-- 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 =2D-- a/gnu/services/mail.scm +++ b/gnu/services/mail.scm @@ -1693,14 +1693,6 @@ accept from local for any relay ;;; Exim. ;;; =20 =2D(define-record-type* exim-configuration =2D make-exim-configuration =2D exim-configuration? =2D (package exim-configuration-package ; =2D (default exim)) =2D (config-file exim-configuration-config-file ;file-like =2D (default #f))) =2D (define %exim-accounts (list (user-group (name "exim") @@ -1752,15 +1744,16 @@ exim_group =3D exim (zero? (system* #$(file-append package "/bin/exim") "-bV" "-C" #$(exim-computed-config-file package= config-file)))))))) =20 =2D(define exim-profile =2D (compose list exim-configuration-package)) =2D =2D(define exim-service-type =2D (service-type =2D (name 'exim) =2D (extensions =2D (list (service-extension shepherd-root-service-type exim-shepherd-se= rvice) =2D (service-extension account-service-type (const %exim-accounts)) =2D (service-extension activation-service-type exim-activation) =2D (service-extension profile-service-type exim-profile) =2D (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-accoun= ts)) + (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)))) =2D-=20 2.12.2 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEwWt2bKTcV+mIZ20oCShLEsLiKqIFAlkW4mkACgkQCShLEsLi KqJfCwf8C/xIfWHV8jIjcO6TYtgvlwCpFUK+IT4Kd5Q/fI/IhAWyA7TpFDVhrSLz aBxqZ+78HJo5XDpD9KHbCyqRYTEW9fQPgK8TbrqjKffLiDJm22KXNBGKX3f/+/ti 55ms4Te9u1WIszT5S4tXF0R7o57uVINtLH7cD2wXELlgoNGVJ1Yl8Tv7nBiKjcx5 BilEqNTiAkEsUeHNcVXHS5JTYQtu/uX2XGw1C6k9VH7caLmue8r9aU+oXbSUUNTH YjUn5AEbsrvRVBef/Pcnhhd8enT9LJpQg0UZA+j4rsLlES3uUbcRUyGuppmITM6e VtgcDGcvougIUJmVNNl9OAe4ehpdgw== =cXYI -----END PGP SIGNATURE----- --==-=-=--