me
/
guix
Archived
1
0
Fork 0

services: replace bare serializers with (serializer ...)

* gnu/home/services/shells.scm
(home-zsh-configuration)[environment-variables]: Use (serializer ...).
(home-bash-configuration)[aliases, environment-variables]: Likewise.
(home-fish-configuration)[abbreviations, aliases]
[environment-variables]: Likewise.
* gnu/services/audio.scm (mpd-configuration)[music-dir, playlist-dir]
[endpoints, address, inputs, archive-plugins, input-cache-size]
[decoders, filters, playlist-plugins]: Likewise.
* gnu/services/linux.scm (fstrim-configuration)[extra-arguments]:
Likewise.
* gnu/services/security.scm (fail2ban-jail-configuration)[backend]
[log-encoding, extra-content]: Likewise.
* tests/services/configuration.scm: Update tests.
("serialize-configuration [deprecated]"): New test.

Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
master
Bruno Victal 2023-03-26 19:41:30 +01:00 committed by Liliana Marie Prikler
parent 6f48efa9b8
commit 0fbb356714
No known key found for this signature in database
GPG Key ID: 442A84B8C70E2F87
5 changed files with 46 additions and 35 deletions

View File

@ -133,7 +133,7 @@ Shell startup process will continue with
(environment-variables (environment-variables
(alist '()) (alist '())
"Association list of environment variables to set for the Zsh session." "Association list of environment variables to set for the Zsh session."
serialize-posix-env-vars) (serializer serialize-posix-env-vars))
(zshenv (zshenv
(text-config '()) (text-config '())
"List of file-like objects, which will be added to @file{.zshenv}. "List of file-like objects, which will be added to @file{.zshenv}.
@ -334,7 +334,7 @@ source ~/.profile
rules for the @code{home-environment-variables-service-type} apply rules for the @code{home-environment-variables-service-type} apply
here (@pxref{Essential Home Services}). The contents of this field will be here (@pxref{Essential Home Services}). The contents of this field will be
added after the contents of the @code{bash-profile} field." added after the contents of the @code{bash-profile} field."
serialize-posix-env-vars) (serializer serialize-posix-env-vars))
(aliases (aliases
(alist '()) (alist '())
"Association list of aliases to set for the Bash session. The aliases will be "Association list of aliases to set for the Bash session. The aliases will be
@ -351,7 +351,7 @@ turns into
@example @example
alias ls=\"ls -alF\" alias ls=\"ls -alF\"
@end example" @end example"
bash-serialize-aliases) (serializer bash-serialize-aliases))
(bash-profile (bash-profile
(text-config '()) (text-config '())
"List of file-like objects, which will be added to @file{.bash_profile}. "List of file-like objects, which will be added to @file{.bash_profile}.
@ -536,19 +536,19 @@ with text blocks from other extensions and the base service."))
(environment-variables (environment-variables
(alist '()) (alist '())
"Association list of environment variables to set in Fish." "Association list of environment variables to set in Fish."
serialize-fish-env-vars) (serializer serialize-fish-env-vars))
(aliases (aliases
(alist '()) (alist '())
"Association list of aliases for Fish, both the key and the value "Association list of aliases for Fish, both the key and the value
should be a string. An alias is just a simple function that wraps a should be a string. An alias is just a simple function that wraps a
command, If you want something more akin to @dfn{aliases} in POSIX command, If you want something more akin to @dfn{aliases} in POSIX
shells, see the @code{abbreviations} field." shells, see the @code{abbreviations} field."
serialize-fish-aliases) (serializer serialize-fish-aliases))
(abbreviations (abbreviations
(alist '()) (alist '())
"Association list of abbreviations for Fish. These are words that, "Association list of abbreviations for Fish. These are words that,
when typed in the shell, will automatically expand to the full text." when typed in the shell, will automatically expand to the full text."
serialize-fish-abbreviations)) (serializer serialize-fish-abbreviations)))
(define (fish-files-service config) (define (fish-files-service config)
`(("fish/config.fish" `(("fish/config.fish"

View File

@ -370,7 +370,7 @@ Available values: @code{notice}, @code{info}, @code{verbose},
(music-dir ; TODO: deprecated, remove later (music-dir ; TODO: deprecated, remove later
maybe-string maybe-string
"The directory to scan for music files." "The directory to scan for music files."
mpd-serialize-deprecated-field) (serializer mpd-serialize-deprecated-field))
(playlist-directory (playlist-directory
maybe-string maybe-string
@ -379,7 +379,7 @@ Available values: @code{notice}, @code{info}, @code{verbose},
(playlist-dir ; TODO: deprecated, remove later (playlist-dir ; TODO: deprecated, remove later
maybe-string maybe-string
"The directory to store playlists." "The directory to store playlists."
mpd-serialize-deprecated-field) (serializer mpd-serialize-deprecated-field))
(db-file (db-file
maybe-string maybe-string
@ -405,16 +405,17 @@ IPv6 addresses must be enclosed in square brackets when a different
port is used. port is used.
To use a Unix domain socket, an absolute path or a path starting with @code{~} To use a Unix domain socket, an absolute path or a path starting with @code{~}
can be specified here." can be specified here."
(lambda (_ endpoints) (serializer
(if (maybe-value-set? endpoints) (lambda (_ endpoints)
(mpd-serialize-list-of-strings "bind_to_address" endpoints) (if (maybe-value-set? endpoints)
""))) (mpd-serialize-list-of-strings "bind_to_address" endpoints)
""))))
(address ; TODO: deprecated, remove later (address ; TODO: deprecated, remove later
maybe-string maybe-string
"The address that mpd will bind to. "The address that mpd will bind to.
To use a Unix domain socket, an absolute path can be specified here." To use a Unix domain socket, an absolute path can be specified here."
mpd-serialize-deprecated-field) (serializer mpd-serialize-deprecated-field))
(database (database
maybe-mpd-plugin maybe-mpd-plugin
@ -431,29 +432,29 @@ To use a Unix domain socket, an absolute path can be specified here."
(inputs (inputs
(list-of-mpd-plugin '()) (list-of-mpd-plugin '())
"List of MPD input plugin configurations." "List of MPD input plugin configurations."
(lambda (_ x) (serializer (lambda (_ x)
(mpd-serialize-list-of-mpd-plugin "input" x))) (mpd-serialize-list-of-mpd-plugin "input" x))))
(archive-plugins (archive-plugins
(list-of-mpd-plugin '()) (list-of-mpd-plugin '())
"List of MPD archive plugin configurations." "List of MPD archive plugin configurations."
(lambda (_ x) (serializer (lambda (_ x)
(mpd-serialize-list-of-mpd-plugin "archive_plugin" x))) (mpd-serialize-list-of-mpd-plugin "archive_plugin" x))))
(input-cache-size (input-cache-size
maybe-string maybe-string
"MPD input cache size." "MPD input cache size."
(lambda (_ x) (serializer (lambda (_ x)
(if (maybe-value-set? x) (if (maybe-value-set? x)
#~(string-append "\ninput_cache {\n" #~(string-append "\ninput_cache {\n"
#$(mpd-serialize-string "size" x) #$(mpd-serialize-string "size" x)
"}\n") ""))) "}\n") ""))))
(decoders (decoders
(list-of-mpd-plugin '()) (list-of-mpd-plugin '())
"List of MPD decoder plugin configurations." "List of MPD decoder plugin configurations."
(lambda (_ x) (serializer (lambda (_ x)
(mpd-serialize-list-of-mpd-plugin "decoder" x))) (mpd-serialize-list-of-mpd-plugin "decoder" x))))
(resampler (resampler
maybe-mpd-plugin maybe-mpd-plugin
@ -462,8 +463,8 @@ To use a Unix domain socket, an absolute path can be specified here."
(filters (filters
(list-of-mpd-plugin '()) (list-of-mpd-plugin '())
"List of MPD filter plugin configurations." "List of MPD filter plugin configurations."
(lambda (_ x) (serializer (lambda (_ x)
(mpd-serialize-list-of-mpd-plugin "filter" x))) (mpd-serialize-list-of-mpd-plugin "filter" x))))
(outputs (outputs
(list-of-mpd-plugin-or-output (list (mpd-output))) (list-of-mpd-plugin-or-output (list (mpd-output)))
@ -473,8 +474,8 @@ By default this is a single output using pulseaudio.")
(playlist-plugins (playlist-plugins
(list-of-mpd-plugin '()) (list-of-mpd-plugin '())
"List of MPD playlist plugin configurations." "List of MPD playlist plugin configurations."
(lambda (_ x) (serializer (lambda (_ x)
(mpd-serialize-list-of-mpd-plugin "playlist_plugin" x))) (mpd-serialize-list-of-mpd-plugin "playlist_plugin" x))))
(extra-options (extra-options
(alist '()) (alist '())

View File

@ -213,9 +213,10 @@ option in fstab are skipped.")
maybe-list-of-strings maybe-list-of-strings
"Extra options to append to @command{fstrim} (run @samp{man fstrim} for "Extra options to append to @command{fstrim} (run @samp{man fstrim} for
more information)." more information)."
(lambda (_ value) (serializer
(if (maybe-value-set? value) (lambda (_ value)
value '()))) (if (maybe-value-set? value)
value '()))))
(prefix fstrim-)) (prefix fstrim-))
(define (serialize-fstrim-configuration config) (define (serialize-fstrim-configuration config)

View File

@ -200,7 +200,7 @@
"Backend to use to detect changes in the @code{log-path}. The default is "Backend to use to detect changes in the @code{log-path}. The default is
'auto. To consult the defaults of the jail configuration, refer to the 'auto. To consult the defaults of the jail configuration, refer to the
@file{/etc/fail2ban/jail.conf} file of the @code{fail2ban} package." @file{/etc/fail2ban/jail.conf} file of the @code{fail2ban} package."
fail2ban-jail-configuration-serialize-backend) (serializer fail2ban-jail-configuration-serialize-backend))
(max-retry (max-retry
maybe-integer maybe-integer
"The number of failures before a host get banned "The number of failures before a host get banned
@ -269,7 +269,7 @@ names matching their filter name.")
maybe-symbol maybe-symbol
"The encoding of the log files handled by the jail. "The encoding of the log files handled by the jail.
Possible values are: @code{'ascii}, @code{'utf-8} and @code{'auto}." Possible values are: @code{'ascii}, @code{'utf-8} and @code{'auto}."
fail2ban-jail-configuration-serialize-log-encoding) (serializer fail2ban-jail-configuration-serialize-log-encoding))
(log-path (log-path
(list-of-strings '()) (list-of-strings '())
"The file names of the log files to be monitored.") "The file names of the log files to be monitored.")
@ -280,7 +280,7 @@ Possible values are: @code{'ascii}, @code{'utf-8} and @code{'auto}."
(text-config '()) (text-config '())
"Extra content for the jail configuration, provided as a list of file-like "Extra content for the jail configuration, provided as a list of file-like
objects." objects."
serialize-text-config) (serializer serialize-text-config))
(prefix fail2ban-jail-configuration-)) (prefix fail2ban-jail-configuration-))
(define list-of-fail2ban-jail-configurations? (define list-of-fail2ban-jail-configurations?

View File

@ -82,6 +82,9 @@
(format #f "~a = ~a;" name value)) (format #f "~a = ~a;" name value))
(define-configuration serializable-configuration (define-configuration serializable-configuration
(port (number 80) "The port number." (serializer custom-number-serializer)))
(define-configuration serializable-configuration-deprecated
(port (number 80) "The port number." custom-number-serializer)) (port (number 80) "The port number." custom-number-serializer))
(test-assert "serialize-configuration" (test-assert "serialize-configuration"
@ -89,8 +92,14 @@
(let ((config (serializable-configuration))) (let ((config (serializable-configuration)))
(serialize-configuration config serializable-configuration-fields)))) (serialize-configuration config serializable-configuration-fields))))
(test-assert "serialize-configuration [deprecated]"
(gexp?
(let ((config (serializable-configuration-deprecated)))
(serialize-configuration
config serializable-configuration-deprecated-fields))))
(define-configuration serializable-configuration (define-configuration serializable-configuration
(port (number 80) "The port number." custom-number-serializer) (port (number 80) "The port number." (serializer custom-number-serializer))
(no-serialization)) (no-serialization))
(test-assert "serialize-configuration with no-serialization" (test-assert "serialize-configuration with no-serialization"