home-services: Add fold-home-service-types function.
authorAndrew Tropin <andrew@trop.in>
Thu, 5 Aug 2021 05:47:40 +0000 (08:47 +0300)
committerOleg Pykhalov <go.wigust@gmail.com>
Thu, 9 Sep 2021 16:54:54 +0000 (19:54 +0300)
* gnu/home-services.scm (parent-directory, %guix-home-root-directory,
%service-type-path, all-home-service-modules, fold-home-service-types): New
variables.

Signed-off-by: Oleg Pykhalov <go.wigust@gmail.com>
gnu/home-services.scm

index d320d3a..16b9736 100644 (file)
@@ -492,3 +492,29 @@ environment, and its configuration file, when available.")))
 
 (define sexp->home-provenance sexp->system-provenance)
 (define home-provenance system-provenance)
+
+\f
+;;;
+;;; 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)))