A service type is a node in the DAG described above. Let us start with a simple example, the service type for the Guix build daemon (see Invoking guix-daemon):
(define guix-service-type (service-type (name 'guix) (extensions (list (service-extension shepherd-root-service-type guix-shepherd-service) (service-extension account-service-type guix-accounts) (service-extension activation-service-type guix-activation))) (default-value (guix-configuration))))
It defines three things:
Every service type has at least one service extension. The only exception is the boot service type, which is the ultimate service.
In this example, guix-service-type extends three services:
The guix-shepherd-service procedure defines how the Shepherd
service is extended. Namely, it returns a
object that defines how
guix-daemon is started and stopped
(see Shepherd Services).
This extension for this service is computed by guix-accounts,
which returns a list of
objects representing the build user accounts (see Invoking guix-daemon).
Here guix-activation is a procedure that returns a gexp, which is a code snippet to run at “activation time”—e.g., when the service is booted.
A service of this type is instantiated like this:
(service guix-service-type (guix-configuration (build-accounts 5) (use-substitutes? #f)))
The second argument to the
service form is a value representing
the parameters of this specific service instance.
information about the
guix-configuration data type. When the
value is omitted, the default value specified by
guix-service-type is used:
guix-service-type is quite simple because it extends other services but is not extensible itself.
The service type for an extensible service looks like this:
(define udev-service-type (service-type (name 'udev) (extensions (list (service-extension shepherd-root-service-type udev-shepherd-service))) (compose concatenate) ;concatenate the list of rules (extend (lambda (config rules) (match config (($ <udev-configuration> udev initial-rules) (udev-configuration (udev udev) ;the udev package to use (rules (append initial-rules rules)))))))))
This is the service type for the eudev device management daemon. Compared to the previous example, in addition to an extension of shepherd-root-service-type, we see two new fields:
This is the procedure to compose the list of extensions to services of this type.
Services can extend the udev service by passing it lists of rules; we compose those extensions simply by concatenating them.
This procedure defines how the value of the service is extended with the composition of the extensions.
Udev extensions are composed into a list of rules, but the udev service
value is itself a
<udev-configuration> record. So here, we
extend that record by appending the list of rules it contains to the
list of contributed rules.
This is a string giving an overview of the service type. The string can
contain Texinfo markup (see Overview in GNU Texinfo). The
guix system search command searches these strings and displays
them (see Invoking guix system).
There can be only one instance of an extensible service type such as
udev-service-type. If there were more, the
service-extension specifications would be ambiguous.
Still here? The next section provides a reference of the programming interface for services.