January 5, 2025 at 10:45 PM, "Fredrik Salomonsson" <platt...@posteo.net mailto:platt...@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-patc...@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 >