Subject: Herd `fport_write: Broken pipe` error when running `guix home reconfigure`

From: Elias Kueny <[email-masked]>
Date: Sat, 09 Sep 2023 16:09:46 +0000

I experience the same thing. I hadn't updated guix since may (last generation was commit 91bfd30ee3f35dfb7048bf42aea92f939cffbf17), and since I did I'm encountering issues with shepherd.

Probably unrelated, but for the record: my first issue was caused by the disappearance of the XDG_LOG_HOME environment variable. I was using it in the definition of shepherd services (as for example `#:log-file (string-append (getenv "XDG_LOG_HOME") "/emacs-daemon.log")`. Guix home reconfigure worked because the getenv wasn't evaluated immediately, but after a reboot the syntax error prevented shepherd to start the session.

But once I solved that, same problems: shepherd seems to hang somewhere after starting the home services.

herd status:
--8<---------------cut here---------------start------------->8---
Started:
 + root
Starting:
 ^ emacs-daemon
 ^ ssh-agent
 ^ syncthing
--8<---------------cut here---------------end--------------->8---

~/.local/state/log/shepherd.log:
--8<---------------cut here---------------start------------->8---
2023-09-09 16:12:42 Service root started.
2023-09-09 16:12:42 Service root running with value #t.
2023-09-09 16:12:42 Service root has been started.
2023-09-09 16:12:42 Daemonizing...
2023-09-09 16:12:42 Restarting signal handler.
2023-09-09 16:12:42 Now running as process 430.
2023-09-09 16:12:42 Starting services...
2023-09-09 16:12:42 Configuration successfully loaded from '/gnu/store/mq01z0gvi1zv3skk6xh1q7g4id6hsgdk-shepherd.conf'.
2023-09-09 16:12:42 Starting service ssh-agent...
2023-09-09 16:12:42 Starting service syncthing...
2023-09-09 16:12:42 Starting service emacs-daemon...
2023-09-09 16:12:42 Service ssh-agent has been started.
2023-09-09 16:12:42 Service syncthing has been started.
--- guix home reconfigure happened here ---
2023-09-09 16:59:00 Service emacs-daemon has been started.
2023-09-09 16:59:00 SSSL2023-09-09 16:59:00 oading /gnu/store/mlvqhkb37zy3yycriv3lmqah7yff34af-shepherd.conf.
--8<---------------cut here---------------end--------------->8---

My 3 services are working normally. If I try to run `herd restart emacs-daemon`, the command hangs until I press Ctrl-C and nothing happens to emacs. Same thing for the other services (and for `herd stop`).

Here's how my services are defined. If I comment out all occurrences of `home-shepherd-service-type` in my home configuration (not just commenting %emacs-daemon-user-service and running it with an empty list of services), then there is no error when running `guix home reconfigure`.

--8<---------------cut here---------------start------------->8---
(define %emacs-daemon-user-service
  (shepherd-service
   (documentation "Run emacs-daemon.")
   (provision '(emacs-daemon))
   (start #~(make-forkexec-constructor
             (list #$(file-append (specification->package %emacs-package) "/bin/emacs") "--fg-daemon")
             #:log-file (string-append #$(getenv "HOME") "/.local/var/log/emacs-daemon.log")))
   (stop #~(make-system-destructor "emacsclient --eval \"(kill-emacs)\""))
   (auto-start? #t)
   (respawn? #t)))

(define-public emacs-services
  (list (simple-service 'emacs-shepherd-service
                         home-shepherd-service-type
                         (list %emacs-daemon-user-service))))

(home-environment (services `(,@emacs-services […])))
--8<---------------cut here---------------end--------------->8---

When reconfiguring with an home-shepherd-service-type service but not shepherd service in the list:

--8<---------------cut here---------------start------------->8---
Finished updating symlinks.

Loading /gnu/store/26jgrxzmabjdl3nhjx16cqa1f5h3flks-shepherd.conf.
herd: error: exception caught while executing 'load' on service 'root':
In procedure fport_write: Broken pipe
Comparing /gnu/store/4vmxyl8fykz9wkrkicnv5azhvr1gb5i1-home/profile/share/fonts and
          /gnu/store/3wlqdh4i4zmwjmqa69isr62nvbgf7abh-home/profile/share/fonts... done (same)
Comparing /gnu/store/4vmxyl8fykz9wkrkicnv5azhvr1gb5i1-home/files/.config/fish/fish_plugins and
          /gnu/store/3wlqdh4i4zmwjmqa69isr62nvbgf7abh-home/files/.config/fish/fish_plugins... done (same)
Evaluating on-change gexps.

On-change gexps evaluation finished.
--8<---------------cut here---------------end--------------->8---

Only new line in ~/.local/state/log/shepherd.log:
--8<---------------cut here---------------start------------->8---
2023-09-09 17:45:07 Loading /gnu/store/26jgrxzmabjdl3nhjx16cqa1f5h3flks-shepherd.conf.
--8<---------------cut here---------------end--------------->8---

/gnu/store/26jgrxzmabjdl3nhjx16cqa1f5h3flks-shepherd.conf:
--8<---------------cut here---------------start------------->8---
(begin (use-modules (srfi srfi-34) (system repl error-handling)) (apply register-services (map (lambda (file) (load file)) (quote ()))) (action (quote root) (quote daemonize)) (format #t "Starting services...~%") (let ((services-to-start (quote ()))) (if (defined? (quote start-in-the-background)) (start-in-the-background services-to-start) (for-each start services-to-start)) (redirect-port (open-input-file "/dev/null") (current-input-port))))
--8<---------------cut here---------------end--------------->8---

So I would guess it's a problem in home-shepherd-service-type, and not in the custom service definitions. I also remember the broken pipe error showing previously, but shepherd commands hanging is new.