unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: Richard Sent <richard@freakingpenguin.com>
To: Remco van 't Veer <remco@remworks.net>
Cc: Oleg Pykhalov <go.wigust@gmail.com>,  help-guix <help-guix@gnu.org>
Subject: Re: add shepherd requirement to an existing service?
Date: Thu, 14 Mar 2024 13:54:54 -0400	[thread overview]
Message-ID: <87ttl8wvf5.fsf@freakingpenguin.com> (raw)
In-Reply-To: <878r2n21dd.fsf@remworks.net> (Remco van t. Veer's message of "Tue, 12 Mar 2024 11:25:18 +0100")

If this winds up being something you do frequently, it may be possible
to write a function to modify the service type. See [1] as an example. I
suspect your code would be smaller, something like

--8<---------------cut here---------------start------------->8---
(define (depend-on type new-requirement)
  "Returns a @code{service-type} record derived from @var{type} with any
  shepherd extensions additionally depending on @var{new-requirement}."
  (service-type
   (inherit type)
   (extensions
    (map (lambda (extension)
           (let ((target (service-extension-target extension))
                 (compute (service-extension-compute extension)))
             (if (eq? target shepherd-root-service-type)
                 (service-extension shepherd-root-service-type
                                    (lambda (config)
                                      (map (lambda (service)
                                             (shepherd-service
                                              (inherit service)
                                              (requirement
                                               (cons*
                                                new-requirement
                                                (shepherd-service-requirement config)))))
                                           (compute config))))
                 extension)))
         (service-type-extensions type)))))
--8<---------------cut here---------------end--------------->8---

This code might not be it exactly, but something similar to this
/should/ work.

[1] https://git.sr.ht/~freakingpenguin/rsent/tree/master/item/channel/rsent/utils/services.scm


-- 
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.


  reply	other threads:[~2024-03-14 17:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 11:04 add shepherd requirement to an existing service? Remco van 't Veer
2024-03-11 18:59 ` Oleg Pykhalov
2024-03-12 10:25   ` Remco van 't Veer
2024-03-14 17:54     ` Richard Sent [this message]
2024-03-15  9:22       ` Remco van 't Veer

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=87ttl8wvf5.fsf@freakingpenguin.com \
    --to=richard@freakingpenguin.com \
    --cc=go.wigust@gmail.com \
    --cc=help-guix@gnu.org \
    --cc=remco@remworks.net \
    /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.
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).