From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id gId4JWcgBmOh/gAAbAwnHQ (envelope-from ) for ; Wed, 24 Aug 2022 14:58:15 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id qARwJGcgBmNo2AAAG6o9tA (envelope-from ) for ; Wed, 24 Aug 2022 14:58:15 +0200 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 1007A3A089 for ; Wed, 24 Aug 2022 14:58:15 +0200 (CEST) Received: from localhost ([::1]:33448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQpxV-0004TJ-Ju for larch@yhetil.org; Wed, 24 Aug 2022 08:58:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34012) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQphr-0005Po-DG for bug-guix@gnu.org; Wed, 24 Aug 2022 08:42:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:56178) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQphq-0000mi-Q6 for bug-guix@gnu.org; Wed, 24 Aug 2022 08:42:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oQphq-00083I-MG for bug-guix@gnu.org; Wed, 24 Aug 2022 08:42:02 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#56799: [PATCH 1/5] services: configuration: Add a 'maybe-value-set?' procedure. References: <87o7xa8qxt.fsf@gmail.com> In-Reply-To: <87o7xa8qxt.fsf@gmail.com> Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Wed, 24 Aug 2022 12:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56799 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 56799@debbugs.gnu.org Cc: Attila Lendvai , Maxim Cournoyer Received: via spool by 56799-submit@debbugs.gnu.org id=B56799.166134487930863 (code B ref 56799); Wed, 24 Aug 2022 12:42:02 +0000 Received: (at 56799) by debbugs.gnu.org; 24 Aug 2022 12:41:19 +0000 Received: from localhost ([127.0.0.1]:45919 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oQph8-00081i-Mi for submit@debbugs.gnu.org; Wed, 24 Aug 2022 08:41:19 -0400 Received: from mail-ej1-f43.google.com ([209.85.218.43]:36568) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oQpgs-00080Q-Ll for 56799@debbugs.gnu.org; Wed, 24 Aug 2022 08:41:17 -0400 Received: by mail-ej1-f43.google.com with SMTP id d21so13936772eje.3 for <56799@debbugs.gnu.org>; Wed, 24 Aug 2022 05:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc; bh=Sw1lpu+FGt7QUeK/SSB0xZaYrJwR3BCmYCIMm/Wuz6Q=; b=dcBC0hu/wn2KhddcxGxI9kXfnVf/Usner/U5m3FsbML+Ji9YPUfvzA6e8Oxb3tCUpN i0ixjcheI1uoO4L9Kl9RvhzCefjDRBaQ5RftogS8D6e8k/SVcswFZECkMtKWVN/PXTtB J3vMtXZ1Wmkdmk8yyimaj7Z7SmCxKZ6SpF66a+yOzIN4Krcdj0s8rSlZXqAuMLUJoZKa ZysN3+vYRd9oGqiADQpDmKcc1mAZ/wwGj05Ao9y///WpAODa0AzutC4LjbM1OR35IMSK qCLeYec+TomqqUQtjxHYnID2qNMl4+4LvBzbtcCWXyYWHGjoKlPvS/b/QRYY4yrM75YR GavA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc; bh=Sw1lpu+FGt7QUeK/SSB0xZaYrJwR3BCmYCIMm/Wuz6Q=; b=x+dSElg/ZBwmL1213IBrxX3TU12Jf3wwxJgI/94vv2X27EH77oWbiIHnzJBh4QAp5d F9Lss17VrmNRgUHpZS6+OFQt2GU65yDYzoNenIzXkle3ZNPDFvwu6Qv7ZkdH1FrlGHyG 0mfRsJzkuvj8wwha6MP+SqfJznrGoGn0Ko0MrO4hy1t7ieVGSp4jEzowIdjqcDX27/5g pD/d94ITvyC7J0x4FE7cu60fSvJzBAWnU5AIKZ0vs7JJivQcISJhWVh5gxqHRaMY2i25 nVkTMJWHkWq1wnTG/LL7Sx70zk01FwBGhRIGLgdY1jmnhN80wQQqM6E/rCYYU3ODDrlA XlsQ== X-Gm-Message-State: ACgBeo1ar64PI+gsrv/5KgcrGKex46TteqcU2QTlvzqAYBKNTolSNT4f BPt0eXgt2dsnvRbObPwXeQVVbH3fMxY= X-Google-Smtp-Source: AA6agR5uiZ6WXUmVjLGgrYtHh0zrTOIrt1ZuW4bNwUF5AJx50w36LQFmGoLMLUEWoK82FXUKgVq7XA== X-Received: by 2002:a17:906:58c8:b0:6fe:91d5:18d2 with SMTP id e8-20020a17090658c800b006fe91d518d2mr2908464ejs.190.1661344856799; Wed, 24 Aug 2022 05:40:56 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:7509:f780:ed82:a496:f55:e07b]) by smtp.gmail.com with ESMTPSA id f2-20020a17090631c200b006fee7b5dff2sm1114628ejf.143.2022.08.24.05.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 05:40:55 -0700 (PDT) From: Attila Lendvai Date: Wed, 24 Aug 2022 14:40:38 +0200 Message-Id: <20220824124042.10959-1-attila@lendvai.name> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1661345895; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Sw1lpu+FGt7QUeK/SSB0xZaYrJwR3BCmYCIMm/Wuz6Q=; b=gYINqnVnDzC+c2eH+6StK7Pp2GIK7bxa+DPUckxUjm6hKDdsyeA09vynl63K0u7VmP0dlz MJW8wK+kYmunNh06eRZNrqtJDsLHlAhHgiTEbnqKNuS+FX53YvNv2qMRGleZ3u8VNjRVTU B37Nbdik51SQjFGsuONx/0TR1lAW95LWsjussDgOfGGKL7z5E11zoJ0sM/1ekg7Z9Tyqq1 qfnDMlUYBknMV2v0TZceUjF8zxcMBh9ccgAcKnByGbe87IuYH/24tDNr4Qt1Tasiu6OUly FfPOLolpO1Yg7nykUfk+eWrGIfZe/hW1HkjiNYtqamiLMWB+ciVGR4Tyy46r4g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1661345895; a=rsa-sha256; cv=none; b=bYSOBl4tkK4TRIPA7nxfmKC4b/1PLrop/Jd+EWNPeVjYJafaJLDksr25tV99T+HLGJY2DI cLVqObmuhqRHzmSgNeI5KkvOQXW49rFLONhslfWMuVQOzFHIdfEQ0QNDYx2bhTPNZ3zwIK anezHkRgTsw204Tlh6Q5K1HTXJYt7xXTucE05Xy6syYAaZDMkQtSlCvylrSoLp6Djyot3Z UGfJ29PcyVEzo8XxLaohHDPR1NzQgQ8dDYeUHDYZwrOgakFptpnD3XR+QpGfarOAR4ZXwh 9EcxkWDYYo0QdLrleaj1qyMibLaDzfDTR+WFV6dvn428ZPGLgOSeT1HbFfvplQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="dcBC0hu/"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 4.19 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="dcBC0hu/"; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 1007A3A089 X-Spam-Score: 4.19 X-Migadu-Scanner: scn1.migadu.com X-TUID: zH8hXz3MDRAv From: Maxim Cournoyer * gnu/services/configuration.scm (maybe-value-set?): New procedure. * doc/guix.texi (Complex Configurations): Document it. Remove comment showing usage of 'maybe-string' with a default value, which doesn't make sense. Co-authored-by: Attila Lendvai --- doc/guix.texi | 7 ++++++- gnu/services/configuration.scm | 15 ++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 86cfe7d49c..039df29ebc 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -38999,7 +38999,7 @@ to be a string, or left unspecified. (name ;; If set to a string, the `serialize-string' procedure will be used ;; to serialize the string. Otherwise this field is not serialized. - maybe-string ; equivalent to (maybe-string *unspecified*) + maybe-string "The name of this module.")) @end lisp @@ -39030,6 +39030,11 @@ whether its value is set or not. @end lisp @end deffn +@deffn (Scheme Procedure) maybe-value-set? @var{value} +Predicate to check whether a user explicitly specified the value of a +maybe field. +@end deffn + @deffn {Scheme Procedure} serialize-configuration @var{configuration} @ @var{fields} Return a G-expression that contains the values corresponding to the diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm index 3007e8de35..e2c4fe9998 100644 --- a/gnu/services/configuration.scm +++ b/gnu/services/configuration.scm @@ -57,6 +57,7 @@ (define-module (gnu services configuration) serialize-configuration define-maybe define-maybe/no-serialization + maybe-value-set? generate-documentation configuration->documentation empty-serializer @@ -142,7 +143,8 @@ (define (define-maybe-helper serialize? prefix syn) (id #'stem #'serialize-maybe- #'stem)))) #`(begin (define (maybe-stem? val) - (or (eq? val 'unset) (stem? val))) + (or (not (maybe-value-set? val)) + (stem? val))) #,@(if serialize? (list #'(define (serialize-maybe-stem field-name val) (if (stem? val) @@ -260,11 +262,10 @@ (define #,(id #'stem #'stem #'-fields) (default-value-thunk (lambda () (display '#,(id #'stem #'% #'stem)) - (if (eq? (syntax->datum field-default) - 'unset) + (if (maybe-value-set? (syntax->datum field-default)) + field-default (configuration-missing-default-value - '#,(id #'stem #'% #'stem) 'field) - field-default))) + '#,(id #'stem #'% #'stem) 'field)))) (documentation doc)) ...)))))))) @@ -300,6 +301,10 @@ (define-configuration stem (field field-type+def (define (empty-serializer field-name val) "") (define serialize-package empty-serializer) +(define (maybe-value-set? value) + "Predicate to check whether a 'maybe' value was explicitly provided." + (not (eq? 'unset value))) + ;; A little helper to make it easier to document all those fields. (define (generate-documentation documentation documentation-name) (define (str x) (object->string x)) -- 2.35.1