diff mbox series

[bug#49419,4/4] home-services: Add fold-home-service-types function

Message ID 87pmvwhio6.fsf@trop.in
State New
Headers show
Series Essential home services | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Andrew Tropin July 5, 2021, 3:41 p.m. UTC
* gnu/home-services.scm (parent-directory, %guix-home-root-directory,
%service-type-path, all-home-service-modules, fold-home-service-types): New
variables.
---
 gnu/home-services.scm | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
diff mbox series

Patch

diff --git a/gnu/home-services.scm b/gnu/home-services.scm
index 20a9537650..a06cd72459 100644
--- a/gnu/home-services.scm
+++ b/gnu/home-services.scm
@@ -444,3 +444,29 @@  environment, and its configuration file, when available.")))
 
 (define sexp->home-provenance sexp->system-provenance)
 (define home-provenance system-provenance)
+
+
+;;;
+;;; Searching
+;;;
+
+(define (parent-directory directory)
+  "Get the parent directory of DIRECTORY"
+  (string-join (drop-right (string-split directory #\/) 1) "/"))
+
+(define %guix-home-root-directory
+  ;; Absolute file name of the module hierarchy.
+  (parent-directory (dirname (search-path %load-path "gnu/home-services.scm"))))
+
+(define %service-type-path
+  ;; Search path for service types.
+  (make-parameter `((,%guix-home-root-directory . "gnu/home-services"))))
+
+(define (all-home-service-modules)
+  "Return the default set of home-service modules."
+  (cons (resolve-interface '(gnu home-services))
+        (all-modules (%service-type-path)
+                     #:warn warn-about-load-error)))
+
+(define* (fold-home-service-types proc seed)
+  (fold-service-types proc seed (all-home-service-modules)))