From patchwork Mon Jun 26 21:59:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruno Victal X-Patchwork-Id: 51380 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 06E5127BBE9; Mon, 26 Jun 2023 23:09:51 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 4CBC927BBE2 for ; Mon, 26 Jun 2023 23:09:48 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qDuGs-0005eI-Id; Mon, 26 Jun 2023 18:01:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qDuGi-00051t-S4 for guix-patches@gnu.org; Mon, 26 Jun 2023 18:01:10 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qDuGe-0005XG-Ng for guix-patches@gnu.org; Mon, 26 Jun 2023 18:01:06 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qDuGe-0008T3-JM for guix-patches@gnu.org; Mon, 26 Jun 2023 18:01:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63985] [PATCH v3 04/11] doc: Rewrite define-configuration. Resent-From: Bruno Victal Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 26 Jun 2023 22:01:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63985 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63985@debbugs.gnu.org Cc: Bruno Victal Received: via spool by 63985-submit@debbugs.gnu.org id=B63985.168781684732456 (code B ref 63985); Mon, 26 Jun 2023 22:01:04 +0000 Received: (at 63985) by debbugs.gnu.org; 26 Jun 2023 22:00:47 +0000 Received: from localhost ([127.0.0.1]:47187 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qDuGM-0008RO-DS for submit@debbugs.gnu.org; Mon, 26 Jun 2023 18:00:46 -0400 Received: from smtpmciv1.myservices.hosting ([185.26.107.237]:37968) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qDuGA-0008Qe-FE for 63985@debbugs.gnu.org; Mon, 26 Jun 2023 18:00:35 -0400 Received: from mail1.netim.hosting (unknown [185.26.106.173]) by smtpmciv1.myservices.hosting (Postfix) with ESMTP id 775BD20CB0 for <63985@debbugs.gnu.org>; Tue, 27 Jun 2023 00:00:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id C61758009C; Tue, 27 Jun 2023 00:00:05 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-2.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xFp_QWaTk86t; Tue, 27 Jun 2023 00:00:05 +0200 (CEST) Received: from guix-nuc.home.arpa (unknown [10.192.1.83]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id C99698009A; Tue, 27 Jun 2023 00:00:04 +0200 (CEST) From: Bruno Victal Date: Mon, 26 Jun 2023 22:59:30 +0100 Message-Id: <3c9e04b336d5627af5167ff3b786918df724f3f6.1687816734.git.mirai@makinata.eu> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Rewrite this section to make it easier to document later syntactical changes. * doc/guix.texi (Complex Configurations): Rewrite define-configuration documentation. Fix simple serializer example. --- doc/guix.texi | 102 +++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 60 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 853396f776..8355260378 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -41953,54 +41953,33 @@ Complex Configurations files, you can use the utilities defined in the @code{(gnu services configuration)} module. -The main utility is the @code{define-configuration} macro, which you -will use to define a Scheme record type (@pxref{Record Overview,,, -guile, GNU Guile Reference Manual}). The Scheme record will be -serialized to a configuration file by using @dfn{serializers}, which are -procedures that take some kind of Scheme value and returns a -G-expression (@pxref{G-Expressions}), which should, once serialized to -the disk, return a string. More details are listed below. +The main utility is the @code{define-configuration} macro, a helper +used to define a Scheme record type (@pxref{Record Overview,,, +guile, GNU Guile Reference Manual}). The fields from this Scheme record +can be serialized using @dfn{serializers}, which are procedures that take +some kind of Scheme value and translates them into another Scheme value or +@ref{G-Expressions}. @defmac define-configuration name clause1 clause2 @dots{} Create a record type named @code{@var{name}} that contains the fields found in the clauses. -A clause can have one of the following forms: +A clause has the following form: @example (@var{field-name} - (@var{type} @var{default-value}) - @var{documentation}) - -(@var{field-name} - (@var{type} @var{default-value}) - @var{documentation} - (serializer @var{serializer})) - -(@var{field-name} - (@var{type}) - @var{documentation}) - -(@var{field-name} - (@var{type}) - @var{documentation} - (serializer @var{serializer})) - -(@var{field-name} - (@var{type}) + @var{type-decl} @var{documentation} - (sanitizer @var{sanitizer}) - -(@var{field-name} - (@var{type}) - @var{documentation} - (sanitizer @var{sanitizer}) - (serializer @var{serializer})) + @var{option*} + @dots{}) @end example @var{field-name} is an identifier that denotes the name of the field in the generated record. +@var{type-decl} is either @code{@var{type}} for fields that require a +value to be set or @code{(@var{type} @var{default})} otherwise. + @var{type} is the type of the value corresponding to @var{field-name}; since Guile is untyped, a predicate procedure---@code{@var{type}?}---will be called on the value @@ -42018,6 +41997,28 @@ Complex Configurations @var{documentation} is a string formatted with Texinfo syntax which should provide a description of what setting this field does. +@var{option*} is one of the following subclauses: + +@table @asis +@item @code{empty-serializer} +Exclude this field from serialization. + +@item @code{(serializer @var{serializer})} +@var{serializer} is the name of a procedure which takes two arguments, +the first is the name of the field, and the second is the value +corresponding to the field. The procedure should return a string or +@ref{G-Expressions} that represents the content that will be serialized +to the configuration file. If none is specified, a procedure of the +name @code{serialize-@var{type}} will be used. + +An example of a simple serializer procedure: +@lisp +(define (serialize-boolean field-name value) + (let ((value (if value "true" "false"))) + #~(string-append '#$field-name #$value))) +@end lisp + +@item @code{(sanitizer @var{sanitizer})} @var{sanitizer} is a procedure which takes one argument, a user-supplied value, and returns a ``sanitized'' value for the field. If no sanitizer is specified, a default sanitizer is used, which raises @@ -42031,21 +42032,7 @@ Complex Configurations ((symbol? value) (symbol->string value)) (else (error "bad value")))) @end lisp - -@var{serializer} is the name of a procedure which takes two arguments, -the first is the name of the field, and the second is the value -corresponding to the field. The procedure should return a string or -G-expression (@pxref{G-Expressions}) that represents the content that -will be serialized to the configuration file. If none is specified, a -procedure of the name @code{serialize-@var{type}} will be used. - -A simple serializer procedure could look like this: - -@lisp -(define (serialize-boolean field-name value) - (let ((value (if value "true" "false"))) - #~(string-append #$field-name #$value))) -@end lisp +@end table In some cases multiple different configuration records might be defined in the same file, but their serializers for the same type might have to @@ -42066,13 +42053,13 @@ Complex Configurations (define-configuration foo-configuration (label - (string) + string "The name of label.") (prefix foo-)) (define-configuration bar-configuration (ip-address - (string) + string "The IPv4 address for this device.") (prefix bar-)) @end lisp @@ -42164,11 +42151,6 @@ Complex Configurations disk by using something like @code{mixed-text-file}. @end deffn -@deffn {Procedure} empty-serializer field-name value -A serializer that just returns an empty string. The -@code{serialize-package} procedure is an alias for this. -@end deffn - Once you have defined a configuration record, you will most likely also want to document it so that other people know to use it. To help with that, there are two procedures, both of which are documented below. @@ -42271,7 +42253,7 @@ Complex Configurations (define-configuration contact-configuration (name - (string) + string "The name of the contact." serialize-contact-name) (phone-number @@ -42281,15 +42263,15 @@ Complex Configurations maybe-string "The person's email address.") (married? - (boolean) + boolean "Whether the person is married.")) (define-configuration contacts-list-configuration (name - (string) + string "The name of the owner of this contact list.") (email - (string) + string "The owner's email address.") (contacts (list-of-contact-configurations '())