(define %default-service-module-path
  ;; Default search path for service modules.
  `((,%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)) ;private variable
        (module-variable module fields-variable-name))))    ;public variable

(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))

Generated by apteryx using scpaste at Wed May 27 21:41:18 2026. JST. (original)