unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: mirai <mirai@makinata.eu>
To: guix-devel@gnu.org
Subject: Expanding service procedure to accept additional arguments
Date: Wed, 28 Dec 2022 16:46:32 +0000	[thread overview]
Message-ID: <eed5454c-9ac4-a5a6-4a4d-a6d8b633afb1@makinata.eu> (raw)

It is occasionally desired to have a service depend on additional shepherd services
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 record-type
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 service-type
record-type and inheriting it which is somewhat clunky for what amounts to a setup-specific
single line change:

--8<---------------cut here---------------start------------->8---
  (shepherd-service
    ...
-   (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 special-files-service-type
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)
                                                             #t)))))
--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---
(services
  (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---

Thoughts?


Regards,
Bruno


             reply	other threads:[~2022-12-28 16:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-28 16:46 mirai [this message]
2023-01-05 20:00 ` Expanding service procedure to accept additional arguments Ryan Sundberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eed5454c-9ac4-a5a6-4a4d-a6d8b633afb1@makinata.eu \
    --to=mirai@makinata.eu \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).