unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ryan Sundberg <ryan@arctype.co>
To: mirai <mirai@makinata.eu>
Cc: guix-devel@gnu.org
Subject: Re: Expanding service procedure to accept additional arguments
Date: Thu, 5 Jan 2023 12:00:09 -0800 (PST)	[thread overview]
Message-ID: <06384d87-f628-4b78-af7a-1ba199b98e85@arctype.co> (raw)
In-Reply-To: <eed5454c-9ac4-a5a6-4a4d-a6d8b633afb1@makinata.eu>

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


      reply	other threads:[~2023-01-05 20:01 UTC|newest]

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

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=06384d87-f628-4b78-af7a-1ba199b98e85@arctype.co \
    --to=ryan@arctype.co \
    --cc=guix-devel@gnu.org \
    --cc=mirai@makinata.eu \
    /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).