1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu services dmd)
20 #:use-module (guix ui)
21 #:use-module (guix sets)
22 #:use-module (guix gexp)
23 #:use-module (guix store)
24 #:use-module (guix monads)
25 #:use-module (guix records)
26 #:use-module (guix derivations) ;imported-modules, etc.
27 #:use-module (gnu services)
28 #:use-module (gnu packages admin)
29 #:use-module (ice-9 match)
30 #:use-module (srfi srfi-1)
31 #:use-module (srfi srfi-34)
32 #:use-module (srfi srfi-35)
33 #:export (dmd-root-service-type
39 dmd-service-documentation
41 dmd-service-requirement
45 dmd-service-auto-start?))
49 ;;; Instantiating system services as a dmd configuration file.
54 (define (dmd-boot-gexp services)
55 (mlet %store-monad ((dmd-conf (dmd-configuration-file services)))
57 ;; Keep track of the booted system.
58 (false-if-exception (delete-file "/run/booted-system"))
59 (symlink (readlink "/run/current-system")
62 ;; Close any remaining open file descriptors to be on the safe
63 ;; side. This must be the very last thing we do, because
64 ;; Guile has internal FDs such as 'sleep_pipe' that need to be
68 (false-if-exception (close-fdes fd))
72 (execl (string-append #$dmd "/bin/dmd")
73 "dmd" "--config" #$dmd-conf)))))
75 (define dmd-root-service-type
78 ;; Extending the root dmd service (aka. PID 1) happens by concatenating the
79 ;; list of services provided by the extensions.
82 (extensions (list (service-extension boot-service-type dmd-boot-gexp)))))
84 (define %dmd-root-service
85 ;; The root dmd service, aka. PID 1. Its parameter is a list of
86 ;; <dmd-service> objects.
87 (service dmd-root-service-type '()))
89 (define-syntax-rule (dmd-service-type service-name proc)
90 "Return a <service-type> denoting a simple dmd service--i.e., the type for a
91 service that extends DMD-ROOT-SERVICE-TYPE and nothing else."
95 (list (service-extension dmd-root-service-type
96 (compose list proc))))))
98 (define-record-type* <dmd-service>
99 dmd-service make-dmd-service
101 (documentation dmd-service-documentation ;string
102 (default "[No documentation.]"))
103 (provision dmd-service-provision) ;list of symbols
104 (requirement dmd-service-requirement ;list of symbols
106 (respawn? dmd-service-respawn? ;Boolean
108 (start dmd-service-start) ;g-expression (procedure)
109 (stop dmd-service-stop ;g-expression (procedure)
110 (default #~(const #f)))
111 (auto-start? dmd-service-auto-start? ;Boolean
115 (define (assert-no-duplicates services)
116 "Raise an error if SERVICES provide the same dmd service more than once.
118 This is a constraint that dmd's 'register-service' verifies but we'd better
119 verify it here statically than wait until PID 1 halts with an assertion
121 (fold (lambda (service set)
122 (define (assert-unique symbol)
123 (when (set-contains? set symbol)
127 (format #f (_ "service '~a' provided more than once")
130 (for-each assert-unique (dmd-service-provision service))
131 (fold set-insert set (dmd-service-provision service)))
135 (define (dmd-configuration-file services)
136 "Return the dmd configuration file for SERVICES."
138 ;; Extra modules visible to dmd.conf.
139 '((guix build syscalls)
140 (gnu build file-systems)
143 (assert-no-duplicates services)
145 (mlet %store-monad ((modules (imported-modules modules))
146 (compiled (compiled-modules modules)))
149 (eval-when (expand load eval)
150 (set! %load-path (cons #$modules %load-path))
151 (set! %load-compiled-path
152 (cons #$compiled %load-compiled-path)))
154 (use-modules (ice-9 ftw)
155 (guix build syscalls)
157 ((gnu build file-systems)
158 #:select (check-file-system canonicalize-device-spec)))
161 #$@(map (lambda (service)
163 #:docstring '#$(dmd-service-documentation service)
164 #:provides '#$(dmd-service-provision service)
165 #:requires '#$(dmd-service-requirement service)
166 #:respawn? '#$(dmd-service-respawn? service)
167 #:start #$(dmd-service-start service)
168 #:stop #$(dmd-service-stop service)))
171 ;; guix-daemon 0.6 aborts if 'PATH' is undefined, so work around it.
172 (setenv "PATH" "/run/current-system/profile/bin")
174 (format #t "starting services...~%")
176 '#$(append-map dmd-service-provision
177 (filter dmd-service-auto-start?
180 (gexp->file "dmd.conf" config)))
182 ;;; dmd.scm ends here