Next: , Previous: , Up: Defining Services   [Contents][Index]

12.18.2 Service Types and Services

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
   (name 'guix)
    (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:

  1. A name, whose sole purpose is to make inspection and debugging easier.
  2. A list of service extensions, where each extension designates the target service type and a procedure that, given the parameters of the service, returns a list of objects to extend the service of that type.

    Every service type has at least one service extension. The only exception is the boot service type, which is the ultimate service.

  3. Optionally, a default value for instances of this type.

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 <shepherd-service> 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 user-group and user-account 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
           (build-accounts 5)
           (extra-options '("--gc-keep-derivations"))))

The second argument to the service form is a value representing the parameters of this specific service instance. See guix-configuration, for information about the guix-configuration data type. When the value is omitted, the default value specified by guix-service-type is used:

(service guix-service-type)

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)
                 (list (service-extension shepherd-root-service-type

                (compose concatenate)       ;concatenate the list of rules
                (extend (lambda (config rules)
                          (match config
                            (($ <udev-configuration> udev initial-rules)
                              (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.

Next: Service Reference, Previous: Service Composition, Up: Defining Services   [Contents][Index]