Hi Alexander,

Apologies for the second email, but I forgot to Cc the list the first
time. Whoops!

On Tue, Aug 05 2025, Alexander Prähauser via wrote:
> The shepherd-manual specifies in the make-timer-constructor that
>
> "ACTION
> may be either a command (returned by ‘command’) or a thunk; in the
> latter case, the thunk must be suspendable or it could block the
> whole shepherd process."
>
> but this is the only place in that manual that the word "thunk"
> appears, I don't know what it is.

A thunk is just a procedure that takes zero arguments. The term is
defined in the Scheme standard (e.g. section 1.3.5 of R7RS), so I don't
think it's specifically defined in the Guix or Shepherd manuals.

Looking at the shepherd-timer helper in Guix, I don't think you can use
a thunk, though. It always uses "command" to wrap the gexp given to it,
so you'll have to use the lower-level shepherd-service primitives to do
it.

> So is it even possible to have timers that run Guile-functions, and if
> so, what is the correct syntax for that?

Something like this (untested, but taken mostly from the example in the
manual in "(guix) Scheduled Job Execution") might work:

--8<---------------cut here---------------start------------->8---
(shepherd-service
  (provision '(battery-notifier))
  (requirement '(user-processes))
  (modules '((shepherd service timer)))
  (start #~(make-timer-constructor
            (cron-string->calendar-event "0,10,20,30,40,50 * * * *")
            (lambda ()
              ;; You'll need to make sure this is available in the
              ;; gexp, possibly using with-imported-modules and
              ;; use-modules - see "(guix) G-Expressions" in the
              ;; manual for more details.
              (ahp-notify-when-battery-low))
            #:wait-for-termination? #t))
  (stop #~(make-timer-destructor))
  (documentation "Periodically check battery status.")
  (actions (list shepherd-trigger-action)))
--8<---------------cut here---------------end--------------->8---

> It would be really nice if an example of that were in the
> manual. There is a more involved example for mcron, but I'm not sure
> if it also applies to shepherd-timers and since I have to reboot each
> time this doesn't work I'm reluctant to try.

Restarting the relevant service (either the timer service, or mcron)
after a system reconfigure should load the new schedule. This should
make experimenting much cheaper. 🙂

Carlo

Reply via email to