* Expanding service procedure to accept additional arguments
@ 2022-12-28 16:46 mirai
2023-01-05 20:00 ` Ryan Sundberg
0 siblings, 1 reply; 2+ messages in thread
From: mirai @ 2022-12-28 16:46 UTC (permalink / raw)
To: guix-devel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Expanding service procedure to accept additional arguments
2022-12-28 16:46 Expanding service procedure to accept additional arguments mirai
@ 2023-01-05 20:00 ` Ryan Sundberg
0 siblings, 0 replies; 2+ messages in thread
From: Ryan Sundberg @ 2023-01-05 20:00 UTC (permalink / raw)
To: mirai; +Cc: guix-devel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-05 20:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-28 16:46 Expanding service procedure to accept additional arguments mirai
2023-01-05 20:00 ` Ryan Sundberg
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).