[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Add a way to disable serialization support to (guix services configu
From: |
Xinglu Chen |
Subject: |
Re: Add a way to disable serialization support to (guix services configuration) |
Date: |
Sat, 01 May 2021 13:54:53 +0200 |
Hi,
On Fri, Apr 23 2021, Xinglu Chen wrote:
>> Wouldn’t it be nicer to write:
>>
>> (define-configuration foo
>> (bar (integer 123) "doc" no-serializer)
>> (baz (string "") "doc"))
>>
>> where ‘bar’ wouldn’t have a serializer and ‘baz’ would?
>>
>> It’s also probably easier to implement correctly.
>
> I think that would be a good idea, maybe it could also make having a
> default value be optional, like this:
>
> #+begin_src scheme
> (define-configuration foo
> (bar (integer) "doc" no-serializer) ;no default
> (baz (string "default") "doc"))
> #+end_src
Since nobody seemed to show any objections, I went ahead and did
something like this myself (see the attached patches). My macros skills
aren’t that good so I hope I didn’t make any obvious mistakes. :)
I haven’t tested it thoroughly, but at least it didn’t break anything
when I ran ‘./pre-inst-env guix home build ...’. :)
0001-services-configuration-Support-fields-without-defaul.patch
Description: no-default-value
>From 90d63a46a29a8080b7f95eabcec115c5c2c6481e Mon Sep 17 00:00:00 2001
Message-Id:
<90d63a46a29a8080b7f95eabcec115c5c2c6481e.1619869705.git.public@yoctocell.xyz>
In-Reply-To: <cover.1619869705.git.public@yoctocell.xyz>
References: <cover.1619869705.git.public@yoctocell.xyz>
From: Xinglu Chen <public@yoctocell.xyz>
Date: Sat, 1 May 2021 13:31:27 +0200
Subject: [PATCH 2/2] services: configuration: Add ability to use custom
serializer.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Some configuration values should not be serialized to a configuration file,
e.g. command line options for a daemon.
* gnu/services/configuration.scm (define-configuration): Add option to use a
custom serializer.
(empty-serializer): New procedure.
(serialize-package): Alias to ‘empty-serializer’.
---
gnu/services/configuration.scm | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm
index 85e1ac78cb..7024b13136 100644
--- a/gnu/services/configuration.scm
+++ b/gnu/services/configuration.scm
@@ -44,6 +44,7 @@
define-configuration
validate-configuration
generate-documentation
+ empty-serializer
serialize-package))
;;; Commentary:
@@ -116,7 +117,7 @@
(define-syntax define-configuration
(lambda (stx)
(syntax-case stx ()
- ((_ stem (field (field-type properties ...) doc) ...)
+ ((_ stem (field (field-type properties ...) doc custom-serializer ...)
...)
(with-syntax (((field-getter ...)
(map (lambda (field)
(id #'stem #'stem #'- field))
@@ -133,9 +134,12 @@
(_ (syntax 'disabled)))
#'((field-type properties ...) ...)))
((field-serializer ...)
- (map (lambda (type)
- (id #'stem #'serialize- type))
- #'(field-type ...))))
+ (map (lambda (type serializer)
+ (match serializer
+ (((serializer)) serializer)
+ (_ (id #'stem #'serialize- type))))
+ #'(field-type ...)
+ #'((custom-serializer ...) ...))))
#`(begin
(define-record-type* #,(id #'stem #'< #'stem #'>)
#,(id #'stem #'% #'stem)
@@ -176,8 +180,8 @@
#,(id #'stem #'stem #'-fields))
conf))))))))
-(define (serialize-package field-name val)
- "")
+(define (empty-serializer field-name val) "")
+(define serialize-package empty-serializer)
;; A little helper to make it easier to document all those fields.
(define (generate-documentation documentation documentation-name)
--
2.31.1
- Re: Add a way to disable serialization support to (guix services configuration),
Xinglu Chen <=