services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
;;; Copyright © 2015 Andy Wingo <wingo@igalia.com>
|
2017-03-24 06:00:13 -04:00
|
|
|
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
|
services: messaging: Prosody config supports file-like objects.
* 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).
* 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.
* guix/gexp.scm (file-like?): New exported procedure.
2018-02-25 19:12:24 -05:00
|
|
|
;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org>
|
2021-05-01 07:24:43 -04:00
|
|
|
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
|
2021-04-12 16:58:15 -04:00
|
|
|
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
;;;
|
|
|
|
;;; 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(define-module (gnu services configuration)
|
|
|
|
#:use-module (guix packages)
|
|
|
|
#:use-module (guix records)
|
|
|
|
#:use-module (guix gexp)
|
2018-12-22 15:30:40 -05:00
|
|
|
#:use-module ((guix utils) #:select (source-properties->location))
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
#:autoload (texinfo) (texi-fragment->stexi)
|
|
|
|
#:autoload (texinfo serialize) (stexi->texi)
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
#:use-module ((srfi srfi-1) #:select (append-map))
|
|
|
|
#:use-module (srfi srfi-34)
|
|
|
|
#:use-module (srfi srfi-35)
|
|
|
|
#:export (configuration-field
|
|
|
|
configuration-field-name
|
2017-01-08 14:08:14 -05:00
|
|
|
configuration-field-type
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
configuration-missing-field
|
|
|
|
configuration-field-error
|
2016-12-03 07:12:56 -05:00
|
|
|
configuration-field-serializer
|
|
|
|
configuration-field-getter
|
2017-01-08 14:08:14 -05:00
|
|
|
configuration-field-default-value-thunk
|
|
|
|
configuration-field-documentation
|
2021-05-07 22:39:54 -04:00
|
|
|
|
|
|
|
configuration-error?
|
|
|
|
|
|
|
|
define-configuration
|
2021-05-17 10:18:34 -04:00
|
|
|
define-configuration/no-serialization
|
2021-05-08 09:06:31 -04:00
|
|
|
no-serialization
|
2021-05-07 22:39:54 -04:00
|
|
|
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
serialize-configuration
|
2017-03-24 06:00:13 -04:00
|
|
|
define-maybe
|
2021-05-16 01:09:39 -04:00
|
|
|
define-maybe/no-serialization
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
validate-configuration
|
|
|
|
generate-documentation
|
2021-04-12 16:58:15 -04:00
|
|
|
configuration->documentation
|
2021-05-07 22:39:54 -04:00
|
|
|
empty-serializer
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
serialize-package))
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;;
|
|
|
|
;;; Syntax for creating Scheme bindings to complex configuration files.
|
|
|
|
;;;
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(define-condition-type &configuration-error &error
|
|
|
|
configuration-error?)
|
|
|
|
|
|
|
|
(define (configuration-error message)
|
|
|
|
(raise (condition (&message (message message))
|
|
|
|
(&configuration-error))))
|
|
|
|
(define (configuration-field-error field val)
|
|
|
|
(configuration-error
|
|
|
|
(format #f "Invalid value for field ~a: ~s" field val)))
|
|
|
|
(define (configuration-missing-field kind field)
|
|
|
|
(configuration-error
|
|
|
|
(format #f "~a configuration missing required field ~a" kind field)))
|
2021-05-01 07:24:43 -04:00
|
|
|
(define (configuration-no-default-value kind field)
|
|
|
|
(configuration-error
|
|
|
|
(format #f "The field `~a' of the `~a' configuration record \
|
|
|
|
does not have a default value" field kind)))
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
|
|
|
|
(define-record-type* <configuration-field>
|
|
|
|
configuration-field make-configuration-field configuration-field?
|
|
|
|
(name configuration-field-name)
|
|
|
|
(type configuration-field-type)
|
|
|
|
(getter configuration-field-getter)
|
|
|
|
(predicate configuration-field-predicate)
|
|
|
|
(serializer configuration-field-serializer)
|
|
|
|
(default-value-thunk configuration-field-default-value-thunk)
|
|
|
|
(documentation configuration-field-documentation))
|
|
|
|
|
|
|
|
(define (serialize-configuration config fields)
|
services: messaging: Prosody config supports file-like objects.
* 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).
* 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.
* guix/gexp.scm (file-like?): New exported procedure.
2018-02-25 19:12:24 -05:00
|
|
|
#~(string-append
|
|
|
|
#$@(map (lambda (field)
|
|
|
|
((configuration-field-serializer field)
|
|
|
|
(configuration-field-name field)
|
|
|
|
((configuration-field-getter field) config)))
|
|
|
|
fields)))
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
|
|
|
|
(define (validate-configuration config fields)
|
|
|
|
(for-each (lambda (field)
|
|
|
|
(let ((val ((configuration-field-getter field) config)))
|
|
|
|
(unless ((configuration-field-predicate field) val)
|
|
|
|
(configuration-field-error
|
|
|
|
(configuration-field-name field) val))))
|
|
|
|
fields))
|
|
|
|
|
2017-03-24 06:00:14 -04:00
|
|
|
(define-syntax-rule (id ctx parts ...)
|
2021-05-07 21:46:51 -04:00
|
|
|
"Assemble PARTS into a raw (unhygienic) identifier."
|
2017-03-24 06:00:14 -04:00
|
|
|
(datum->syntax ctx (symbol-append (syntax->datum parts) ...)))
|
2017-03-24 06:00:13 -04:00
|
|
|
|
2021-06-12 15:17:08 -04:00
|
|
|
(define (define-maybe-helper serialize? prefix syn)
|
2021-05-16 01:09:39 -04:00
|
|
|
(syntax-case syn ()
|
|
|
|
((_ stem)
|
|
|
|
(with-syntax
|
|
|
|
((stem? (id #'stem #'stem #'?))
|
|
|
|
(maybe-stem? (id #'stem #'maybe- #'stem #'?))
|
2021-06-12 15:17:08 -04:00
|
|
|
(serialize-stem (if prefix
|
|
|
|
(id #'stem prefix #'serialize- #'stem)
|
|
|
|
(id #'stem #'serialize- #'stem)))
|
|
|
|
(serialize-maybe-stem (if prefix
|
|
|
|
(id #'stem prefix #'serialize-maybe- #'stem)
|
|
|
|
(id #'stem #'serialize-maybe- #'stem))))
|
2021-05-16 01:09:39 -04:00
|
|
|
#`(begin
|
|
|
|
(define (maybe-stem? val)
|
|
|
|
(or (eq? val 'disabled) (stem? val)))
|
|
|
|
#,@(if serialize?
|
|
|
|
(list #'(define (serialize-maybe-stem field-name val)
|
|
|
|
(if (stem? val)
|
|
|
|
(serialize-stem field-name val)
|
|
|
|
"")))
|
|
|
|
'()))))))
|
|
|
|
|
2017-03-24 06:00:13 -04:00
|
|
|
(define-syntax define-maybe
|
|
|
|
(lambda (x)
|
2021-06-12 15:17:08 -04:00
|
|
|
(syntax-case x (no-serialization prefix)
|
2021-05-16 01:09:39 -04:00
|
|
|
((_ stem (no-serialization))
|
2021-06-12 15:17:08 -04:00
|
|
|
(define-maybe-helper #f #f #'(_ stem)))
|
|
|
|
((_ stem (prefix serializer-prefix))
|
|
|
|
(define-maybe-helper #t #'serializer-prefix #'(_ stem)))
|
2017-03-24 06:00:13 -04:00
|
|
|
((_ stem)
|
2021-06-12 15:17:08 -04:00
|
|
|
(define-maybe-helper #t #f #'(_ stem))))))
|
2021-05-16 01:09:39 -04:00
|
|
|
|
|
|
|
(define-syntax-rule (define-maybe/no-serialization stem)
|
|
|
|
(define-maybe stem (no-serialization)))
|
2017-03-24 06:00:13 -04:00
|
|
|
|
2021-06-12 15:17:08 -04:00
|
|
|
(define (define-configuration-helper serialize? serializer-prefix syn)
|
2021-05-07 21:46:51 -04:00
|
|
|
(syntax-case syn ()
|
2021-05-07 22:39:54 -04:00
|
|
|
((_ stem (field (field-type def ...) doc custom-serializer ...) ...)
|
2021-05-07 21:46:51 -04:00
|
|
|
(with-syntax (((field-getter ...)
|
|
|
|
(map (lambda (field)
|
|
|
|
(id #'stem #'stem #'- field))
|
|
|
|
#'(field ...)))
|
|
|
|
((field-predicate ...)
|
|
|
|
(map (lambda (type)
|
|
|
|
(id #'stem type #'?))
|
|
|
|
#'(field-type ...)))
|
|
|
|
((field-default ...)
|
|
|
|
(map (match-lambda
|
|
|
|
((field-type default-value)
|
|
|
|
default-value)
|
|
|
|
((field-type)
|
|
|
|
;; Quote `undefined' to prevent a possibly
|
|
|
|
;; unbound warning.
|
|
|
|
(syntax 'undefined)))
|
|
|
|
#'((field-type def ...) ...)))
|
|
|
|
((field-serializer ...)
|
2021-05-07 22:39:54 -04:00
|
|
|
(map (lambda (type custom-serializer)
|
|
|
|
(and serialize?
|
|
|
|
(match custom-serializer
|
|
|
|
((serializer)
|
|
|
|
serializer)
|
|
|
|
(()
|
2021-06-12 15:17:08 -04:00
|
|
|
(if serializer-prefix
|
|
|
|
(id #'stem
|
|
|
|
serializer-prefix
|
|
|
|
#'serialize- type)
|
|
|
|
(id #'stem #'serialize- type))))))
|
2021-05-07 22:39:54 -04:00
|
|
|
#'(field-type ...)
|
|
|
|
#'((custom-serializer ...) ...))))
|
2021-05-07 21:46:51 -04:00
|
|
|
#`(begin
|
|
|
|
(define-record-type* #,(id #'stem #'< #'stem #'>)
|
|
|
|
#,(id #'stem #'% #'stem)
|
|
|
|
#,(id #'stem #'make- #'stem)
|
|
|
|
#,(id #'stem #'stem #'?)
|
2021-05-08 00:54:03 -04:00
|
|
|
(%location #,(id #'stem #'stem #'-location)
|
2021-05-07 21:46:51 -04:00
|
|
|
(default (and=> (current-source-location)
|
|
|
|
source-properties->location))
|
|
|
|
(innate))
|
|
|
|
#,@(map (lambda (name getter def)
|
|
|
|
(if (eq? (syntax->datum def) (quote 'undefined))
|
|
|
|
#`(#,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)
|
|
|
|
(default-value-thunk
|
|
|
|
(lambda ()
|
|
|
|
(display '#,(id #'stem #'% #'stem))
|
|
|
|
(if (eq? (syntax->datum field-default)
|
|
|
|
'undefined)
|
|
|
|
(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)))))))
|
|
|
|
|
2021-05-08 09:06:31 -04:00
|
|
|
(define no-serialization ;syntactic keyword for 'define-configuration'
|
|
|
|
'(no serialization))
|
|
|
|
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
(define-syntax define-configuration
|
2021-05-07 21:46:51 -04:00
|
|
|
(lambda (s)
|
2021-06-12 15:17:08 -04:00
|
|
|
(syntax-case s (no-serialization prefix)
|
2021-05-07 22:39:54 -04:00
|
|
|
((_ stem (field (field-type def ...) doc custom-serializer ...) ...
|
|
|
|
(no-serialization))
|
2021-05-07 21:46:51 -04:00
|
|
|
(define-configuration-helper
|
2021-06-12 15:17:08 -04:00
|
|
|
#f #f #'(_ stem (field (field-type def ...) doc custom-serializer ...)
|
|
|
|
...)))
|
|
|
|
((_ stem (field (field-type def ...) doc custom-serializer ...) ...
|
|
|
|
(prefix serializer-prefix))
|
|
|
|
(define-configuration-helper
|
|
|
|
#t #'serializer-prefix #'(_ stem (field (field-type def ...)
|
|
|
|
doc custom-serializer ...)
|
2021-05-07 22:39:54 -04:00
|
|
|
...)))
|
|
|
|
((_ stem (field (field-type def ...) doc custom-serializer ...) ...)
|
2021-05-07 21:46:51 -04:00
|
|
|
(define-configuration-helper
|
2021-06-12 15:17:08 -04:00
|
|
|
#t #f #'(_ stem (field (field-type def ...) doc custom-serializer ...)
|
2021-05-07 22:39:54 -04:00
|
|
|
...))))))
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
|
2021-05-17 10:18:34 -04:00
|
|
|
(define-syntax-rule (define-configuration/no-serialization
|
|
|
|
stem (field (field-type def ...)
|
|
|
|
doc custom-serializer ...) ...)
|
|
|
|
(define-configuration stem (field (field-type def ...)
|
|
|
|
doc custom-serializer ...) ...
|
|
|
|
(no-serialization)))
|
|
|
|
|
2021-05-07 22:39:54 -04:00
|
|
|
(define (empty-serializer field-name val) "")
|
|
|
|
(define serialize-package empty-serializer)
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
|
|
|
|
;; A little helper to make it easier to document all those fields.
|
|
|
|
(define (generate-documentation documentation documentation-name)
|
|
|
|
(define (str x) (object->string x))
|
|
|
|
(define (generate configuration-name)
|
|
|
|
(match (assq-ref documentation configuration-name)
|
|
|
|
((fields . sub-documentation)
|
|
|
|
`((para "Available " (code ,(str configuration-name)) " fields are:")
|
|
|
|
,@(map
|
|
|
|
(lambda (f)
|
|
|
|
(let ((field-name (configuration-field-name f))
|
|
|
|
(field-type (configuration-field-type f))
|
|
|
|
(field-docs (cdr (texi-fragment->stexi
|
|
|
|
(configuration-field-documentation f))))
|
|
|
|
(default (catch #t
|
|
|
|
(configuration-field-default-value-thunk f)
|
|
|
|
(lambda _ '%invalid))))
|
|
|
|
(define (show-default? val)
|
2017-11-24 16:55:28 -05:00
|
|
|
(or (string? val) (number? val) (boolean? val)
|
services: Factorize configuration abstraction.
* gnu/services/mail.scm and gnu/services/cups.scm (&configuration-error)
(configuration-error, configuration-field-error)
(configuration-missing-field, configuration-field, serialize-configuration)
(validate-configuration, define-configuration, uglify-field-name)
(serialize-field, serialize-package, serialize-string)
(serialize-space-separated-string-list, space-separated-string-list?)
(serialize-file-name, file-name?, serialize-field-name)
(generate-documentation): Move duplicate code...
* gnu/services/configuration.scm: ...to this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add configuration.scm.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-11-23 15:43:42 -05:00
|
|
|
(and (symbol? val) (not (eq? val '%invalid)))
|
|
|
|
(and (list? val) (and-map show-default? val))))
|
|
|
|
`(deftypevr (% (category
|
|
|
|
(code ,(str configuration-name)) " parameter")
|
|
|
|
(data-type ,(str field-type))
|
|
|
|
(name ,(str field-name)))
|
|
|
|
,@field-docs
|
|
|
|
,@(if (show-default? default)
|
|
|
|
`((para "Defaults to " (samp ,(str default)) "."))
|
|
|
|
'())
|
|
|
|
,@(append-map
|
|
|
|
generate
|
|
|
|
(or (assq-ref sub-documentation field-name) '())))))
|
|
|
|
fields)))))
|
|
|
|
(stexi->texi `(*fragment* . ,(generate documentation-name))))
|
2021-04-12 16:58:15 -04:00
|
|
|
|
|
|
|
(define (configuration->documentation configuration-symbol)
|
|
|
|
"Take CONFIGURATION-SYMBOL, the symbol corresponding to the name used when
|
|
|
|
defining a configuration record with DEFINE-CONFIGURATION, and output the
|
|
|
|
Texinfo documentation of its fields."
|
|
|
|
;; This is helper for a simple, straight-forward application of
|
|
|
|
;; GENERATE-DOCUMENTATION.
|
|
|
|
(let ((fields-getter (module-ref (current-module)
|
|
|
|
(symbol-append configuration-symbol
|
|
|
|
'-fields))))
|
2021-05-07 09:40:47 -04:00
|
|
|
(display (generate-documentation `((,configuration-symbol ,fields-getter))
|
|
|
|
configuration-symbol))))
|