[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Expanding service procedure to accept additional arguments

From: mirai
Subject: Expanding service procedure to accept additional arguments
Date: Wed, 28 Dec 2022 16:46:32 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0

It is occasionally desired to have a service depend on additional shepherd 
than the defaults listed in their definition.

Examples where this can be seen is the shepherd-requirement field provided by
nginx-configuration and opensmtpd-configuration, but these fields are 
specific and not available for the other service types (unless patched in).

An alternative to patching the original record-type is to define a custom 
record-type and inheriting it which is somewhat clunky for what amounts to a 
single line change:

--8<---------------cut here---------------start------------->8---
-   (requirement `(...))
+   (requirement `(... ,@shepherd-requirement))
--8<---------------cut here---------------end--------------->8---

Another type of extensibility that should be considered is the capability to 
add extra
service-extensions to existing service-type records.
These can be useful for setup-specific (i.e. not applicable in general to be 
included with Guix) scenarios,
for example, to add an extra activation-service-type extension or have a 
extension that the service-type usually does not have.

The current approach that I'm aware of to achieve something similar is through
simple-service, drawbacks being extra boilerplate code and a "disjoint" service
whose connection to the "parent service" is not immediately apparent.

--8<---------------cut here---------------start------------->8---
;; Ideally this should go in radicale-service-type
          (simple-service 'chmod-radicale shepherd-root-service-type
                          (list (shepherd-service (requirement '(user-homes))
                                                  (provision '(radicale-home))
                                                  (documentation "chmod g+rwx 
to user 'radicale' home.")
                                                  (one-shot? #t)
                                                  (start #~(lambda _
                                                             (chmod (passwd:dir 
(getpw "radicale")) #o770)
--8<---------------cut here---------------end--------------->8---

Instead, what if the service procedure could be changed to accept optional 
keyword arguments?
Then one could express the extensions and dependencies as:

--8<---------------cut here---------------start------------->8---
  (service foo-service-type
           #:requirements '(networking nscd smtpd)
           #:extensions (list (service-extension bar-service-type (lambda _ 
                              (service-extension activation-service-type 
(lambda _ ...))))
--8<---------------cut here---------------end--------------->8---



reply via email to

[Prev in Thread] Current Thread [Next in Thread]