From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0r.migadu.com with LMTPS id OPGNEbJBjWCYXwEALuJCtg (envelope-from ) for ; Sat, 01 May 2021 13:55:30 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id CP48DbJBjWCLOgAAB5/wlQ (envelope-from ) for ; Sat, 01 May 2021 11:55:30 +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 CD4AC10BAF for ; Sat, 1 May 2021 13:55:29 +0200 (CEST) Received: from localhost ([::1]:56260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcoDZ-000558-0q for larch@yhetil.org; Sat, 01 May 2021 07:55:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcoDM-00054n-Cx for guix-devel@gnu.org; Sat, 01 May 2021 07:55:17 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:35712 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 1lcoDI-0000Na-0o; Sat, 01 May 2021 07:55:13 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1619870105; bh=WT9pFIbEHpluVMBqK7UQ/cIKxMHYuRBHIOGQu4nKqwM=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=IeXJzs+EwMoNr5BhihOfBFW8+TsuDTW+p0tVB46/fZDxYoQmkM2OZxmu5jf68fdij /KfYux28hIW5HFQCXilCbqnCKcgk1Gu+60iQ1wYu7XiFKGTCQg8xbZ03LTZKdbPRbQ Q8m8aqv2tGsZpXk9x1zuiG4yrqk7bkwMViy3ITEA= To: Ludovic =?utf-8?Q?Court=C3=A8s?= , Maxim Cournoyer Subject: Re: Add a way to disable serialization support to (guix services configuration) In-Reply-To: <871rb15y6k.fsf@yoctocell.xyz> References: <878s5ncjaw.fsf@gmail.com> <87fszoswmc.fsf@gnu.org> <87k0ovd4ok.fsf@gmail.com> <87mttqt0ms.fsf@gnu.org> <871rb15y6k.fsf@yoctocell.xyz> Date: Sat, 01 May 2021 13:54:53 +0200 Message-ID: <87k0oik6sy.fsf@yoctocell.xyz> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=87.96.130.155; envelope-from=public@yoctocell.xyz; helo=mail.yoctocell.xyz X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 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.5, PDS_OTHER_BAD_TLD=1.999, RDNS_DYNAMIC=0.982, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: guix-devel Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619870129; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=/Ri9UtdQXlGVmlhkMmucZHA1jq72aDNxZfqSnltwDSk=; b=TqxGSTUXcZsXN5dWwadNj5Z6Wk/ZR7v7GzQXgMnKXZZxInELijA1jpEvOf6KzTcTkZo9xL oaIev6M56ELLVbYAmH1NZjgG4DfSv77RnOBikQQaofwD/bhvMUR1i1G0adbzzAUa3DV11W 94Y/qDkNZXSXARcFn9tzHz7CAGP+qU35sTt615Og1UlFc1OmliDUk+KeIHTbCJXT7+nfzJ nYRRZcekKzfwEq8cJrM13k7pMWV+5eBLNfHz1RV90hMlCubr+FPLuo88lvDEFCK7IqGWIE 4QkVJoerBQce0rh/tdAcrGTN60S5sCi9+6ZzNIRNvPpftNiqq3ChR3nXfsEW7w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619870129; a=rsa-sha256; cv=none; b=AEo3dBuBsfXc0eXgztmJKWZbJqSJifFv6ufZhA1glE0v0k/c/T8aDd3NNmHiQuPAM7OvUO SWwaubXIotapSvwLrV0BHJGz0X4vd7E1eKg7MnlMt49JX1mnlYRnwmcwZlwlG4WAAaWu3/ k/Zg5Neu5ja9RFzmO1PKwUwcvnOY76AA42EKwWmZgkO13j74OU9C/91miVHJ+zI/ElsEh5 sSXeuSfg+yl82p9UZv8qmViszqU6zbwSfsHI0oAoWftXF+zsofU1NqoWcN7cE+/g8wSBQu oEoJA6iOvkJVw9EeeHQuKyyl6QlTtEbPHU8VAuDb6uYiCr9vKEqK1GbJF/8Dnw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=yoctocell.xyz header.s=mail header.b=IeXJzs+E; dmarc=pass (policy=none) header.from=yoctocell.xyz; spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Migadu-Spam-Score: -3.16 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=yoctocell.xyz header.s=mail header.b=IeXJzs+E; dmarc=pass (policy=none) header.from=yoctocell.xyz; spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Migadu-Queue-Id: CD4AC10BAF X-Spam-Score: -3.16 X-Migadu-Scanner: scn0.migadu.com X-TUID: kWOOxNj/lQfC --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, On Fri, Apr 23 2021, Xinglu Chen wrote: >> Wouldn=E2=80=99t it be nicer to write: >> >> (define-configuration foo >> (bar (integer 123) "doc" no-serializer) >> (baz (string "") "doc")) >> >> where =E2=80=98bar=E2=80=99 wouldn=E2=80=99t have a serializer and =E2= =80=98baz=E2=80=99 would? >> >> It=E2=80=99s also probably easier to implement correctly. > > I think that would be a good idea, maybe it could also make having a > default value be optional, like this: > > #+begin_src scheme > (define-configuration foo > (bar (integer) "doc" no-serializer) ;no default > (baz (string "default") "doc")) > #+end_src Since nobody seemed to show any objections, I went ahead and did something like this myself (see the attached patches). My macros skills aren=E2=80=99t that good so I hope I didn=E2=80=99t make any obvious mistak= es. :) I haven=E2=80=99t tested it thoroughly, but at least it didn=E2=80=99t brea= k anything when I ran =E2=80=98./pre-inst-env guix home build ...=E2=80=99. :) --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-services-configuration-Support-fields-without-defaul.patch Content-Transfer-Encoding: quoted-printable Content-Description: no-default-value >From 231281ebf555295e83513873293a1ad3eab884a8 Mon Sep 17 00:00:00 2001 Message-Id: <231281ebf555295e83513873293a1ad3eab884a8.1619869705.git.public= @yoctocell.xyz> In-Reply-To: References: From: Xinglu Chen Date: Sat, 1 May 2021 13:24:43 +0200 Subject: [PATCH 1/2] services: configuration: Support fields without default values. MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit Not all fields in a configuration have a sensible default value, e.g. =E2=80=98user.name=E2=80=99 in gitconfig, the user should have to set = that themselves * gnu/services/configuration.scm (configuration-missing-field): New procedu= re. (define-configuration): Make default value optional. --- gnu/services/configuration.scm | 78 ++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm index 90f12a8d39..85e1ac78cb 100644 --- a/gnu/services/configuration.scm +++ b/gnu/services/configuration.scm @@ -2,6 +2,7 @@ ;;; Copyright =C2=A9 2015 Andy Wingo ;;; Copyright =C2=A9 2017 Mathieu Othacehe ;;; Copyright =C2=A9 2017, 2018 Cl=C3=A9ment Lassieur +;;; Copyright =C2=A9 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -63,6 +64,9 @@ (define (configuration-missing-field kind field) (configuration-error (format #f "~a configuration missing required field ~a" kind field))) +(define (configuration-no-default-value kind field) + (configuration-error + (format #f "`~a' in `~a' does not have a default value" kind field))) =20 (define-record-type* configuration-field make-configuration-field configuration-field? @@ -112,7 +116,7 @@ (define-syntax define-configuration (lambda (stx) (syntax-case stx () - ((_ stem (field (field-type def) doc) ...) + ((_ stem (field (field-type properties ...) doc) ...) (with-syntax (((field-getter ...) (map (lambda (field) (id #'stem #'stem #'- field)) @@ -121,36 +125,56 @@ (map (lambda (type) (id #'stem type #'?)) #'(field-type ...))) + ((field-default ...) + (map (match-lambda + ((field-type default _ ...) default) + ;; We get warnings about `disabled' being an + ;; unbound variable unless we quote it. + (_ (syntax 'disabled))) + #'((field-type properties ...) ...))) ((field-serializer ...) (map (lambda (type) (id #'stem #'serialize- type)) #'(field-type ...)))) - #`(begin - (define-record-type* #,(id #'stem #'< #'stem #'>) - #,(id #'stem #'% #'stem) - #,(id #'stem #'make- #'stem) - #,(id #'stem #'stem #'?) - (%location #,(id #'stem #'-location) - (default (and=3D> (current-source-location) - source-properties->location)) - (innate)) - (field field-getter (default def)) - ...) - (define #,(id #'stem #'stem #'-fields) - (list (configuration-field - (name 'field) - (type 'field-type) - (getter field-getter) - (predicate field-predicate) - (serializer field-serializer) - (default-value-thunk (lambda () def)) - (documentation doc)) - ...)) - (define-syntax-rule (stem arg (... ...)) - (let ((conf (#,(id #'stem #'% #'stem) arg (... ...)))) - (validate-configuration conf - #,(id #'stem #'stem #'-fields)) - conf)))))))) + #`(begin + (define-record-type* #,(id #'stem #'< #'stem #'>) + #,(id #'stem #'% #'stem) + #,(id #'stem #'make- #'stem) + #,(id #'stem #'stem #'?) + (%location #,(id #'stem #'-location) + (default (and=3D> (current-source-location) + source-properties->location)) + (innate)) + #,@(map (lambda (name getter def) + (if (equal? (syntax->datum def) (quote 'disabled)) + #`(#,name #,getter) + #`(#,name #,getter (default #,def)))) + #'(field ...) + #'(field-getter ...) + #'(field-default ...))) + (define #,(id #'stem #'stem #'-fields) + (list (configuration-field + (name 'field) + (type 'field-type) + (getter field-getter) + (predicate field-predicate) + (serializer field-serializer) + ;; TODO: What if there is no default value? + (default-value-thunk + (lambda () + (display '#,(id #'stem #'% #'stem)) + (if (equal? (syntax->datum field-default) + (quote 'disabled)) + (configuration-no-default-value + '#,(id #'stem #'% #'stem) 'field) + field-default))) + (documentation doc)) + ...)) + (define-syntax-rule (stem arg (... ...)) + (let ((conf (#,(id #'stem #'% #'stem) arg (... ...)))) + (validate-configuration conf + #,(id #'stem #'stem #'-fields)) + conf)))))))) =20 (define (serialize-package field-name val) "") --=20 2.31.1 --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0002-services-configuration-Add-ability-to-use-custom-ser.patch Content-Transfer-Encoding: quoted-printable Content-Description: custom-serializer >From 90d63a46a29a8080b7f95eabcec115c5c2c6481e Mon Sep 17 00:00:00 2001 Message-Id: <90d63a46a29a8080b7f95eabcec115c5c2c6481e.1619869705.git.public= @yoctocell.xyz> In-Reply-To: References: From: Xinglu Chen Date: Sat, 1 May 2021 13:31:27 +0200 Subject: [PATCH 2/2] services: configuration: Add ability to use custom serializer. MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit Some configuration values should not be serialized to a configuration file, e.g. command line options for a daemon. * gnu/services/configuration.scm (define-configuration): Add option to use a custom serializer. (empty-serializer): New procedure. (serialize-package): Alias to =E2=80=98empty-serializer=E2=80=99. --- gnu/services/configuration.scm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm index 85e1ac78cb..7024b13136 100644 --- a/gnu/services/configuration.scm +++ b/gnu/services/configuration.scm @@ -44,6 +44,7 @@ define-configuration validate-configuration generate-documentation + empty-serializer serialize-package)) =20 ;;; Commentary: @@ -116,7 +117,7 @@ (define-syntax define-configuration (lambda (stx) (syntax-case stx () - ((_ stem (field (field-type properties ...) doc) ...) + ((_ stem (field (field-type properties ...) doc custom-serializer ..= .) ...) (with-syntax (((field-getter ...) (map (lambda (field) (id #'stem #'stem #'- field)) @@ -133,9 +134,12 @@ (_ (syntax 'disabled))) #'((field-type properties ...) ...))) ((field-serializer ...) - (map (lambda (type) - (id #'stem #'serialize- type)) - #'(field-type ...)))) + (map (lambda (type serializer) + (match serializer + (((serializer)) serializer) + (_ (id #'stem #'serialize- type)))) + #'(field-type ...) + #'((custom-serializer ...) ...)))) #`(begin (define-record-type* #,(id #'stem #'< #'stem #'>) #,(id #'stem #'% #'stem) @@ -176,8 +180,8 @@ #,(id #'stem #'stem #'-fields)) conf)))))))) =20 -(define (serialize-package field-name val) - "") +(define (empty-serializer field-name val) "") +(define serialize-package empty-serializer) =20 ;; A little helper to make it easier to document all those fields. (define (generate-documentation documentation documentation-name) --=20 2.31.1 --=-=-=--