From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id IJZfA3YIxWCBtgAAgWs5BA (envelope-from ) for ; Sat, 12 Jun 2021 21:18:14 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 0GuxOnUIxWCxaAAAB5/wlQ (envelope-from ) for ; Sat, 12 Jun 2021 19:18:13 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 581602CB9D for ; Sat, 12 Jun 2021 21:18:13 +0200 (CEST) Received: from localhost ([::1]:55890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ls992-00042C-Cl for larch@yhetil.org; Sat, 12 Jun 2021 15:18:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ls98t-000422-6p for guix-patches@gnu.org; Sat, 12 Jun 2021 15:18:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58707) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ls98s-0005k6-Qf for guix-patches@gnu.org; Sat, 12 Jun 2021 15:18:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ls98s-00053m-7L for guix-patches@gnu.org; Sat, 12 Jun 2021 15:18:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48976] [PATCH] services: configuration: Allow specifying prefix for serializer names. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 12 Jun 2021 19:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 48976 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48976@debbugs.gnu.org Cc: Maxim Cournoyer X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.162352544219394 (code B ref -1); Sat, 12 Jun 2021 19:18:02 +0000 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= 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1623525493; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=fCacr5SYJ499QECCvPlsYEZcSHFYB3Xu6aHvi0w6RIo=; b=QbFG5LhM2lotihaOuc/P4igItHKnIX3UaxrnWc083ltvNPjxJnMo/64nWuNdr75/HxyqSV V/zdgfl+sRd34CUKB2VUN5s0Yh20Jj2LX0wQkruM5uvUH8jBQCFlCNv6PVFbeTBsZa8P2S LpgSSE5B9LQeRow6NTiCtgKWhQeaiDVkB47EHWKnTA0ICZFS5W539GuohCHTn1pL84F5PG wd9yR5gyg+Y22DgYWrCgWhtdgQwz5vUFx9LwzopWD6L/pHjfLKqxcgg7MFILjT/ZsnvLyz UBV/2TwZcqPEXilcz+zQUtEtT5nA3RMI9Mle+nSJX7tNU8Lu1kLutjQdEGUovA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1623525493; a=rsa-sha256; cv=none; b=CgP9WUuYWfbRJTtgquWpKpKrqYjPmcmPjcf+JuevzoG8Phy9q7fPEC0hEKDb/IW5jaMgr/ OMP3K4OohnroMEj01g8V00YD1PeyrG7yHxjmZJL4/LhVnBfaHo8gGAt8scIlhfjyPfRzAP NNdhjoR6ZQzjEfI7yYWSOtExs2vL2fu4yNVI7jr0CL1E3KNKHSgQNUemQS2EqMXkhCXrUe LTLpgYRpDroxYComyvfwc+Pk1E4csSpZLWW3dTQ3pDWAAHUPf2A9izjUiWab9lO9GkRVvt UBv2Z1rYkUg2l0peeuFAb1p04VPVCZDwGYFUf3ohr5jyxzGZM7qbzL4Pra7SEA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=FZN9jYRY; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -0.33 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=FZN9jYRY; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 581602CB9D X-Spam-Score: -0.33 X-Migadu-Scanner: scn0.migadu.com X-TUID: TFb5BSchzrgc 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