[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Expanding service procedure to accept additional arguments
From: |
Ryan Sundberg |
Subject: |
Re: Expanding service procedure to accept additional arguments |
Date: |
Thu, 5 Jan 2023 12:00:09 -0800 (PST) |
Hi Bruno,
I have written some useful macros for transforming services as you describe
here. You may find them useful:
https://lab.arctype.co/poseidon/poseidon-os/-/blob/master/poseidon/services/base.scm
Sincerely,
Ryan Sundberg
Dec 28, 2022 8:48:15 AM mirai <mirai@makinata.eu>:
> 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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Expanding service procedure to accept additional arguments,
Ryan Sundberg <=