guix/gnu/services
Xinglu Chen 2ad896751c
services: configuration: Allow specifying prefix for serializer names.
Sometimes two configurations might have the same types for their field values,
but the values might be serialized in two completely different
ways (e.g. because the two programs have different configuration languages).

An example of this would be the ‘serialize-boolean’ procedure in (gnu services
mail) and (gnu services getmail).  They both serialize a boolean value, but
because the Dovecot’s configuration language has a different syntax to the
configuration language for Getmail, two different procedures have to be
defined.

One way to workaround this would be to specify custom serializers for many
fields in order to separate the serialization of the values that have the same
type but serialize in different ways.  This could get very tedious, especially
if there are many configurations in the same module.

Another way would be to move one of the configurations to its own module, like
what was done with (gnu services getmail).  However, this would mean that
there would be multiple modules containing configurations for related
programs, e.g. we have (gnu services mail) and (gnu services getmail), it
doesn’t make much sense to keep the Getmail configuration in its own module.

This patch will allow one to write something like this:

  (define-configuration foo-configuration
    (bar
      (string "bob")
      "Option bar.")
    (prefix bar-))

and the value of the ‘bar’ field would be serialized using a procedure named
‘bar-serialize-string’ instead of just ‘serialize-string’.

* gnu/services/configuration.scm (define-maybe-helper): Accept ‘prefix’
argument for using serializer with custom prefix.
(define-maybe): Pattern match on ‘prefix’ literal.
(define-configuration-helper): Accept ‘prefix’ argument for using serializer
with custom prefix.
(define-configuration): Pattern match on ‘prefix’ literal.
* tests/services/configuration.scm ("serialize-configuration with prefix"):
New test.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2021-06-29 12:37:33 +02:00
..
admin.scm
audio.scm
auditd.scm
authentication.scm
avahi.scm services: Remove deprecated service procedures. 2021-06-14 18:35:17 +02:00
base.scm services: guix: Authorize 'bordeaux.guix.gnu.org.pub' by default. 2021-06-19 09:32:54 +01:00
certbot.scm services: certbot: Add option to use CSR file. 2021-06-24 18:19:39 -04:00
cgit.scm
ci.scm
configuration.scm services: configuration: Allow specifying prefix for serializer names. 2021-06-29 12:37:33 +02:00
cuirass.scm
cups.scm services: cups: Remove obsolete KeepAliveTimeout directive. 2021-06-23 03:26:33 +02:00
databases.scm
dbus.scm
desktop.scm services: Remove deprecated service procedures. 2021-06-14 18:35:17 +02:00
dict.scm
dns.scm
docker.scm
file-sharing.scm
games.scm
ganeti.scm
getmail.scm
guix.scm
herd.scm
hurd.scm
kerberos.scm
linux.scm
lirc.scm
mail.scm
mcron.scm services: Remove deprecated service procedures. 2021-06-14 18:35:17 +02:00
messaging.scm services: Remove deprecated service procedures. 2021-06-14 18:35:17 +02:00
monitoring.scm
networking.scm services: Remove deprecated service procedures. 2021-06-14 18:35:17 +02:00
nfs.scm
nix.scm
pam-mount.scm
pm.scm
rsync.scm
science.scm
sddm.scm
security-token.scm services: pcscd: Cleanup socket when started. 2021-06-19 23:49:18 +02:00
shepherd.scm
sound.scm
spice.scm
ssh.scm services: openssh: Replace 'without-password' by 'prohibit-password'. 2021-06-20 16:44:08 +02:00
syncthing.scm
sysctl.scm
telephony.scm
version-control.scm
virtualization.scm
vpn.scm Remove unused module imports from (gnu services vpn). 2021-06-25 13:27:10 +02:00
web.scm
xorg.scm services: Remove deprecated service procedures. 2021-06-14 18:35:17 +02:00