summary refs log tree commit diff
path: root/gnu/services/dmd.scm
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2015-10-17 19:08:53 -0400
committerMark H Weaver <mhw@netris.org>2015-10-17 19:08:53 -0400
commitccb522324bd99cc379ada4a1da5b8bcfd7d12c5b (patch)
treebd73bf8f8dabc046c12c53295b18daad49379887 /gnu/services/dmd.scm
parent5fba12ecd3146e17d826167b6b9ffdfcbe2a49c9 (diff)
parent9e2592a3466c72dbfb64494e1316ce8af1554647 (diff)
downloadguix-ccb522324bd99cc379ada4a1da5b8bcfd7d12c5b.tar.gz
Merge branch 'master' into dbus-update
Diffstat (limited to 'gnu/services/dmd.scm')
-rw-r--r--gnu/services/dmd.scm73
1 files changed, 53 insertions, 20 deletions
diff --git a/gnu/services/dmd.scm b/gnu/services/dmd.scm
index 6020ffc8eb..e87b9e4415 100644
--- a/gnu/services/dmd.scm
+++ b/gnu/services/dmd.scm
@@ -27,7 +27,9 @@
   #:use-module (gnu services)
   #:use-module (gnu packages admin)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 vlist)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-34)
   #:use-module (srfi srfi-35)
   #:export (dmd-root-service-type
@@ -42,7 +44,9 @@
             dmd-service-respawn?
             dmd-service-start
             dmd-service-stop
-            dmd-service-auto-start?))
+            dmd-service-auto-start?
+
+            dmd-service-back-edges))
 
 ;;; Commentary:
 ;;;
@@ -86,11 +90,11 @@
   ;; <dmd-service> objects.
   (service dmd-root-service-type '()))
 
-(define-syntax-rule (dmd-service-type proc)
+(define-syntax-rule (dmd-service-type service-name proc)
   "Return a <service-type> denoting a simple dmd service--i.e., the type for a
 service that extends DMD-ROOT-SERVICE-TYPE and nothing else."
   (service-type
-   (name 'some-dmd-service)
+   (name service-name)
    (extensions
     (list (service-extension dmd-root-service-type
                              (compose list proc))))))
@@ -98,17 +102,17 @@ service that extends DMD-ROOT-SERVICE-TYPE and nothing else."
 (define-record-type* <dmd-service>
   dmd-service make-dmd-service
   dmd-service?
-  (documentation service-documentation            ; string
+  (documentation dmd-service-documentation        ;string
                  (default "[No documentation.]"))
-  (provision     service-provision)               ; list of symbols
-  (requirement   service-requirement              ; list of symbols
+  (provision     dmd-service-provision)           ;list of symbols
+  (requirement   dmd-service-requirement          ;list of symbols
                  (default '()))
-  (respawn?      service-respawn?                 ; Boolean
+  (respawn?      dmd-service-respawn?             ;Boolean
                  (default #t))
-  (start         service-start)                   ; g-expression (procedure)
-  (stop          service-stop                     ; g-expression (procedure)
+  (start         dmd-service-start)               ;g-expression (procedure)
+  (stop          dmd-service-stop                 ;g-expression (procedure)
                  (default #~(const #f)))
-  (auto-start?   service-auto-start?              ; Boolean
+  (auto-start?   dmd-service-auto-start?          ;Boolean
                  (default #t)))
 
 
@@ -127,8 +131,8 @@ failure."
                         (format #f (_ "service '~a' provided more than once")
                                 symbol)))))))
 
-          (for-each assert-unique (service-provision service))
-          (fold set-insert set (service-provision service)))
+          (for-each assert-unique (dmd-service-provision service))
+          (fold set-insert set (dmd-service-provision service)))
         (setq)
         services))
 
@@ -160,12 +164,12 @@ failure."
           (register-services
            #$@(map (lambda (service)
                      #~(make <service>
-                         #:docstring '#$(service-documentation service)
-                         #:provides '#$(service-provision service)
-                         #:requires '#$(service-requirement service)
-                         #:respawn? '#$(service-respawn? service)
-                         #:start #$(service-start service)
-                         #:stop #$(service-stop service)))
+                         #:docstring '#$(dmd-service-documentation service)
+                         #:provides '#$(dmd-service-provision service)
+                         #:requires '#$(dmd-service-requirement service)
+                         #:respawn? '#$(dmd-service-respawn? service)
+                         #:start #$(dmd-service-start service)
+                         #:stop #$(dmd-service-stop service)))
                    services))
 
           ;; guix-daemon 0.6 aborts if 'PATH' is undefined, so work around it.
@@ -173,9 +177,38 @@ failure."
 
           (format #t "starting services...~%")
           (for-each start
-                    '#$(append-map service-provision
-                                   (filter service-auto-start? services)))))
+                    '#$(append-map dmd-service-provision
+                                   (filter dmd-service-auto-start?
+                                           services)))))
 
     (gexp->file "dmd.conf" config)))
 
+(define (dmd-service-back-edges services)
+  "Return a procedure that, when given a <dmd-service> from SERVICES, returns
+the list of <dmd-service> that depend on it."
+  (define provision->service
+    (let ((services (fold (lambda (service result)
+                            (fold (cut vhash-consq <> service <>)
+                                  result
+                                  (dmd-service-provision service)))
+                          vlist-null
+                          services)))
+      (lambda (name)
+        (match (vhash-assq name services)
+          ((_ . service) service)
+          (#f            #f)))))
+
+  (define edges
+    (fold (lambda (service edges)
+            (fold (lambda (requirement edges)
+                    (vhash-consq (provision->service requirement) service
+                                 edges))
+                  edges
+                  (dmd-service-requirement service)))
+          vlist-null
+          services))
+
+  (lambda (service)
+    (vhash-foldq* cons '() service edges)))
+
 ;;; dmd.scm ends here