From unknown Sat Sep 13 11:12:05 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#30657 <30657@debbugs.gnu.org> To: bug#30657 <30657@debbugs.gnu.org> Subject: Status: Add support for file-like objects to the Prosody configuration Reply-To: bug#30657 <30657@debbugs.gnu.org> Date: Sat, 13 Sep 2025 18:12:05 +0000 retitle 30657 Add support for file-like objects to the Prosody configuration reassign 30657 guix-patches submitter 30657 Cl=C3=A9ment Lassieur severity 30657 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 28 17:26:31 2018 Received: (at submit) by debbugs.gnu.org; 28 Feb 2018 22:26:31 +0000 Received: from localhost ([127.0.0.1]:37999 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erABC-0008Fv-Va for submit@debbugs.gnu.org; Wed, 28 Feb 2018 17:26:31 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53659) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erABB-0008Fi-Bw for submit@debbugs.gnu.org; Wed, 28 Feb 2018 17:26:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erAAl-0000Ld-NU for submit@debbugs.gnu.org; Wed, 28 Feb 2018 17:26:24 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:60167) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erAAl-0000Kx-DN for submit@debbugs.gnu.org; Wed, 28 Feb 2018 17:26:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erAAV-0002pg-KD for guix-patches@gnu.org; Wed, 28 Feb 2018 17:26:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erAAF-000838-1R for guix-patches@gnu.org; Wed, 28 Feb 2018 17:25:47 -0500 Received: from mail.lassieur.org ([83.152.10.219]:51748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erAAE-0007wv-Ds for guix-patches@gnu.org; Wed, 28 Feb 2018 17:25:30 -0500 Received: from rodion (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id a49595be (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO) for ; Wed, 28 Feb 2018 22:25:26 +0000 (UTC) User-agent: mu4e 1.0; emacs 25.3.1 From: =?utf-8?Q?Cl=C3=A9ment?= Lassieur To: guix-patches@gnu.org Subject: Add support for file-like objects to the Prosody configuration Date: Wed, 28 Feb 2018 23:25:25 +0100 Message-ID: <877eqwhhuy.fsf@lassieur.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.1 (----) X-Debbugs-Envelope-To: submit 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: -4.1 (----) Hello, These patches add support for file-like objects to the Prosody service configuration. The idea is to replace this mechanism (which is used very often): (plain-file (with-output-to-string ... (format #t ...) ...)) with this one: (mixed-text-file (flatten (with-tokens-to-list ... (push-tokens ...) ...)) The point is that tokens don't have to be strings. Comments are welcome! Clément From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 28 17:28:37 2018 Received: (at 30657) by debbugs.gnu.org; 28 Feb 2018 22:28:37 +0000 Received: from localhost ([127.0.0.1]:38007 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erADF-0008JJ-CG for submit@debbugs.gnu.org; Wed, 28 Feb 2018 17:28:37 -0500 Received: from mail.lassieur.org ([83.152.10.219]:54098) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erADA-0008Iv-0d for 30657@debbugs.gnu.org; Wed, 28 Feb 2018 17:28:35 -0500 Received: from localhost.localdomain (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id cf63cedf (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for <30657@debbugs.gnu.org>; Wed, 28 Feb 2018 22:28:30 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20Lassieur?= To: 30657@debbugs.gnu.org Subject: [PATCH 1/4] services: utils: Add 'push-tokens' and 'with-tokens-to-list'. Date: Wed, 28 Feb 2018 23:28:18 +0100 Message-Id: <20180228222821.6195-1-clement@lassieur.org> X-Mailer: git-send-email 2.16.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 30657 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.0 (/) * gnu/services/utils.scm: New file. (push-tokens, with-tokens-to-list): New exported procedures. (%tokens-stack): New parameter. * gnu/local.mk: Add new file. --- gnu/local.mk | 1 + gnu/services/utils.scm | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 gnu/services/utils.scm diff --git a/gnu/local.mk b/gnu/local.mk index 68f3a20f6..07cc2229a 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -482,6 +482,7 @@ GNU_SYSTEM_MODULES = \ %D%/services/ssh.scm \ %D%/services/sysctl.scm \ %D%/services/telephony.scm \ + %D%/services/utils.scm \ %D%/services/version-control.scm \ %D%/services/vpn.scm \ %D%/services/web.scm \ diff --git a/gnu/services/utils.scm b/gnu/services/utils.scm new file mode 100644 index 000000000..a8d7981b2 --- /dev/null +++ b/gnu/services/utils.scm @@ -0,0 +1,41 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2018 Clément Lassieur +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu services utils) + #:export (push-tokens + with-tokens-to-list)) + +(define %tokens-stack (make-parameter #f)) + +(define (push-tokens . tokens) + "Push TOKENS to %TOKENS-STACK so that they will be returned by +WITH-TOKENS-TO-LIST." + (unless (%tokens-stack) + (error "not called within the dynamic extent of 'with-tokens-to-list'")) + (%tokens-stack (append (%tokens-stack) tokens))) + +(define (with-tokens-to-list thunk) + "Call THUNK and return the tokens that were pushed to %TOKENS-STACK as a +list." + (parameterize ((%tokens-stack '())) + (thunk) + (%tokens-stack))) + +;;; Local Variables: +;;; eval: (put 'with-tokens-to-list 'scheme-indent-function 0) +;;; End: -- 2.16.2 From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 28 17:28:38 2018 Received: (at 30657) by debbugs.gnu.org; 28 Feb 2018 22:28:38 +0000 Received: from localhost ([127.0.0.1]:38009 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erADF-0008JQ-Px for submit@debbugs.gnu.org; Wed, 28 Feb 2018 17:28:38 -0500 Received: from mail.lassieur.org ([83.152.10.219]:54098) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erADD-0008Iv-SF for 30657@debbugs.gnu.org; Wed, 28 Feb 2018 17:28:36 -0500 Received: from localhost.localdomain (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id 69217f90 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for <30657@debbugs.gnu.org>; Wed, 28 Feb 2018 22:28:31 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20Lassieur?= To: 30657@debbugs.gnu.org Subject: [PATCH 2/4] gexp: Add 'file-like?'. Date: Wed, 28 Feb 2018 23:28:19 +0100 Message-Id: <20180228222821.6195-2-clement@lassieur.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180228222821.6195-1-clement@lassieur.org> References: <20180228222821.6195-1-clement@lassieur.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 30657 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.0 (/) * guix/gexp.scm (file-like?): New exported procedure. --- guix/gexp.scm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/guix/gexp.scm b/guix/gexp.scm index f005c4d29..9a30579a6 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès +;;; Copyright © 2018 Clément Lassieur ;;; ;;; This file is part of GNU Guix. ;;; @@ -70,6 +71,8 @@ file-append-base file-append-suffix + file-like? + load-path-expression gexp-modules @@ -437,6 +440,14 @@ SUFFIX." (base (expand base lowered output))) (string-append base (string-concatenate suffix))))))) +(define (file-like? object) + (or (local-file? object) + (plain-file? object) + (computed-file? object) + (program-file? object) + (scheme-file? object) + (file-append? object))) + ;;; ;;; Inputs & outputs. -- 2.16.2 From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 28 17:28:44 2018 Received: (at 30657) by debbugs.gnu.org; 28 Feb 2018 22:28:44 +0000 Received: from localhost ([127.0.0.1]:38011 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erADM-0008Ji-3b for submit@debbugs.gnu.org; Wed, 28 Feb 2018 17:28:44 -0500 Received: from mail.lassieur.org ([83.152.10.219]:54100) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erADE-0008J7-Ji for 30657@debbugs.gnu.org; Wed, 28 Feb 2018 17:28:36 -0500 Received: from localhost.localdomain (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id eeb946a6 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for <30657@debbugs.gnu.org>; Wed, 28 Feb 2018 22:28:31 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20Lassieur?= To: 30657@debbugs.gnu.org Subject: [PATCH 3/4] services: utils: move 'flatten' from (gnu services web). Date: Wed, 28 Feb 2018 23:28:20 +0100 Message-Id: <20180228222821.6195-3-clement@lassieur.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180228222821.6195-1-clement@lassieur.org> References: <20180228222821.6195-1-clement@lassieur.org> X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 30657 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.0 (/) * gnu/services/web.scm (flatten): Move it... * gnu/services/utils.scm (flatten): ...to here, and export it. --- gnu/services/utils.scm | 12 +++++++++++- gnu/services/web.scm | 9 +-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/gnu/services/utils.scm b/gnu/services/utils.scm index a8d7981b2..4b7c9c219 100644 --- a/gnu/services/utils.scm +++ b/gnu/services/utils.scm @@ -17,8 +17,10 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu services utils) + #:use-module (srfi srfi-1) #:export (push-tokens - with-tokens-to-list)) + with-tokens-to-list + flatten)) (define %tokens-stack (make-parameter #f)) @@ -36,6 +38,14 @@ list." (thunk) (%tokens-stack))) +(define (flatten . lst) + "Return a list that recursively concatenates all sub-lists of LST." + (define (flatten1 head out) + (if (list? head) + (fold-right flatten1 out head) + (cons head out))) + (fold-right flatten1 '() lst)) + ;;; Local Variables: ;;; eval: (put 'with-tokens-to-list 'scheme-indent-function 0) ;;; End: diff --git a/gnu/services/web.scm b/gnu/services/web.scm index beda481b0..38af66367 100644 --- a/gnu/services/web.scm +++ b/gnu/services/web.scm @@ -29,6 +29,7 @@ #:use-module (gnu packages admin) #:use-module (gnu packages web) #:use-module (gnu packages php) + #:use-module (gnu services utils) #:use-module (guix records) #:use-module (guix gexp) #:use-module ((guix utils) #:select (version-major)) @@ -499,14 +500,6 @@ of index files." (nginx-upstream-configuration-servers upstream)) " }\n")) -(define (flatten . lst) - "Return a list that recursively concatenates all sub-lists of LST." - (define (flatten1 head out) - (if (list? head) - (fold-right flatten1 out head) - (cons head out))) - (fold-right flatten1 '() lst)) - (define (default-nginx-config config) (match-record config -- 2.16.2 From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 28 17:28:45 2018 Received: (at 30657) by debbugs.gnu.org; 28 Feb 2018 22:28:45 +0000 Received: from localhost ([127.0.0.1]:38013 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erADM-0008Jk-Dm for submit@debbugs.gnu.org; Wed, 28 Feb 2018 17:28:44 -0500 Received: from mail.lassieur.org ([83.152.10.219]:54098) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erADE-0008Iv-Ny for 30657@debbugs.gnu.org; Wed, 28 Feb 2018 17:28:37 -0500 Received: from localhost.localdomain (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id ccfc2d06 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for <30657@debbugs.gnu.org>; Wed, 28 Feb 2018 22:28:31 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20Lassieur?= To: 30657@debbugs.gnu.org Subject: [PATCH 4/4] services: messaging: Prosody config supports file-like objects. Date: Wed, 28 Feb 2018 23:28:21 +0100 Message-Id: <20180228222821.6195-4-clement@lassieur.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180228222821.6195-1-clement@lassieur.org> References: <20180228222821.6195-1-clement@lassieur.org> X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 30657 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.0 (/) * doc/guix.texi (Messaging Services): Update accordingly. * gnu/services/messaging.scm (serialize-field, enclose-quotes, serialize-raw-content, serialize-ssl-configuration, serialize-virtualhost-configuration, serialize-int-component-configuration, serialize-ext-component-configuration, prosody-activation): Replace 'format' with 'push-token' and 'with-output-to-string' with 'with-tokens-to-list'. (prosody-activation): Replace 'plain-file' with 'mixed-text-file' and flatten the tokens. (serialize-non-negative-integer, serialize-non-negative-integer-list): Convert numbers to strings. (file-object?, serialize-file-object, file-object-list?, serialize-file-object-list): New procedures. (ssl-configuration)[capath, cafile], (prosody-configuration)[plugin-paths, groups-file]: Replace 'file-name' with 'file-object'. --- doc/guix.texi | 13 +++++++---- gnu/services/messaging.scm | 58 ++++++++++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 24db16761..3bb544e62 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -14210,6 +14210,9 @@ There is also a way to specify the configuration as a string, if you have an old @code{prosody.cfg.lua} file that you want to port over from some other system; see the end for more details. +The @code{file-object} type designates either a file-like object +(@pxref{G-Expressions, file-like objects}) or a file name. + @c The following documentation was initially generated by @c (generate-documentation) in (gnu services messaging). Manually maintained @c documentation is better, so we shouldn't hesitate to edit below as @@ -14230,7 +14233,7 @@ Location of the Prosody data storage directory. See Defaults to @samp{"/var/lib/prosody"}. @end deftypevr -@deftypevr {@code{prosody-configuration} parameter} file-name-list plugin-paths +@deftypevr {@code{prosody-configuration} parameter} file-object-list plugin-paths Additional plugin directories. They are searched in all the specified paths in order. See @url{https://prosody.im/doc/plugins_directory}. Defaults to @samp{()}. @@ -14271,7 +14274,7 @@ should you want to disable them then add them to this list. Defaults to @samp{()}. @end deftypevr -@deftypevr {@code{prosody-configuration} parameter} file-name groups-file +@deftypevr {@code{prosody-configuration} parameter} file-object groups-file Path to a text file where the shared groups are defined. If this path is empty then @samp{mod_groups} does nothing. See @url{https://prosody.im/doc/modules/mod_groups}. @@ -14304,13 +14307,13 @@ Path to your private key file. Path to your certificate file. @end deftypevr -@deftypevr {@code{ssl-configuration} parameter} file-name capath +@deftypevr {@code{ssl-configuration} parameter} file-object capath Path to directory containing root certificates that you wish Prosody to trust when verifying the certificates of remote servers. Defaults to @samp{"/etc/ssl/certs"}. @end deftypevr -@deftypevr {@code{ssl-configuration} parameter} maybe-file-name cafile +@deftypevr {@code{ssl-configuration} parameter} maybe-file-object cafile Path to a file containing root certificates that you wish Prosody to trust. Similar to @code{capath} but with all certificates concatenated together. @end deftypevr @@ -14570,6 +14573,8 @@ string, you could instantiate a prosody service like this: (prosody.cfg.lua ""))) @end example +@c end of Prosody auto-generated documentation + @subsubheading BitlBee Service @cindex IRC (Internet Relay Chat) diff --git a/gnu/services/messaging.scm b/gnu/services/messaging.scm index 427e2121f..316eebecb 100644 --- a/gnu/services/messaging.scm +++ b/gnu/services/messaging.scm @@ -24,6 +24,7 @@ #:use-module (gnu services) #:use-module (gnu services shepherd) #:use-module (gnu services configuration) + #:use-module (gnu services utils) #:use-module (gnu system shadow) #:use-module (guix gexp) #:use-module (guix modules) @@ -115,16 +116,16 @@ "_"))) (define (serialize-field field-name val) - (format #t "~a = ~a;\n" (uglify-field-name field-name) val)) + (push-tokens (format #f "~a = " (uglify-field-name field-name)) val ";\n")) (define (serialize-field-list field-name val) (serialize-field field-name - (with-output-to-string + (with-tokens-to-list (lambda () - (format #t "{\n") + (push-tokens "{\n") (for-each (lambda (x) - (format #t "~a;\n" x)) + (push-tokens x ";\n")) val) - (format #t "}"))))) + (push-tokens "}"))))) (define (serialize-boolean field-name val) (serialize-field field-name (if val "true" "false"))) @@ -140,17 +141,17 @@ (define (non-negative-integer? val) (and (exact-integer? val) (not (negative? val)))) (define (serialize-non-negative-integer field-name val) - (serialize-field field-name val)) + (serialize-field field-name (number->string val))) (define-maybe non-negative-integer) (define (non-negative-integer-list? val) (and (list? val) (and-map non-negative-integer? val))) (define (serialize-non-negative-integer-list field-name val) - (serialize-field-list field-name val)) + (serialize-field-list field-name (map number->string val))) (define-maybe non-negative-integer-list) (define (enclose-quotes s) - (format #f "\"~a\"" s)) + (list "\"" s "\"")) (define (serialize-string field-name val) (serialize-field field-name (enclose-quotes val))) (define-maybe string) @@ -183,10 +184,22 @@ (serialize-string-list field-name val)) (define-maybe file-name) +(define (file-object? val) + (or (file-like? val) (file-name? val))) +(define (serialize-file-object field-name val) + (serialize-string field-name val)) +(define-maybe file-object) + +(define (file-object-list? val) + (and (list? val) (and-map file-object? val))) +(define (serialize-file-object-list field-name val) + (serialize-string-list field-name val)) +(define-maybe file-object) + (define (raw-content? val) (not (eq? val 'disabled))) (define (serialize-raw-content field-name val) - (format #t "~a" val)) + (push-tokens val)) (define-maybe raw-content) (define-configuration mod-muc-configuration @@ -224,12 +237,12 @@ just joined the room.")) "Path to your certificate file.") (capath - (file-name "/etc/ssl/certs") + (file-object "/etc/ssl/certs") "Path to directory containing root certificates that you wish Prosody to trust when verifying the certificates of remote servers.") (cafile - (maybe-file-name 'disabled) + (maybe-file-object 'disabled) "Path to a file containing root certificates that you wish Prosody to trust. Similar to @code{capath} but with all certificates concatenated together.") @@ -273,9 +286,9 @@ can create such a file with: (maybe-string 'disabled) "Password for encrypted private keys.")) (define (serialize-ssl-configuration field-name val) - (format #t "ssl = {\n") + (push-tokens "ssl = {\n") (serialize-configuration val ssl-configuration-fields) - (format #t "};\n")) + (push-tokens "};\n")) (define-maybe ssl-configuration) (define %default-modules-enabled @@ -331,7 +344,7 @@ can create such a file with: global) (plugin-paths - (file-name-list '()) + (file-object-list '()) "Additional plugin directories. They are searched in all the specified paths in order. See @url{https://prosody.im/doc/plugins_directory}." global) @@ -372,7 +385,7 @@ should you want to disable them then add them to this list." common) (groups-file - (file-name "/var/lib/prosody/sharedgroups.txt") + (file-object "/var/lib/prosody/sharedgroups.txt") "Path to a text file where the shared groups are defined. If this path is empty then @samp{mod_groups} does nothing. See @url{https://prosody.im/doc/modules/mod_groups}." @@ -566,7 +579,7 @@ See also @url{https://prosody.im/doc/modules/mod_muc}." '(domain)))) (let ((domain (virtualhost-configuration-domain config)) (rest (filter rest? virtualhost-configuration-fields))) - (format #t "VirtualHost \"~a\"\n" domain) + (push-tokens (format #f "VirtualHost \"~a\"\n" domain)) (serialize-configuration config rest))) ;; Serialize Component line first. @@ -577,7 +590,7 @@ See also @url{https://prosody.im/doc/modules/mod_muc}." (let ((hostname (int-component-configuration-hostname config)) (plugin (int-component-configuration-plugin config)) (rest (filter rest? int-component-configuration-fields))) - (format #t "Component \"~a\" \"~a\"\n" hostname plugin) + (push-tokens (format #f "Component \"~a\" \"~a\"\n" hostname plugin)) (serialize-configuration config rest))) ;; Serialize Component line first. @@ -587,7 +600,7 @@ See also @url{https://prosody.im/doc/modules/mod_muc}." '(hostname)))) (let ((hostname (ext-component-configuration-hostname config)) (rest (filter rest? ext-component-configuration-fields))) - (format #t "Component \"~a\"\n" hostname) + (push-tokens (format #f "Component \"~a\"\n" hostname)) (serialize-configuration config rest))) ;; Serialize virtualhosts and components last. @@ -646,13 +659,14 @@ See also @url{https://prosody.im/doc/modules/mod_muc}." (default-certs-dir "/etc/prosody/certs") (data-path (prosody-configuration-data-path config)) (pidfile-dir (dirname (prosody-configuration-pidfile config))) - (config-str + (config-tokens (if (opaque-prosody-configuration? config) - (opaque-prosody-configuration-prosody.cfg.lua config) - (with-output-to-string + (list (opaque-prosody-configuration-prosody.cfg.lua config)) + (with-tokens-to-list (lambda () (serialize-prosody-configuration config))))) - (config-file (plain-file "prosody.cfg.lua" config-str))) + (config-file + (apply mixed-text-file "prosody.cfg.lua" (flatten config-tokens)))) #~(begin (use-modules (guix build utils)) (define %user (getpw "prosody")) -- 2.16.2 From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 02 11:51:07 2018 Received: (at 30657) by debbugs.gnu.org; 2 Mar 2018 16:51:07 +0000 Received: from localhost ([127.0.0.1]:41482 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ernti-0005QK-Pj for submit@debbugs.gnu.org; Fri, 02 Mar 2018 11:51:06 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:47154) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ernth-0005QC-8r for 30657@debbugs.gnu.org; Fri, 02 Mar 2018 11:51:05 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id BE8D911B36; Fri, 2 Mar 2018 17:51:04 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CqWVSvzGtRZh; Fri, 2 Mar 2018 17:51:03 +0100 (CET) Received: from ribbon (unknown [193.50.110.134]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 0487C10495; Fri, 2 Mar 2018 17:51:02 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: =?utf-8?Q?Cl=C3=A9ment?= Lassieur Subject: Re: [bug#30657] [PATCH 2/4] gexp: Add 'file-like?'. References: <20180228222821.6195-1-clement@lassieur.org> <20180228222821.6195-2-clement@lassieur.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 12 =?utf-8?Q?Vent=C3=B4se?= an 226 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Fri, 02 Mar 2018 17:51:02 +0100 In-Reply-To: <20180228222821.6195-2-clement@lassieur.org> (=?utf-8?Q?=22Cl?= =?utf-8?Q?=C3=A9ment?= Lassieur"'s message of "Wed, 28 Feb 2018 23:28:19 +0100") Message-ID: <87sh9ictft.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30657 Cc: 30657@debbugs.gnu.org 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.0 (+) Hello! Cl=C3=A9ment Lassieur skribis: > * guix/gexp.scm (file-like?): New exported procedure. > --- > guix/gexp.scm | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/guix/gexp.scm b/guix/gexp.scm > index f005c4d29..9a30579a6 100644 > --- a/guix/gexp.scm > +++ b/guix/gexp.scm > @@ -1,5 +1,6 @@ > ;;; GNU Guix --- Functional package management for GNU > ;;; Copyright =C2=A9 2014, 2015, 2016, 2017 Ludovic Court=C3=A8s > +;;; Copyright =C2=A9 2018 Cl=C3=A9ment Lassieur > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -70,6 +71,8 @@ > file-append-base > file-append-suffix >=20=20 > + file-like? > + > load-path-expression > gexp-modules >=20=20 > @@ -437,6 +440,14 @@ SUFFIX." > (base (expand base lowered output))) > (string-append base (string-concatenate suffix)))))= )) >=20=20 > +(define (file-like? object) > + (or (local-file? object) > + (plain-file? object) > + (computed-file? object) > + (program-file? object) > + (scheme-file? object) > + (file-append? object))) This procedure would miss new types added with =E2=80=98define-gexp-compile= r=E2=80=99. In fact I think you can simply write: (define file-like? (@@ (guix gexp) lookup-compiler)) Does that make sense? Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 02 12:01:04 2018 Received: (at 30657) by debbugs.gnu.org; 2 Mar 2018 17:01:04 +0000 Received: from localhost ([127.0.0.1]:41493 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ero3M-0005fn-6A for submit@debbugs.gnu.org; Fri, 02 Mar 2018 12:01:04 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:47232) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ero3I-0005fE-Aa for 30657@debbugs.gnu.org; Fri, 02 Mar 2018 12:01:02 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 9809210495; Fri, 2 Mar 2018 18:00:59 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RImKshR5xCrK; Fri, 2 Mar 2018 18:00:59 +0100 (CET) Received: from ribbon (unknown [193.50.110.134]) by hera.aquilenet.fr (Postfix) with ESMTPSA id D2A5F10228; Fri, 2 Mar 2018 18:00:58 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: =?utf-8?Q?Cl=C3=A9ment?= Lassieur Subject: Re: [bug#30657] Add support for file-like objects to the Prosody configuration References: <877eqwhhuy.fsf@lassieur.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 12 =?utf-8?Q?Vent=C3=B4se?= an 226 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Fri, 02 Mar 2018 18:00:58 +0100 In-Reply-To: <877eqwhhuy.fsf@lassieur.org> (=?utf-8?Q?=22Cl=C3=A9ment?= Lassieur"'s message of "Wed, 28 Feb 2018 23:25:25 +0100") Message-ID: <87o9k6csz9.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30657 Cc: 30657@debbugs.gnu.org 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.0 (+) Hello, Cl=C3=A9ment Lassieur skribis: > These patches add support for file-like objects to the Prosody service > configuration. The idea is to replace this mechanism (which is used > very often): > > (plain-file > (with-output-to-string > ... > (format #t ...) > ...)) > > with this one: > > (mixed-text-file > (flatten > (with-tokens-to-list > ... > (push-tokens ...) > ...)) > > The point is that tokens don't have to be strings. That=E2=80=99s a great improvement. I=E2=80=99m wondering if we could somehow avoid building the token list in = this imperative manner. We could arrange to procedure a string-value gexp, i.e.: #~(string-append #$a #$b #$c) What if each =E2=80=98serialize-*=E2=80=99 procedure produce a string-value= d gexp that can be directly spliced in this big #~(string-append =E2=80=A6)? That would require changing =E2=80=98serialize-*=E2=80=99 to return a value= (currently their return value is ignored.) WDYT? Doable? Pointless? Thanks, Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 02 20:33:22 2018 Received: (at 30657) by debbugs.gnu.org; 3 Mar 2018 01:33:22 +0000 Received: from localhost ([127.0.0.1]:41691 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erw37-0008Kg-FF for submit@debbugs.gnu.org; Fri, 02 Mar 2018 20:33:22 -0500 Received: from mail.lassieur.org ([83.152.10.219]:54372) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erw35-0008KW-0a for 30657@debbugs.gnu.org; Fri, 02 Mar 2018 20:33:20 -0500 Received: from localhost.localdomain (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id 35b26853 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Sat, 3 Mar 2018 01:33:17 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20Lassieur?= To: 30657@debbugs.gnu.org Subject: [PATCH] services: messaging: Prosody config supports file-like objects. Date: Sat, 3 Mar 2018 02:33:08 +0100 Message-Id: <20180303013308.12929-1-clement@lassieur.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <87o9k6csz9.fsf@gnu.org> References: <87o9k6csz9.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 30657 Cc: ludo@gnu.org 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.0 (/) * doc/guix.texi (Messaging Services): Update accordingly. * gnu/services/configuration.scm (serialize-configuration, serialize-maybe-stem, serialize-package): Return strings or string-valued gexps (these procedures were only used for their side-effects). (file-like?): New exported procedure. * gnu/services/messaging.scm (serialize-field, serialize-field-list, enclose-quotes, serialize-raw-content, serialize-ssl-configuration, serialize-virtualhost-configuration-list, serialize-int-component-configuration-list, serialize-ext-component-configuration-list, serialize-virtualhost-configuration, serialize-int-component-configuration, serialize-ext-component-configuration, serialize-prosody-configuration): Return strings or string-valued gexps and stop printing. (prosody-activation): Use SERIALIZE-PROSODY-CONFIGURATION's return value with MIXED-TEXT-FILE instead of using its output with PLAIN-FILE. (serialize-non-negative-integer, serialize-non-negative-integer-list): Convert numbers to strings. (file-object?, serialize-file-object, file-object-list?, serialize-file-object-list): New procedures. (ssl-configuration)[capath, cafile], (prosody-configuration)[plugin-paths, groups-file]: Replace FILE-NAME with FILE-OBJECT. --- doc/guix.texi | 13 +++-- gnu/services/configuration.scm | 23 +++++---- gnu/services/messaging.scm | 111 ++++++++++++++++++++++++----------------- 3 files changed, 87 insertions(+), 60 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 24db16761..3bb544e62 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -14210,6 +14210,9 @@ There is also a way to specify the configuration as a string, if you have an old @code{prosody.cfg.lua} file that you want to port over from some other system; see the end for more details. +The @code{file-object} type designates either a file-like object +(@pxref{G-Expressions, file-like objects}) or a file name. + @c The following documentation was initially generated by @c (generate-documentation) in (gnu services messaging). Manually maintained @c documentation is better, so we shouldn't hesitate to edit below as @@ -14230,7 +14233,7 @@ Location of the Prosody data storage directory. See Defaults to @samp{"/var/lib/prosody"}. @end deftypevr -@deftypevr {@code{prosody-configuration} parameter} file-name-list plugin-paths +@deftypevr {@code{prosody-configuration} parameter} file-object-list plugin-paths Additional plugin directories. They are searched in all the specified paths in order. See @url{https://prosody.im/doc/plugins_directory}. Defaults to @samp{()}. @@ -14271,7 +14274,7 @@ should you want to disable them then add them to this list. Defaults to @samp{()}. @end deftypevr -@deftypevr {@code{prosody-configuration} parameter} file-name groups-file +@deftypevr {@code{prosody-configuration} parameter} file-object groups-file Path to a text file where the shared groups are defined. If this path is empty then @samp{mod_groups} does nothing. See @url{https://prosody.im/doc/modules/mod_groups}. @@ -14304,13 +14307,13 @@ Path to your private key file. Path to your certificate file. @end deftypevr -@deftypevr {@code{ssl-configuration} parameter} file-name capath +@deftypevr {@code{ssl-configuration} parameter} file-object capath Path to directory containing root certificates that you wish Prosody to trust when verifying the certificates of remote servers. Defaults to @samp{"/etc/ssl/certs"}. @end deftypevr -@deftypevr {@code{ssl-configuration} parameter} maybe-file-name cafile +@deftypevr {@code{ssl-configuration} parameter} maybe-file-object cafile Path to a file containing root certificates that you wish Prosody to trust. Similar to @code{capath} but with all certificates concatenated together. @end deftypevr @@ -14570,6 +14573,8 @@ string, you could instantiate a prosody service like this: (prosody.cfg.lua ""))) @end example +@c end of Prosody auto-generated documentation + @subsubheading BitlBee Service @cindex IRC (Internet Relay Chat) diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm index c45340f02..016ef4e0e 100644 --- a/gnu/services/configuration.scm +++ b/gnu/services/configuration.scm @@ -1,7 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2015 Andy Wingo ;;; Copyright © 2017 Mathieu Othacehe -;;; Copyright © 2017 Clément Lassieur +;;; Copyright © 2017, 2018 Clément Lassieur ;;; ;;; This file is part of GNU Guix. ;;; @@ -42,7 +42,8 @@ define-configuration validate-configuration generate-documentation - serialize-package)) + serialize-package + file-like?)) ;;; Commentary: ;;; @@ -74,11 +75,12 @@ (documentation configuration-field-documentation)) (define (serialize-configuration config fields) - (for-each (lambda (field) - ((configuration-field-serializer field) - (configuration-field-name field) - ((configuration-field-getter field) config))) - fields)) + #~(string-append + #$@(map (lambda (field) + ((configuration-field-serializer field) + (configuration-field-name field) + ((configuration-field-getter field) config))) + fields))) (define (validate-configuration config fields) (for-each (lambda (field) @@ -105,7 +107,7 @@ (define (maybe-stem? val) (or (eq? val 'disabled) (stem? val))) (define (serialize-maybe-stem field-name val) - (when (stem? val) (serialize-stem field-name val))))))))) + (if (stem? val) (serialize-stem field-name val) "")))))))) (define-syntax define-configuration (lambda (stx) @@ -147,7 +149,7 @@ conf)))))))) (define (serialize-package field-name val) - #f) + "") ;; A little helper to make it easier to document all those fields. (define (generate-documentation documentation documentation-name) @@ -182,3 +184,6 @@ (or (assq-ref sub-documentation field-name) '()))))) fields))))) (stexi->texi `(*fragment* . ,(generate documentation-name)))) + +(define (file-like? val) + (and (struct? val) ((@@ (guix gexp) lookup-compiler) val))) diff --git a/gnu/services/messaging.scm b/gnu/services/messaging.scm index 427e2121f..aa3d5f0a0 100644 --- a/gnu/services/messaging.scm +++ b/gnu/services/messaging.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2017 Clément Lassieur +;;; Copyright © 2017, 2018 Clément Lassieur ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2015, 2017, 2018 Ludovic Courtès ;;; @@ -115,16 +115,16 @@ "_"))) (define (serialize-field field-name val) - (format #t "~a = ~a;\n" (uglify-field-name field-name) val)) + #~(string-append + #$(format #f "~a = " (uglify-field-name field-name)) #$val ";\n")) (define (serialize-field-list field-name val) (serialize-field field-name - (with-output-to-string - (lambda () - (format #t "{\n") - (for-each (lambda (x) - (format #t "~a;\n" x)) - val) - (format #t "}"))))) + #~(string-append + "{\n" + #$@(map (lambda (x) + #~(string-append #$x ";\n")) + val) + "}"))) (define (serialize-boolean field-name val) (serialize-field field-name (if val "true" "false"))) @@ -140,17 +140,17 @@ (define (non-negative-integer? val) (and (exact-integer? val) (not (negative? val)))) (define (serialize-non-negative-integer field-name val) - (serialize-field field-name val)) + (serialize-field field-name (number->string val))) (define-maybe non-negative-integer) (define (non-negative-integer-list? val) (and (list? val) (and-map non-negative-integer? val))) (define (serialize-non-negative-integer-list field-name val) - (serialize-field-list field-name val)) + (serialize-field-list field-name (map number->string val))) (define-maybe non-negative-integer-list) (define (enclose-quotes s) - (format #f "\"~a\"" s)) + #~(string-append "\"" #$s "\"")) (define (serialize-string field-name val) (serialize-field field-name (enclose-quotes val))) (define-maybe string) @@ -183,10 +183,22 @@ (serialize-string-list field-name val)) (define-maybe file-name) +(define (file-object? val) + (or (file-like? val) (file-name? val))) +(define (serialize-file-object field-name val) + (serialize-string field-name val)) +(define-maybe file-object) + +(define (file-object-list? val) + (and (list? val) (and-map file-object? val))) +(define (serialize-file-object-list field-name val) + (serialize-string-list field-name val)) +(define-maybe file-object) + (define (raw-content? val) (not (eq? val 'disabled))) (define (serialize-raw-content field-name val) - (format #t "~a" val)) + val) (define-maybe raw-content) (define-configuration mod-muc-configuration @@ -224,12 +236,12 @@ just joined the room.")) "Path to your certificate file.") (capath - (file-name "/etc/ssl/certs") + (file-object "/etc/ssl/certs") "Path to directory containing root certificates that you wish Prosody to trust when verifying the certificates of remote servers.") (cafile - (maybe-file-name 'disabled) + (maybe-file-object 'disabled) "Path to a file containing root certificates that you wish Prosody to trust. Similar to @code{capath} but with all certificates concatenated together.") @@ -273,9 +285,10 @@ can create such a file with: (maybe-string 'disabled) "Password for encrypted private keys.")) (define (serialize-ssl-configuration field-name val) - (format #t "ssl = {\n") - (serialize-configuration val ssl-configuration-fields) - (format #t "};\n")) + #~(string-append + "ssl = {\n" + #$(serialize-configuration val ssl-configuration-fields) + "};\n")) (define-maybe ssl-configuration) (define %default-modules-enabled @@ -303,20 +316,23 @@ can create such a file with: (define (virtualhost-configuration-list? val) (and (list? val) (and-map virtualhost-configuration? val))) (define (serialize-virtualhost-configuration-list l) - (for-each - (lambda (val) (serialize-virtualhost-configuration val)) l)) + #~(string-append + #$@(map (lambda (val) + (serialize-virtualhost-configuration val)) l))) (define (int-component-configuration-list? val) (and (list? val) (and-map int-component-configuration? val))) (define (serialize-int-component-configuration-list l) - (for-each - (lambda (val) (serialize-int-component-configuration val)) l)) + #~(string-append + #$@(map (lambda (val) + (serialize-int-component-configuration val)) l))) (define (ext-component-configuration-list? val) (and (list? val) (and-map ext-component-configuration? val))) (define (serialize-ext-component-configuration-list l) - (for-each - (lambda (val) (serialize-ext-component-configuration val)) l)) + #~(string-append + #$@(map (lambda (val) + (serialize-ext-component-configuration val)) l))) (define-all-configurations prosody-configuration (prosody @@ -331,7 +347,7 @@ can create such a file with: global) (plugin-paths - (file-name-list '()) + (file-object-list '()) "Additional plugin directories. They are searched in all the specified paths in order. See @url{https://prosody.im/doc/plugins_directory}." global) @@ -372,7 +388,7 @@ should you want to disable them then add them to this list." common) (groups-file - (file-name "/var/lib/prosody/sharedgroups.txt") + (file-object "/var/lib/prosody/sharedgroups.txt") "Path to a text file where the shared groups are defined. If this path is empty then @samp{mod_groups} does nothing. See @url{https://prosody.im/doc/modules/mod_groups}." @@ -566,8 +582,9 @@ See also @url{https://prosody.im/doc/modules/mod_muc}." '(domain)))) (let ((domain (virtualhost-configuration-domain config)) (rest (filter rest? virtualhost-configuration-fields))) - (format #t "VirtualHost \"~a\"\n" domain) - (serialize-configuration config rest))) + #~(string-append + #$(format #f "VirtualHost \"~a\"\n" domain) + #$(serialize-configuration config rest)))) ;; Serialize Component line first. (define (serialize-int-component-configuration config) @@ -577,8 +594,9 @@ See also @url{https://prosody.im/doc/modules/mod_muc}." (let ((hostname (int-component-configuration-hostname config)) (plugin (int-component-configuration-plugin config)) (rest (filter rest? int-component-configuration-fields))) - (format #t "Component \"~a\" \"~a\"\n" hostname plugin) - (serialize-configuration config rest))) + #~(string-append + #$(format #f "Component \"~a\" \"~a\"\n" hostname plugin) + #$(serialize-configuration config rest)))) ;; Serialize Component line first. (define (serialize-ext-component-configuration config) @@ -587,22 +605,24 @@ See also @url{https://prosody.im/doc/modules/mod_muc}." '(hostname)))) (let ((hostname (ext-component-configuration-hostname config)) (rest (filter rest? ext-component-configuration-fields))) - (format #t "Component \"~a\"\n" hostname) - (serialize-configuration config rest))) + #~(string-append + #$(format #f "Component \"~a\"\n" hostname) + #$(serialize-configuration #$config #$rest)))) ;; Serialize virtualhosts and components last. (define (serialize-prosody-configuration config) (define (rest? field) (not (memq (configuration-field-name field) '(virtualhosts int-components ext-components)))) - (let ((rest (filter rest? prosody-configuration-fields))) - (serialize-configuration config rest)) - (serialize-virtualhost-configuration-list - (prosody-configuration-virtualhosts config)) - (serialize-int-component-configuration-list - (prosody-configuration-int-components config)) - (serialize-ext-component-configuration-list - (prosody-configuration-ext-components config))) + #~(string-append + #$(let ((rest (filter rest? prosody-configuration-fields))) + (serialize-configuration config rest)) + #$(serialize-virtualhost-configuration-list + (prosody-configuration-virtualhosts config)) + #$(serialize-int-component-configuration-list + (prosody-configuration-int-components config)) + #$(serialize-ext-component-configuration-list + (prosody-configuration-ext-components config)))) (define-configuration opaque-prosody-configuration (prosody @@ -646,13 +666,10 @@ See also @url{https://prosody.im/doc/modules/mod_muc}." (default-certs-dir "/etc/prosody/certs") (data-path (prosody-configuration-data-path config)) (pidfile-dir (dirname (prosody-configuration-pidfile config))) - (config-str - (if (opaque-prosody-configuration? config) - (opaque-prosody-configuration-prosody.cfg.lua config) - (with-output-to-string - (lambda () - (serialize-prosody-configuration config))))) - (config-file (plain-file "prosody.cfg.lua" config-str))) + (config-str (if (opaque-prosody-configuration? config) + (opaque-prosody-configuration-prosody.cfg.lua config) + (serialize-prosody-configuration config))) + (config-file (mixed-text-file "prosody.cfg.lua" config-str))) #~(begin (use-modules (guix build utils)) (define %user (getpw "prosody")) -- 2.16.2 From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 02 20:40:12 2018 Received: (at 30657) by debbugs.gnu.org; 3 Mar 2018 01:40:12 +0000 Received: from localhost ([127.0.0.1]:41700 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erw9j-0008Tz-18 for submit@debbugs.gnu.org; Fri, 02 Mar 2018 20:40:11 -0500 Received: from mail.lassieur.org ([83.152.10.219]:54374) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erw9g-0008Tq-Qf for 30657@debbugs.gnu.org; Fri, 02 Mar 2018 20:40:09 -0500 Received: from rodion (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id bcd4f6f4 (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO); Sat, 3 Mar 2018 01:40:07 +0000 (UTC) References: <877eqwhhuy.fsf@lassieur.org> <87o9k6csz9.fsf@gnu.org> User-agent: mu4e 1.0; emacs 25.3.1 From: =?utf-8?Q?Cl=C3=A9ment?= Lassieur To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#30657] Add support for file-like objects to the Prosody configuration In-reply-to: <87o9k6csz9.fsf@gnu.org> Date: Sat, 03 Mar 2018 02:40:06 +0100 Message-ID: <87606elyx5.fsf@lassieur.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 30657 Cc: 30657@debbugs.gnu.org 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.0 (/) Hello Ludovic, Ludovic Courtès writes: > I’m wondering if we could somehow avoid building the token list in this > imperative manner. Indeed it's much better if it's functional! I just sent a new patch. WDYT? Thanks, Clément From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 02 20:44:29 2018 Received: (at 30657) by debbugs.gnu.org; 3 Mar 2018 01:44:29 +0000 Received: from localhost ([127.0.0.1]:41704 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erwDt-00008N-45 for submit@debbugs.gnu.org; Fri, 02 Mar 2018 20:44:29 -0500 Received: from mail.lassieur.org ([83.152.10.219]:54380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1erwDr-00008G-Qa for 30657@debbugs.gnu.org; Fri, 02 Mar 2018 20:44:28 -0500 Received: from rodion (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id 0323793e (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO); Sat, 3 Mar 2018 01:44:23 +0000 (UTC) References: <20180228222821.6195-1-clement@lassieur.org> <20180228222821.6195-2-clement@lassieur.org> <87sh9ictft.fsf@gnu.org> User-agent: mu4e 1.0; emacs 25.3.1 From: =?utf-8?Q?Cl=C3=A9ment?= Lassieur To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#30657] [PATCH 2/4] gexp: Add 'file-like?'. In-reply-to: <87sh9ictft.fsf@gnu.org> Date: Sat, 03 Mar 2018 02:44:22 +0100 Message-ID: <874llylyq1.fsf@lassieur.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 30657 Cc: 30657@debbugs.gnu.org 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.0 (/) Ludovic Courtès writes: >> +(define (file-like? object) >> + (or (local-file? object) >> + (plain-file? object) >> + (computed-file? object) >> + (program-file? object) >> + (scheme-file? object) >> + (file-append? object))) > > This procedure would miss new types added with ‘define-gexp-compiler’. > > In fact I think you can simply write: > > (define file-like? (@@ (guix gexp) lookup-compiler)) > > Does that make sense? Yes it's great! One also needs to check that it's a struct though. I put it in (gnu services configuration). Would it make sense to add the 'struct?' check in (guix gexp), or to add 'file-like?' there? Clément From debbugs-submit-bounces@debbugs.gnu.org Sat Mar 03 06:43:32 2018 Received: (at 30657) by debbugs.gnu.org; 3 Mar 2018 11:43:32 +0000 Received: from localhost ([127.0.0.1]:41876 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1es5Zc-0007no-1T for submit@debbugs.gnu.org; Sat, 03 Mar 2018 06:43:32 -0500 Received: from mail.lassieur.org ([83.152.10.219]:54388) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1es5Za-0007nf-H3 for 30657@debbugs.gnu.org; Sat, 03 Mar 2018 06:43:31 -0500 Received: from rodion (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id c85b18f9 (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO); Sat, 3 Mar 2018 11:43:29 +0000 (UTC) References: <87o9k6csz9.fsf@gnu.org> <20180303013308.12929-1-clement@lassieur.org> User-agent: mu4e 1.0; emacs 25.3.1 From: =?utf-8?Q?Cl=C3=A9ment?= Lassieur To: 30657@debbugs.gnu.org Subject: Re: [bug#30657] [PATCH] services: messaging: Prosody config supports file-like objects. In-reply-to: <20180303013308.12929-1-clement@lassieur.org> Date: Sat, 03 Mar 2018 12:43:28 +0100 Message-ID: <871sh1mljz.fsf@lassieur.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 30657 Cc: ludo@gnu.org 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.0 (/) With a better use of 'format'... Clément Lassieur writes: > (define (serialize-field field-name val) > - (format #t "~a = ~a;\n" (uglify-field-name field-name) val)) > + #~(string-append > + #$(format #f "~a = " (uglify-field-name field-name)) #$val ";\n")) #~(format #f "~a = ~a;\n" #$(uglify-field-name field-name) #$val)) > (define (serialize-field-list field-name val) > (serialize-field field-name > - (with-output-to-string > - (lambda () > - (format #t "{\n") > - (for-each (lambda (x) > - (format #t "~a;\n" x)) > - val) > - (format #t "}"))))) > + #~(string-append > + "{\n" > + #$@(map (lambda (x) > + #~(string-append #$x ";\n")) > + val) > + "}"))) (ice-9 format) can do miracles ;-) (serialize-field field-name #~(format #f "{\n~@{~a;\n~}}" #$@val))) > (define (enclose-quotes s) > - (format #f "\"~a\"" s)) > + #~(string-append "\"" #$s "\"")) #~(format #f "\"~a\"" #$s)) > @@ -273,9 +285,10 @@ can create such a file with: > (maybe-string 'disabled) > "Password for encrypted private keys.")) > (define (serialize-ssl-configuration field-name val) > - (format #t "ssl = {\n") > - (serialize-configuration val ssl-configuration-fields) > - (format #t "};\n")) > + #~(string-append > + "ssl = {\n" > + #$(serialize-configuration val ssl-configuration-fields) > + "};\n")) #~(format #f "ssl = {\n~a};\n" #$(serialize-configuration val ssl-configuration-fields))) > (define-configuration opaque-prosody-configuration > (prosody > @@ -646,13 +666,10 @@ See also @url{https://prosody.im/doc/modules/mod_muc}." > (default-certs-dir "/etc/prosody/certs") > (data-path (prosody-configuration-data-path config)) > (pidfile-dir (dirname (prosody-configuration-pidfile config))) > - (config-str > - (if (opaque-prosody-configuration? config) > - (opaque-prosody-configuration-prosody.cfg.lua config) > - (with-output-to-string > - (lambda () > - (serialize-prosody-configuration config))))) > - (config-file (plain-file "prosody.cfg.lua" config-str))) > + (config-str (if (opaque-prosody-configuration? config) > + (opaque-prosody-configuration-prosody.cfg.lua config) > + (serialize-prosody-configuration config))) > + (config-file (mixed-text-file "prosody.cfg.lua" config-str))) > #~(begin > (use-modules (guix build utils)) > (define %user (getpw "prosody")) (with-imported-modules '((ice-9 format)) #~(begin (use-modules (ice-9 format)) #$(serialize-prosody-configuration config))))) From debbugs-submit-bounces@debbugs.gnu.org Sat Mar 03 09:27:56 2018 Received: (at 30657) by debbugs.gnu.org; 3 Mar 2018 14:27:56 +0000 Received: from localhost ([127.0.0.1]:41991 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1es88i-00075c-Fk for submit@debbugs.gnu.org; Sat, 03 Mar 2018 09:27:56 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:52408) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1es88h-00075U-Ae for 30657@debbugs.gnu.org; Sat, 03 Mar 2018 09:27:55 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 2632510638; Sat, 3 Mar 2018 15:27:54 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dR1SfyCBc-Ta; Sat, 3 Mar 2018 15:27:53 +0100 (CET) Received: from ribbon (unknown [IPv6:2a01:e0a:1d:7270:af76:b9b:ca24:c465]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 05847DAF5; Sat, 3 Mar 2018 15:27:52 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: =?utf-8?Q?Cl=C3=A9ment?= Lassieur Subject: Re: [bug#30657] [PATCH] services: messaging: Prosody config supports file-like objects. References: <87o9k6csz9.fsf@gnu.org> <20180303013308.12929-1-clement@lassieur.org> <871sh1mljz.fsf@lassieur.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 13 =?utf-8?Q?Vent=C3=B4se?= an 226 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Sat, 03 Mar 2018 15:27:52 +0100 In-Reply-To: <871sh1mljz.fsf@lassieur.org> (=?utf-8?Q?=22Cl=C3=A9ment?= Lassieur"'s message of "Sat, 03 Mar 2018 12:43:28 +0100") Message-ID: <87k1utb5ef.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30657 Cc: 30657@debbugs.gnu.org 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.0 (+) Hi! Cl=C3=A9ment Lassieur skribis: > Cl=C3=A9ment Lassieur writes: > >> (define (serialize-field field-name val) >> - (format #t "~a =3D ~a;\n" (uglify-field-name field-name) val)) >> + #~(string-append >> + #$(format #f "~a =3D " (uglify-field-name field-name)) #$val ";\n"= )) > > #~(format #f "~a =3D ~a;\n" #$(uglify-field-name field-name) #$val)) > >> (define (serialize-field-list field-name val) >> (serialize-field field-name >> - (with-output-to-string >> - (lambda () >> - (format #t "{\n") >> - (for-each (lambda (x) >> - (format #t "~a;\n" x)) >> - val) >> - (format #t "}"))))) >> + #~(string-append >> + "{\n" >> + #$@(map (lambda (x) >> + #~(string-append #$x ";\n")) >> + val) >> + "}"))) > > (ice-9 format) can do miracles ;-) > > (serialize-field field-name #~(format #f "{\n~@{~a;\n~}}" #$@val))) Indeed, though you need to make sure (ice-9 format) is in scope on the build side (the default =E2=80=98format=E2=80=99, aka. =E2=80=98simple-form= at=E2=80=99, doesn=E2=80=99t support anything beyond ~a, ~s, and ~%). >> (define (enclose-quotes s) >> - (format #f "\"~a\"" s)) >> + #~(string-append "\"" #$s "\"")) > > #~(format #f "\"~a\"" #$s)) It=E2=80=99s a case where I prefer =E2=80=98string-append=E2=80=99 because = is ensures that everything is a string and reports a type error if not. Conversely, (format #f "~a" =E2=80=A6) will silently convert anything to a string, whic= h may not be what you want. > (with-imported-modules '((ice-9 format)) This would import (ice-9 format) from the host Guile into the build environment. Thus, if you build your system with Guix on Guile 2.2.2 and I build mine on Guile 2.0.14, we end up with different derivations, which is not desirable. Instead, what you need is this: > #~(begin > (use-modules (ice-9 format)) That puts (ice-9 format) in scope, which is all you need. It=E2=80=99s the (ice-9 format) of the build-side Guile that=E2=80=99s used. Thanks, Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Sat Mar 03 09:37:53 2018 Received: (at 30657) by debbugs.gnu.org; 3 Mar 2018 14:37:53 +0000 Received: from localhost ([127.0.0.1]:41995 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1es8IL-0007KI-Ed for submit@debbugs.gnu.org; Sat, 03 Mar 2018 09:37:53 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:52448) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1es8IJ-0007K9-Dd for 30657@debbugs.gnu.org; Sat, 03 Mar 2018 09:37:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id CEE8510695; Sat, 3 Mar 2018 15:37:50 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QxrVZnx9pHiT; Sat, 3 Mar 2018 15:37:49 +0100 (CET) Received: from ribbon (unknown [IPv6:2a01:e0a:1d:7270:af76:b9b:ca24:c465]) by hera.aquilenet.fr (Postfix) with ESMTPSA id B8DDBDAF5; Sat, 3 Mar 2018 15:37:49 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: =?utf-8?Q?Cl=C3=A9ment?= Lassieur Subject: Re: [PATCH] services: messaging: Prosody config supports file-like objects. References: <87o9k6csz9.fsf@gnu.org> <20180303013308.12929-1-clement@lassieur.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 13 =?utf-8?Q?Vent=C3=B4se?= an 226 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Sat, 03 Mar 2018 15:37:49 +0100 In-Reply-To: <20180303013308.12929-1-clement@lassieur.org> (=?utf-8?Q?=22C?= =?utf-8?Q?l=C3=A9ment?= Lassieur"'s message of "Sat, 3 Mar 2018 02:33:08 +0100") Message-ID: <87bmg5b4xu.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30657 Cc: 30657@debbugs.gnu.org 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.0 (+) Hello, Cl=C3=A9ment Lassieur skribis: > * doc/guix.texi (Messaging Services): Update accordingly. > * gnu/services/configuration.scm (serialize-configuration, > serialize-maybe-stem, serialize-package): Return strings or string-valued > gexps (these procedures were only used for their side-effects). > (file-like?): New exported procedure. > * gnu/services/messaging.scm (serialize-field, serialize-field-list, > enclose-quotes, serialize-raw-content, serialize-ssl-configuration, > serialize-virtualhost-configuration-list, > serialize-int-component-configuration-list, > serialize-ext-component-configuration-list, > serialize-virtualhost-configuration, serialize-int-component-configuratio= n, > serialize-ext-component-configuration, serialize-prosody-configuration): > Return strings or string-valued gexps and stop printing. > (prosody-activation): Use SERIALIZE-PROSODY-CONFIGURATION's return value = with > MIXED-TEXT-FILE instead of using its output with PLAIN-FILE. > (serialize-non-negative-integer, serialize-non-negative-integer-list): Co= nvert > numbers to strings. > (file-object?, serialize-file-object, file-object-list?, > serialize-file-object-list): New procedures. > (ssl-configuration)[capath, cafile], (prosody-configuration)[plugin-paths, > groups-file]: Replace FILE-NAME with FILE-OBJECT. [...] > + #~(string-append > + #$@(map (lambda (field) > + ((configuration-field-serializer field) > + (configuration-field-name field) > + ((configuration-field-getter field) config))) > + fields))) Awesome, I find it clearer. :-) > +(define (file-like? val) > + (and (struct? val) ((@@ (guix gexp) lookup-compiler) val))) I=E2=80=99m not fond of the idea of using @@ in real code. :-) Could you move =E2=80=98file-like?=E2=80=99 to (guix gexp), with a docstrin= g, and with =E2=80=98->bool=E2=80=99 to avoid exposing internal details: (define (file-like? value) (and (struct? value) (->bool (lookup-compiler value)))) ? > +(define (file-object? val) > + (or (file-like? val) (file-name? val))) Do we need this predicate? After all, all we can say is that a file name is necessarily a string (or a string-valued gexp), but a string is not necessarily a file name (IOW there=E2=80=99s no disjoint type for file names.) I suppose the configuration mechanism needs it though, right? In that context it=E2=80=99s probably OK. Apart from this the patch LGTM, thank you! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Sat Mar 03 09:39:01 2018 Received: (at 30657) by debbugs.gnu.org; 3 Mar 2018 14:39:01 +0000 Received: from localhost ([127.0.0.1]:41999 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1es8JQ-0007M0-R3 for submit@debbugs.gnu.org; Sat, 03 Mar 2018 09:39:01 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:52458) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1es8JP-0007Lt-Ie for 30657@debbugs.gnu.org; Sat, 03 Mar 2018 09:38:59 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 1758610695; Sat, 3 Mar 2018 15:38:59 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zCrUWMZUp0gW; Sat, 3 Mar 2018 15:38:58 +0100 (CET) Received: from ribbon (unknown [IPv6:2a01:e0a:1d:7270:af76:b9b:ca24:c465]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 2D249DAF5; Sat, 3 Mar 2018 15:38:58 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: =?utf-8?Q?Cl=C3=A9ment?= Lassieur Subject: Re: [bug#30657] [PATCH 2/4] gexp: Add 'file-like?'. References: <20180228222821.6195-1-clement@lassieur.org> <20180228222821.6195-2-clement@lassieur.org> <87sh9ictft.fsf@gnu.org> <874llylyq1.fsf@lassieur.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 13 =?utf-8?Q?Vent=C3=B4se?= an 226 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Sat, 03 Mar 2018 15:38:57 +0100 In-Reply-To: <874llylyq1.fsf@lassieur.org> (=?utf-8?Q?=22Cl=C3=A9ment?= Lassieur"'s message of "Sat, 03 Mar 2018 02:44:22 +0100") Message-ID: <877eqtb4vy.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30657 Cc: 30657@debbugs.gnu.org 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.0 (+) Cl=C3=A9ment Lassieur skribis: > Ludovic Court=C3=A8s writes: > >>> +(define (file-like? object) >>> + (or (local-file? object) >>> + (plain-file? object) >>> + (computed-file? object) >>> + (program-file? object) >>> + (scheme-file? object) >>> + (file-append? object))) >> >> This procedure would miss new types added with =E2=80=98define-gexp-comp= iler=E2=80=99. >> >> In fact I think you can simply write: >> >> (define file-like? (@@ (guix gexp) lookup-compiler)) >> >> Does that make sense? > > Yes it's great! One also needs to check that it's a struct though. I > put it in (gnu services configuration). Would it make sense to add the > 'struct?' check in (guix gexp), or to add 'file-like?' there? Yes, it makes sense to add =E2=80=98file-like?=E2=80=99 to (guix gexp) prop= er, as I wrote in my other reply. I was hoping we could avoid that, but I understand there=E2=80=99s a need f= or it. Thanks, Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Sat Mar 03 12:38:26 2018 Received: (at 30657-done) by debbugs.gnu.org; 3 Mar 2018 17:38:26 +0000 Received: from localhost ([127.0.0.1]:42968 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esB73-00039a-RK for submit@debbugs.gnu.org; Sat, 03 Mar 2018 12:38:26 -0500 Received: from mail.lassieur.org ([83.152.10.219]:54392) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esB72-00039R-CS for 30657-done@debbugs.gnu.org; Sat, 03 Mar 2018 12:38:25 -0500 Received: from rodion (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id d9ebaed8 (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO); Sat, 3 Mar 2018 17:38:23 +0000 (UTC) References: <87o9k6csz9.fsf@gnu.org> <20180303013308.12929-1-clement@lassieur.org> <87bmg5b4xu.fsf@gnu.org> User-agent: mu4e 1.0; emacs 25.3.1 From: =?utf-8?Q?Cl=C3=A9ment?= Lassieur To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [PATCH] services: messaging: Prosody config supports file-like objects. In-reply-to: <87bmg5b4xu.fsf@gnu.org> Date: Sat, 03 Mar 2018 18:38:22 +0100 Message-ID: <87zi3pkqk1.fsf@lassieur.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 30657-done Cc: 30657-done@debbugs.gnu.org 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.0 (/) Ludovic Courtès writes: >> +(define (file-like? val) >> + (and (struct? val) ((@@ (guix gexp) lookup-compiler) val))) > > I’m not fond of the idea of using @@ in real code. :-) > > Could you move ‘file-like?’ to (guix gexp), with a docstring, and with > ‘->bool’ to avoid exposing internal details: > > (define (file-like? value) > (and (struct? value) (->bool (lookup-compiler value)))) > > ? I did it. >> +(define (file-object? val) >> + (or (file-like? val) (file-name? val))) > > Do we need this predicate? After all, all we can say is that a file > name is necessarily a string (or a string-valued gexp), but a string is > not necessarily a file name (IOW there’s no disjoint type for file > names.) > > I suppose the configuration mechanism needs it though, right? In that > context it’s probably OK. The problem is that the check happens when the user evaluates (prosody-configuration), which allow them to know right away about type errors, without running "guix system reconfigure". So the user doesn't even need a store. Plus, not everything should go to the store. For example, certificate keys shouldn't, as they are private. Thus, having both 'file-object?' and 'file-name?' makes sense to me. > Apart from this the patch LGTM, thank you! Pushed as bdcf0e6fd484a54240a98ddf8b6fa433c1b9bd6c, with the modifications you suggested. Thank you for the review! Clément From unknown Sat Sep 13 11:12:05 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 01 Apr 2018 11:24:04 +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