[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: |
Ludovic Courtès |
Subject: |
Re: Add a way to disable serialization support to (guix services configuration) |
Date: |
Sat, 17 Apr 2021 18:29:15 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
Hi Maxim,
Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
> I've rediscovered the little gem that is (guix services configurations),
> and attempted to make it more generally useful by adding an option to
> opt out of serialization (which is not well adapted for producing a list
> of command line arguments from the configuration for example):
In the meantime I saw you discuss this on #guile so maybe you’ve solved
the issue now?
If not, attached is a possible solution and example. It’s not perfect:
in the example, you’ll get a warning about ‘serialize-integer’ being
unbound, which is completely harmless but suboptimal. Not sure how to
address that.
HTH!
Ludo’.
diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm
index 90f12a8d39..20e1647335 100644
--- a/gnu/services/configuration.scm
+++ b/gnu/services/configuration.scm
@@ -109,6 +109,9 @@
(define (serialize-maybe-stem field-name val)
(if (stem? val) (serialize-stem field-name val) ""))))))))
+(define-syntax-parameter configuration-field-serialization?
+ (identifier-syntax #t))
+
(define-syntax define-configuration
(lambda (stx)
(syntax-case stx ()
@@ -123,7 +126,8 @@
#'(field-type ...)))
((field-serializer ...)
(map (lambda (type)
- (id #'stem #'serialize- type))
+ #`(and configuration-field-serialization?
+ #,(id #'stem #'serialize- type)))
#'(field-type ...))))
#`(begin
(define-record-type* #,(id #'stem #'< #'stem #'>)
@@ -152,6 +156,16 @@
#,(id #'stem #'stem #'-fields))
conf))))))))
+(define-syntax-rule (without-field-serialization definition)
+ (syntax-parameterize ((configuration-field-serialization?
+ (identifier-syntax #f)))
+ definition
+ #t))
+
+(without-field-serialization
+ (define-configuration foo
+ (bar (integer 123) "doc")))
+
(define (serialize-package field-name val)
"")