[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: |
Maxim Cournoyer |
Subject: |
Re: Add a way to disable serialization support to (guix services configuration) |
Date: |
Wed, 21 Apr 2021 11:43:07 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
Hi Ludovic,
Ludovic Courtès <ludo@gnu.org> writes:
> 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?
No, thank you for your reply! :-)
> 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.
>
> 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)))
I tried:
(if (syntax->datum configuration-field-serialization?)
#,(id #'stem #'serialize- type)
#false)
hoping to get rid of the warning, but that appears to be strictly
equivalent, resulting in the same warning. I also don't know how to fix
that.
> #'(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)
> "")
That does work, thanks! I'm a bit uncomfortable adding more warnings to
the Guix build output; OTOH it provides value (another user recently
pointed to the same annoyance here [0]).
Maxim
[0] https://lists.gnu.org/archive/html/guix-devel/2021-04/msg00319.html