From: jbranso@dismail.de
To: "Fredrik Salomonsson" <plattfot@posteo.net>,
"help-guix" <help-guix@gnu.org>
Subject: Re: Shepherd environment question
Date: Wed, 08 Jan 2025 13:49:13 +0000 [thread overview]
Message-ID: <318957a3fcd213580542bb223cb7f6e7de7a9200@dismail.de> (raw)
In-Reply-To: <875xmsfvvn.fsf@posteo.net>
January 5, 2025 at 10:45 PM, "Fredrik Salomonsson" <plattfot@posteo.net mailto:plattfot@posteo.net?to=%22Fredrik%20Salomonsson%22%20%3Cplattfot%40posteo.net%3E > wrote:
>
> Hi Guix,
>
> After reading the Shepherd 1.0.0 blog post [0], it got me thinking that
> with the log rotation etc it would be nice to let shepherd handle sway
> and the programs it launches.
>
> As right now I got a simple line in my ~/.bash_profile that if logging
> in to tty1 exec sway. And all the output from sway and its program just
> outputs into the ether.
>
> So I migrated all the programs that sway launches from the config to
> shepherd services. And made a shepherd service for sway but disable the
> auto-start for it. So that I can kick it off with my .bash_profile:
If guix doesn't already have a sway-service (home-service or system
service), then it might be a good idea to throw this patch to
guix-patches@gnu.org.
Joshua
>
> Sway launches fine when I login, and I can now see some logs when
> checking the status:
>
> ```
> herd status sway
> ● Status of sway:
> It is running since 18:45:58 (27 seconds ago).
> Main PID: 1100
> Command: /gnu/store/c990qdj2nqcgfif7qs2gnyfbshskkp4y-sway-1.10/bin/sway
> It is enabled.
> Provides: sway
> Will be respawned.
> Log file: /home/plattfot/.local/state/log/sway.log
>
> Recent messages (use '-n' to view more or less):
> 2025-01-05 18:46:15 (process:1425): GLib-CRITICAL **: 18:46:15.714: g_string_insert_len: assertion 'len == 0 || val != NULL' failed
> 2025-01-05 18:46:15 00:00:16.666 [ERROR] [wlr] [xwayland/xwm.c:1500] Unhandled message 'new: ID=rofi/|gnu|store|9z44nwi28zvw3cay7m9q6388b26d74kd-emacs-pgtk-29.4|bin|emacs/1425-0-surt_TIME43379 SCREEN=0 NAME=Emacs DESCRIPTION=Launching\ '/gnu/store/9z44nwi28zvw3cay7m9q6388b26d74kd-emacs-pgtk-29.4/bin/emacs'\ via\ rofi WMCLASS=Emacs BIN=/gnu/store/9z44nwi28zvw3cay7m9q6388b26d74kd-emacs-pgtk-29.4/bin/emacs ICON=emacs APPLICATION_ID=emacs'
> 2025-01-05 18:46:15
> 2025-01-05 18:46:15 00:00:16.666 [ERROR] [wlr] [xwayland/xwm.c:1633] xcb error: op ChangeWindowAttributes (no minor), code Window (no extension), sequence 173, value 4194320
> 2025-01-05 18:46:21 warn: wayland.c:1619: compositor does not implement the XDG toplevel icon protocol
>
> ```
>
> Pretty cool! 🤓
>
> However, the programs that requires a running wayland session did not
> go that well — for example mako and swayidle. Here is a line from the
> swayidle log:
>
> ```
> 2025-01-05 18:29:34 2025-01-05 18:29:34 - [Line 1096] Unable to connect to the compositor. If your compositor is running, check or set the WAYLAND_DISPLAY environment variable.
> ```
>
> What I think I need to do to run them properly, is to run them in the
> environment sway creates. The `make-forkexec-constructor` does have a
> `#:environment-variables` argument so I need to somehow extract the
> environment variables required from the sway service and feed that into
> the constructor for the services that require a wayland session. Anyone
> have any idea how to set that up? Or am I going about this the wrong way?
>
> Thanks!
>
> Here is what I got so far:
>
> ~/.bash_profile
> ```
> # Start sway when logging in on tty
> if [ "$(tty)" = "/dev/tty1" ]; then
> herd start sway
> fi
>
> ```
>
> My sway shepherd services:
> ```
> (define-configuration/no-serialization plt-sway-configuration
> (turn-off-displays?
> (boolean #t)
> "Specify if it should turn off the displays when the machine is idle."))
>
> (define (plt-sway-shepherd config)
> (list
> (shepherd-service
> (provision '(sway))
> (documentation "Start sway")
> (auto-start? #f)
> (start #~(make-forkexec-constructor
> (list (string-append #$sway "/bin/sway"))
> #:log-file (format #f "~a/log/sway.log"
> (getenv "XDG_STATE_HOME"))))
> (stop #~(make-kill-destructor)))
> (let ((turn-off-displays? (plt-sway-configuration-turn-off-displays? config)))
> (shepherd-service
> (requirement '(sway))
> (provision '(swayidle))
> (documentation (string-append "Lock screen after 5 min"
> (if turn-off-displays?
> "and turn them off after 10 min."
> ".")))
> (start #~(make-forkexec-constructor
> (append
> (list (string-append #$swayidle "/bin/swayidle") "-w")
> (if #$turn-off-displays?
> '("timeout" "600" "swaymsg 'output * dpms off'"
> "resume" "swaymsg 'output * dpms on'")
> '())
> (list "timeout" "300" (string-append #$swaylock "/bin/swaylock -f -c 000000")
> "before-sleep" (string-append #$swaylock "/bin/swaylock -f -c 000000")))
> #:log-file (format #f "~a/log/swayidle.log" (getenv "XDG_STATE_HOME"))))
> (stop #~(make-kill-destructor))))
> (shepherd-service
> (provision '(waybar))
> (requirement '(sway))
> (documentation "Start waybar.")
> (start #~(make-forkexec-constructor
> (list (string-append #$waybar "/bin/waybar"))
> #:log-file (format #f "~a/log/waybar.log"
> (getenv "XDG_STATE_HOME"))))
> (stop #~(make-kill-destructor)))
> (shepherd-service
> (provision '(mako))
> (requirement '(sway))
> (documentation "Start mako; lightweight Wayland notification daemon.")
> (start #~(make-forkexec-constructor
> (list (string-append #$mako "/bin/mako"))
> #:log-file (format #f "~a/log/mako.log"
> (getenv "XDG_STATE_HOME"))))
> (stop #~(make-kill-destructor)))
> (shepherd-service
> (provision '(dbus-update-activation-environment))
> (requirement '(dbus sway))
> (documentation "Tell dbus that we are using sway")
> (one-shot? #t)
> (start #~(make-forkexec-constructor
> (list (string-append #$dbus "/bin/dbus-update-activation-environment")
> "DISPLAY SWAYSOCK"
> "WAYLAND_DISPLAY"
> "XDG_CURRENT_DESKTOP=sway")
> #:log-file (format #f "~a/log/dbus-activate-environment.log"
> (getenv "XDG_STATE_HOME"))))
> (stop #~(make-kill-destructor)))
> (shepherd-service
> (requirement '(sway))
> (provision '(playerctld))
> (documentation "Controll the latest active player over MPRIS")
> (start #~(make-forkexec-constructor
> (list (string-append #$playerctl "/bin/playerctld"))
> #:log-file (format #f "~a/log/playerctld.log" (getenv "XDG_STATE_HOME"))))
> (stop #~(make-kill-destructor)))))
> ```
>
> [0] https://guix.gnu.org/blog/2024/the-shepherd-1.0.0-released
>
> --
> s/Fred[re]+i[ck]+/Fredrik/g
>
next prev parent reply other threads:[~2025-01-08 13:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-06 3:45 Shepherd environment question Fredrik Salomonsson
2025-01-08 13:49 ` jbranso [this message]
2025-01-08 18:05 ` Fredrik Salomonsson
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=318957a3fcd213580542bb223cb7f6e7de7a9200@dismail.de \
--to=jbranso@dismail.de \
--cc=help-guix@gnu.org \
--cc=plattfot@posteo.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).