summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorGiacomo Leidi <therewasa@fishinthecalculator.me>2026-03-08 17:27:13 +0100
committerLiliana Marie Prikler <liliana.prikler@gmail.com>2026-04-12 17:23:42 +0200
commit0b8e838208a26fb8d7785b24fe26a4f9c9f744ac (patch)
treea00916cc8df1e360cf1d082bde415d2a82bedad9 /doc
parent2abfd1370fbdd2e6e859c7bd0f491c9f7bda4f0b (diff)
services: configuration: Add environment variable serializer.
This patch implements a general API to serialize configuration records to list of pairs representing environment variables. The car of each pair represents the variable name and the cdr the variable value. * gnu/services/configuration/environment-variables.scm: New file. (serialize-string-environment-variable) (serialize-maybe-string-environment-variable) (serialize-boolean-environment-variable) (serialize-maybe-boolean-environment-variable) (serialize-number-environment-variable) (serialize-maybe-number-environment-variable): New variables. (serialize-environment-variables): New variable. * gnu/services/configuration/utils.scm: New file. (uglify-snake-case): New variable. * tests/services/configuration.scm: Add tests for environment serializer. (wrong type for a field): Adjust error location. * doc/guix.texi: Document it. Change-Id: I81a166576f94d3c8f5bf78c82a02183689a3091c Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/guix.texi57
1 files changed, 57 insertions, 0 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 733c86afac..198ecb3413 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -51663,6 +51663,63 @@ phone-number = 0
is-married = true
@end example
+@subsubsection Serializing to environment variables
+@cindex environment variables, serialization of configuration records
+
+There are services which expect their configuration as environment variables.
+The @code{(gnu services configuration environment-variables)} module provides
+facilities to serialize configuration records from
+@code{(gnu services configuration)} to list of pairs representing environment
+variables.
+
+For example this configuration record:
+
+@lisp
+(define-configuration/no-serialization server
+ (ssh-port
+ (number 22)
+ "The public SSH port of the server.")
+ (fqdn
+ (maybe-string)
+ "The fully qualified domain name of the server.")
+ (active?
+ (boolean #f)
+ "Whether or not the server should be activated."))
+
+(define my-server
+ (server
+ (ssh-port 20022)
+ (active? #t)))
+@end lisp
+
+with this call:
+
+@lisp
+(serialize-environment-variables my-server server-fields
+ #:true-value "1"
+ #:false-value "0")
+@end lisp
+
+would yield:
+
+@lisp
+'(("SSH_PORT" . "20022")
+ ("ACTIVE" . "1"))
+@end lisp
+
+@anchor{serialize-environment-variables-procedure}
+@deffn {Procedure} serialize-environment-variables @var{config} @var{fields} @
+ [@var{selection} #f] [@var{negate?} #f] [#:prefix #f] @
+ [#:true-value "true"] [#:false-value "false"]
+Serializes the fields whose name is included in SELECTION from CONFIG, a
+configuration from @code{(gnu services configuration)}, and FIELDS, the
+list of its field records, to a list of pairs. When NEGATE? is #t all services
+not included in SELECTION will be serialized. Each pair represents an
+environment variable. The first element of each pair is the variable name, the
+second is the value. When PREFIX is a string it is prepended to the variable
+name. TRUE-VALUE and FALSE-VALUE will be used as a representation for
+respectfully @code{#t} and @code{#f}.
+@end deffn
@c *********************************************************************
@cindex troubleshooting, Guix System