From unknown Sun Jun 15 07:59:16 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#48976 <48976@debbugs.gnu.org> To: bug#48976 <48976@debbugs.gnu.org> Subject: Status: [PATCH] services: configuration: Allow specifying prefix for serializer names. Reply-To: bug#48976 <48976@debbugs.gnu.org> Date: Sun, 15 Jun 2025 14:59:16 +0000 retitle 48976 [PATCH] services: configuration: Allow specifying prefix for = serializer names. reassign 48976 guix-patches submitter 48976 Xinglu Chen severity 48976 normal tag 48976 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 12 15:17:22 2021 Received: (at submit) by debbugs.gnu.org; 12 Jun 2021 19:17:22 +0000 Received: from localhost ([127.0.0.1]:42020 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ls98E-00052j-4l for submit@debbugs.gnu.org; Sat, 12 Jun 2021 15:17:22 -0400 Received: from lists.gnu.org ([209.51.188.17]:43394) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ls98B-00052b-Va for submit@debbugs.gnu.org; Sat, 12 Jun 2021 15:17:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ls98B-0003zw-N6 for guix-patches@gnu.org; Sat, 12 Jun 2021 15:17:19 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:36318 helo=mail.yoctocell.xyz) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ls989-0005Kq-3n for guix-patches@gnu.org; Sat, 12 Jun 2021 15:17:19 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1623525429; bh=E2D2+3n8OcK4SV1iu/O2thYprix8lr4C2/ywUXZXSGs=; h=From:To:Cc:Subject:Date; b=FZN9jYRY+DqMNOrHgQH2KA41k0ES0UY9SP3Pn/lE2rVaUHfwyAKmL7ruipL1Vmerq ilstE6Mnq8ZNhOBn9V0DKIG4N/rV/eCdzzW6dICAsA43OC8fVAy3yCxaUEQ5CsRpLq 90QX10jOfyqcwzTGpV2pj11uyd99z38icUhfjNdo= To: guix-patches@gnu.org Subject: [PATCH] services: configuration: Allow specifying prefix for serializer names. Message-Id: <78d519eab8503f4eadf9c57b9d3d4ee07de1450c.1623525052.git.public@yoctocell.xyz> Date: Sat, 12 Jun 2021 21:17:08 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=87.96.130.155; envelope-from=public@yoctocell.xyz; helo=mail.yoctocell.xyz X-Spam_score_int: 30 X-Spam_score: 3.0 X-Spam_bar: +++ X-Spam_report: (3.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.498, FROM_SUSPICIOUS_NTLD_FP=1.593, PDS_OTHER_BAD_TLD=1.997, RDNS_DYNAMIC=0.982, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 2.8 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Sometimes two configurations might have the same types for their field values, but the values might be serialized in two completely different ways (e.g. because the two programs have different configu [...] Content analysis details: (2.8 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [209.51.188.17 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: yoctocell.xyz (xyz)] 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [209.51.188.17 listed in wl.mailspike.net] 1.6 FROM_SUSPICIOUS_NTLD_FP From abused NTLD 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 0.0 T_FILL_THIS_FORM_SHORT Fill in a short form with personal information X-Debbugs-Envelope-To: submit Cc: Maxim Cournoyer X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.2 (/) Sometimes two configurations might have the same types for their field valu= es, but the values might be serialized in two completely different ways (e.g. because the two programs have different configuration languages). An example of this would be the =E2=80=98serialize-boolean=E2=80=99 procedu= re in (gnu services mail) and (gnu services getmail). They both serialize a boolean value, but because the Dovecot=E2=80=99s configuration language has a different syntax= to the configuration language for Getmail, two different procedures have to be defined. One way to workaround this would be to specify custom serializers for many fields in order to separate the serialization of the values that have the s= ame type but serialize in different ways. This could get very tedious, especia= lly if there are many configurations in the same module. Another way would be to move one of the configurations to its own module, l= ike what was done with (gnu services getmail). However, this would mean that there would be multiple modules containing configurations for related programs, e.g. we have (gnu services mail) and (gnu services getmail), it doesn=E2=80=99t make much sense to keep the Getmail configuration in its ow= n module. This patch will allow one to write something like this: (define-configuration foo-configuration (bar (string "bob") "Option bar.") (prefix bar-)) and the value of the =E2=80=98bar=E2=80=99 field would be serialized using = a procedure named =E2=80=98bar-serialize-string=E2=80=99 instead of just =E2=80=98serialize-s= tring=E2=80=99. * gnu/services/configuration.scm (define-maybe-helper): Accept =E2=80=98pre= fix=E2=80=99 argument for using serializer with custom prefix. (define-maybe): Pattern match on =E2=80=98prefix=E2=80=99 literal. (define-configuration-helper): Accept =E2=80=98prefix=E2=80=99 argument for= using serializer with custom prefix. (define-configuration): Pattern match on =E2=80=98prefix=E2=80=99 literal. * tests/services/configuration.scm ("serialize-configuration with prefix"): New test. --- On top of that, I also have few services (at least 3 of them are mail-related, Procmail, Notmuch, L2md) I want to upstream once Guix Home has been merged. With this patch it would be possible to sort of put each configuration in a namespace without having to create new modules that just contain one configuration. gnu/services/configuration.scm | 38 +++++++++++++++++++++++--------- tests/services/configuration.scm | 12 ++++++++++ 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm index f23840ee6d..fd07b6fa49 100644 --- a/gnu/services/configuration.scm +++ b/gnu/services/configuration.scm @@ -109,14 +109,18 @@ does not have a default value" field kind))) "Assemble PARTS into a raw (unhygienic) identifier." (datum->syntax ctx (symbol-append (syntax->datum parts) ...))) =20 -(define (define-maybe-helper serialize? syn) +(define (define-maybe-helper serialize? prefix syn) (syntax-case syn () ((_ stem) (with-syntax ((stem? (id #'stem #'stem #'?)) (maybe-stem? (id #'stem #'maybe- #'stem #'?)) - (serialize-stem (id #'stem #'serialize- #'stem)) - (serialize-maybe-stem (id #'stem #'serialize-maybe- #'stem))) + (serialize-stem (if prefix + (id #'stem prefix #'serialize- #'stem) + (id #'stem #'serialize- #'stem))) + (serialize-maybe-stem (if prefix + (id #'stem prefix #'serialize-maybe- #= 'stem) + (id #'stem #'serialize-maybe- #'stem))= )) #`(begin (define (maybe-stem? val) (or (eq? val 'disabled) (stem? val))) @@ -129,16 +133,18 @@ does not have a default value" field kind))) =20 (define-syntax define-maybe (lambda (x) - (syntax-case x (no-serialization) + (syntax-case x (no-serialization prefix) ((_ stem (no-serialization)) - (define-maybe-helper #f #'(_ stem))) + (define-maybe-helper #f #f #'(_ stem))) + ((_ stem (prefix serializer-prefix)) + (define-maybe-helper #t #'serializer-prefix #'(_ stem))) ((_ stem) - (define-maybe-helper #t #'(_ stem)))))) + (define-maybe-helper #t #f #'(_ stem)))))) =20 (define-syntax-rule (define-maybe/no-serialization stem) (define-maybe stem (no-serialization))) =20 -(define (define-configuration-helper serialize? syn) +(define (define-configuration-helper serialize? serializer-prefix syn) (syntax-case syn () ((_ stem (field (field-type def ...) doc custom-serializer ...) ...) (with-syntax (((field-getter ...) @@ -165,7 +171,11 @@ does not have a default value" field kind))) ((serializer) serializer) (() - (id #'stem #'serialize- type))))) + (if serializer-prefix + (id #'stem + serializer-prefix + #'serialize- type) + (id #'stem #'serialize- type)))))) #'(field-type ...) #'((custom-serializer ...) ...)))) #`(begin @@ -212,15 +222,21 @@ does not have a default value" field kind))) =20 (define-syntax define-configuration (lambda (s) - (syntax-case s (no-serialization) + (syntax-case s (no-serialization prefix) ((_ stem (field (field-type def ...) doc custom-serializer ...) ... (no-serialization)) (define-configuration-helper - #f #'(_ stem (field (field-type def ...) doc custom-serializer ..= .) + #f #f #'(_ stem (field (field-type def ...) doc custom-serializer= ...) + ...))) + ((_ stem (field (field-type def ...) doc custom-serializer ...) ... + (prefix serializer-prefix)) + (define-configuration-helper + #t #'serializer-prefix #'(_ stem (field (field-type def ...) + doc custom-serializer ...) ...))) ((_ stem (field (field-type def ...) doc custom-serializer ...) ...) (define-configuration-helper - #t #'(_ stem (field (field-type def ...) doc custom-serializer ..= .) + #t #f #'(_ stem (field (field-type def ...) doc custom-serializer= ...) ...)))))) =20 (define-syntax-rule (define-configuration/no-serialization diff --git a/tests/services/configuration.scm b/tests/services/configuratio= n.scm index 85badd2da6..86a36a388d 100644 --- a/tests/services/configuration.scm +++ b/tests/services/configuration.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2021 Maxim Cournoyer +;;; Copyright =C2=A9 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -82,6 +83,17 @@ (let ((config (serializable-configuration))) (serialize-configuration config serializable-configuration-field= s))))) =20 +(define (custom-prefix-serialize-integer field-name name) name) + +(define-configuration configuration-with-prefix + (port (integer 10) "The port number.") + (prefix custom-prefix-)) + +(test-assert "serialize-configuration with prefix" + (gexp? + (let ((config (configuration-with-prefix))) + (serialize-configuration config configuration-with-prefix-fields)))) + ;;; ;;; define-maybe macro. base-commit: 00727470b92e0b8ab0e00dd2cd87495c0c136341 --=20 2.32.0 From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 29 06:03:30 2021 Received: (at 48976-done) by debbugs.gnu.org; 29 Jun 2021 10:03:30 +0000 Received: from localhost ([127.0.0.1]:53642 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lyAaX-0004Gj-TZ for submit@debbugs.gnu.org; Tue, 29 Jun 2021 06:03:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52426) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lyAaV-0004GU-Oy for 48976-done@debbugs.gnu.org; Tue, 29 Jun 2021 06:03:28 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:49378) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyAaQ-0001Mk-0E; Tue, 29 Jun 2021 06:03:22 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=42524 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyAaN-0000Rz-Pb; Tue, 29 Jun 2021 06:03:21 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Xinglu Chen Subject: Re: bug#48976: [PATCH] services: configuration: Allow specifying prefix for serializer names. References: <78d519eab8503f4eadf9c57b9d3d4ee07de1450c.1623525052.git.public@yoctocell.xyz> Date: Tue, 29 Jun 2021 12:03:18 +0200 In-Reply-To: <78d519eab8503f4eadf9c57b9d3d4ee07de1450c.1623525052.git.public@yoctocell.xyz> (Xinglu Chen's message of "Sat, 12 Jun 2021 21:17:08 +0200") Message-ID: <87sg11t2c9.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.3 (/) X-Debbugs-Envelope-To: 48976-done Cc: 48976-done@debbugs.gnu.org, Maxim Cournoyer X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) Hi, Xinglu Chen skribis: > Sometimes two configurations might have the same types for their field va= lues, > but the values might be serialized in two completely different > ways (e.g. because the two programs have different configuration language= s). > > An example of this would be the =E2=80=98serialize-boolean=E2=80=99 proce= dure in (gnu services > mail) and (gnu services getmail). They both serialize a boolean value, b= ut > because the Dovecot=E2=80=99s configuration language has a different synt= ax to the > configuration language for Getmail, two different procedures have to be > defined. > > One way to workaround this would be to specify custom serializers for many > fields in order to separate the serialization of the values that have the= same > type but serialize in different ways. This could get very tedious, espec= ially > if there are many configurations in the same module. > > Another way would be to move one of the configurations to its own module,= like > what was done with (gnu services getmail). However, this would mean that > there would be multiple modules containing configurations for related > programs, e.g. we have (gnu services mail) and (gnu services getmail), it > doesn=E2=80=99t make much sense to keep the Getmail configuration in its = own module. > > This patch will allow one to write something like this: > > (define-configuration foo-configuration > (bar > (string "bob") > "Option bar.") > (prefix bar-)) > > and the value of the =E2=80=98bar=E2=80=99 field would be serialized usin= g a procedure named > =E2=80=98bar-serialize-string=E2=80=99 instead of just =E2=80=98serialize= -string=E2=80=99. > > * gnu/services/configuration.scm (define-maybe-helper): Accept =E2=80=98p= refix=E2=80=99 > argument for using serializer with custom prefix. > (define-maybe): Pattern match on =E2=80=98prefix=E2=80=99 literal. > (define-configuration-helper): Accept =E2=80=98prefix=E2=80=99 argument f= or using serializer > with custom prefix. > (define-configuration): Pattern match on =E2=80=98prefix=E2=80=99 literal. > * tests/services/configuration.scm ("serialize-configuration with prefix"= ): > New test. Looks reasonable to me. Applied, thanks! Ludo=E2=80=99. From unknown Sun Jun 15 07:59:16 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 27 Jul 2021 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator