Re: Service refactoring

From: Ludovic Courtès Subject: Re: Service refactoring Date: Sun, 20 Sep 2015 17:42:47 +0200 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Currently that ’wip-service-refactor’ contains a first implementation of the “service DAG”. So far I only “converted” services in (gnu services base); modulo the yet-to-be-converted services, it looks like this:

“Service” here has a much broader meaning than before. There’s a service for PAM services, one for user accounts, one for dmd services, one for /etc entries, one for activation snippets, and finally the “boot” service. The PAM root service collects PAM services produced by lshd, mingetty, etc. and turns them into ‘pam.d’ entry for /etc; the /etc service takes such entries and turns them into a gexp that calls ‘activate-etc’. Likewise, the guix-daemon service passes user accounts and groups to the account service, which turns that into an activation snippet. The nice thing is that it allows us to express things that were not possible before, and increases separation of concerns. For instance, the ‘account’ service takes care of everything related to user accounts in a single place, whereas before this would be entangled in (gnu system); ditto for PAM services. The API defines <service-type>, <service-extension>, and <service>. The “service type” defines how services of this type are “extended” and/or how services of this type extend other services: (define dmd-root-service-type (service-type (name 'dmd-root) ;; Extending the root dmd service (aka. PID 1) happens by concatenating the ;; list of <dmd-service> provided by the extensions. (extend concatenate) (extensions (list (service-extension (target boot-service-type) (compute dmd-boot-gexp)))))) (define guix-service-type (service-type (name 'guix) (extensions (list (service-extension (target dmd-root-service-type) (compute guix-dmd-service)) (service-extension (target account-service-type) (compute guix-accounts)) (service-extension (target activation-service-type) (compute guix-activation)))))) The service procedures used in OS declarations can usually remain unchanged, written like this: (define* (guix-service #:optional (config %default-guix-configuration)) (service (type guix-service-type) (parameters config))) There can be several services of a given type. However, there must be only one service of a type that can be extended–for instance, there can be only one service of type ‘dmd-root-service-type’ or ‘etc-service-type’. The ‘fold-services’ procedure is passed a list of services, propagates extensions, and returns the root service (typically ‘%boot-service’) with its ‘parameters’ field changed accordingly. I’m quite happy with the result, but comments are welcome! I’ll convert some more services to see how it goes. Ludo’.