bug#65463: Herd `fport_write: Broken pipe` error when running `guix home reconfigure`

2024-03-21 Thread Richard Sent
Hi Ludo,

I tried replicating this issue on guix
d67e4f0f9b10c7ddac8fb0ca68cbf1d6ad0a6e5d and was not able to. My guess
is either shepherd 10.2->10.3 resolved the issue or there was a change in
fish.

It seems to work fine now, but I've not tested thoroughly. Hopefully
anyone else who can into the issue can chime in.

> (I assume this is the strace of shepherd, not herd.)

When you say this do you mean daemon vs. CLI process? I'm fairly
confident that was the strace of the daemon although I can't recall how
I pulled that off.

> Maybe we should unconditionally run shepherd with stdout/stderr
> redirected to /dev/null?
> 
> That would sidestep the problem and it’s probably a good idea anyway.

Would unconditionally redirecting to /dev/null mess with the system
shepherd? I noticed that stdout and stderr for my system shepherd (in
/proc/1/fd) are printing to /dev/console. If so that would probably make
debugging shepherd issues harder, particularly on something like a
single board computer.

Thanks for looking at this!

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





bug#67649: shepherd: (shepherd support) is visible for start GEXP

2024-03-21 Thread Ludovic Courtès
Hi,

Attila Lendvai  skribis:

> start GEXP's of services are loaded into unnamed modules. the definitions 
> from (shepherd support) are visible in these unnamed modules. see the 
> attached rerpoducer.

It’s more than (shepherd support):

--8<---cut here---start->8---
shepherd[1]: Starting service reproducer...
shepherd[1]: *** reproducer gexp speaking, current module: #, mor
face (oop goops) 7f2cf8a89c80> # 
# # 
# # 
# # 
# # # # # # # 
# # # # # # # # # # # 
# # 
# # 
# # 
# # # # # # 
# # #), ringbuffer: #
--8<---cut here---end--->8---

> is this indended? i.e. part of the shepherd API?

It’s not really intended.

In Guix, ‘shepherd-service’ instances have a ‘modules’ field.  Many,
like the one for mcron, have (shepherd support) there because they need
it for one thing or another.

Now, your ‘reproducer’ service has a default ‘modules’ field so why does
it see those modules anyway?

First, note that (current-module) called from the ‘start’ method does
*not* return the module where that ‘start’ method was defined.

Still, what we see here is that the module in which the shepherd config
file is evaluated has way more imports than expected.  This stems from
the way services get loaded on Guix System, in
‘shepherd-configuration-file’:

(register-services
 (parameterize ((current-warning-port
 (%make-void-port "w")))
   (map load-compiled '#$(map scm->go files

Thus, each one of ‘files’ augments the imports of the current module,
eventually leading to this import soup.

This is a Guix bug we can fix by loading each service file in a fresh
module:

diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm
index f5bcde721f..6b8527f0dc 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -383,6 +383,14 @@ (define (shepherd-configuration-file services shepherd)
   (use-modules (srfi srfi-34)
(system repl error-handling))
 
+  (define (make-user-module)
+;; Copied from (shepherd support), where it's private.
+(let ((m (make-fresh-user-module)))
+  ;; The typical configuration file wants to do '(service ...)', and
+  ;; '(register-services ...)', so provide the relevant bindings by default.
+  (module-use! m (resolve-interface '(shepherd service)))
+  m))
+
   ;; There's code run from shepherd that uses 'call-with-input-file' &
   ;; co.--e.g., the 'urandom-seed' service.  Starting from Shepherd
   ;; 0.9.2, users need to make sure not to leak non-close-on-exec file
@@ -416,7 +424,12 @@ (define (shepherd-configuration-file services shepherd)
   (register-services
(parameterize ((current-warning-port
(%make-void-port "w")))
- (map load-compiled '#$(map scm->go files))
+ (map (lambda (file)
+(save-module-excursion
+ (lambda ()
+   (set-current-module (make-user-module))
+   (load-compiled file
+  '#$(map scm->go files))
 
   (format #t "starting services...~%")
   (let ((services-to-start

There might be breakage due to services that currently get the modules
they need “by chance” (as a side effect of loading another module), but
at least this small sample works fine:

  make check-system TESTS="basic openssh nginx static-networking 
static-networking-advanced mcron hpcguix-web" -j4

I’ll push the patch soonish.

Thanks!

Ludo’.