(define %default-service-module-path
`((,%distro-root-directory . "gnu/services")))
(define (define-configuration? module symbol)
"Predicate to check if SYMBOL points to a `define-configuration'-generated
object in MODULE."
(let ((fields-variable-name (symbol-append symbol '-fields)))
(or (pk 'module-local-variable? module fields-variable-name (module-local-variable module fields-variable-name)) (module-variable module fields-variable-name))))
(define* (fold-configurations proc init
#:optional
(modules (all-modules %default-service-module-path
#:warn
warn-about-load-error))
#:key (select? (const #t)))
"Call (PROC MODULE SYMBOL RESULT) for each service configuration defined via
`define-configuration' in the MODULES that matches SELECT?, using INIT as the
initial value of RESULT. SELECT? is called with two arguments, the module
object as well as the variable name (a symbol) of the configuration record
constructor, e.g. @code{'forgejo-configuration}."
(fold-module-public-variables* (lambda (module symbol _ result)
(if (and (define-configuration? module symbol)
(select? module symbol))
(proc module symbol result)
result))
init
modules))