services: Missing services are automatically instantiated.

This simplifies OS configuration: users no longer need to be aware of
what a given service depends on.

See the discussion at
<https://lists.gnu.org/archive/html/guix-devel/2018-01/msg00114.html>.

* gnu/services.scm (missing-target-error): New procedure.
(service-back-edges): Use it.
(instantiate-missing-services): New procedure.
* gnu/system.scm (operating-system-services): Call
'instantiate-missing-services'.
* tests/services.scm ("instantiate-missing-services")
("instantiate-missing-services, no default value"): New tests.
* gnu/services/version-control.scm (cgit-service-type)[extensions]: Add
FCGIWRAP-SERVICE-TYPE.
* gnu/tests/version-control.scm (%cgit-os): Remove NGINX-SERVICE-TYPE
and FCGIWRAP-SERVICE-TYPE instances.
* doc/guix.texi (Log Rotation): Remove 'mcron-service-type' in example.
(Miscellaneous Services): Remove 'nginx-service-type' and
'fcgiwrap-service-type' in Cgit example.
This commit is contained in:
Ludovic Courtès 2018-01-21 00:05:09 +01:00
parent bc58201ec2
commit d466b1fc82
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
6 changed files with 90 additions and 23 deletions

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@ -122,6 +122,36 @@
(fold-services (list s) #:target-type t1)
#f)))
(test-assert "instantiate-missing-services"
(let* ((t1 (service-type (name 't1) (extensions '())
(default-value 'dflt)
(compose concatenate)
(extend cons)))
(t2 (service-type (name 't2)
(extensions
(list (service-extension t1 list)))))
(s1 (service t1 'hey!))
(s2 (service t2 42)))
(and (lset= equal?
(list (service t1) s2)
(instantiate-missing-services (list s2)))
(equal? (list s1 s2)
(instantiate-missing-services (list s1 s2))))))
(test-assert "instantiate-missing-services, no default value"
(let* ((t1 (service-type (name 't1) (extensions '())))
(t2 (service-type (name 't2)
(extensions
(list (service-extension t1 list)))))
(s (service t2 42)))
(guard (c ((missing-target-service-error? c)
(and (eq? (missing-target-service-error-target-type c)
t1)
(eq? (missing-target-service-error-service c)
s))))
(instantiate-missing-services (list s))
#f)))
(test-assert "shepherd-service-lookup-procedure"
(let* ((s1 (shepherd-service (provision '(s1 s1b)) (start #f)))
(s2 (shepherd-service (provision '(s2 s2b)) (start #f)))