sway: do the WAYLAND_DISPLAY moving inside sway config itself

This commit is contained in:
2024-03-23 17:09:57 +00:00
parent 6102a0301d
commit f65d3d04dc
2 changed files with 11 additions and 13 deletions

View File

@@ -8,7 +8,7 @@ let
swayLauncher = pkgs.writeShellScriptBin "sway" ''
# delete DISPLAY-related vars from env before launch, else sway will try to connect to a remote display.
# (consider: nested sway sessions, where sway actually has a reason to read these)
exec env -u DISPLAY -u WAYLAND_DISPLAY ${configuredSway}/bin/sway 2>&1
exec env -u DISPLAY -u WAYLAND_DISPLAY "REAL_WAYLAND_DISPLAY=$WAYLAND_DISPLAY" ${configuredSway}/bin/sway 2>&1
'';
in
pkgs.symlinkJoin {
@@ -232,16 +232,7 @@ in
'';
# readiness.waitExists = "$SWAYSOCK";
readiness.waitCommand = pkgs.writeShellScript "sway-readycheck" ''
# wait for sway to create its socket AND its wayland display.
# it doesn't know to create the wayland display in the right directory, so have to manually move it socket... bleh.
# TODO: socket moving could be more reliable inside of the sway config
set -e
test -e "$SWAYSOCK"
expected_display="$XDG_RUNTIME_DIR/$(basename "$WAYLAND_DISPLAY")"
test -e "$expected_display" && test -e "$expected_display.lock"
set +e # make only a best-effort to move these; if it fails (because e.g. perms, or destination exists somehow), don't hold up init
mv "$expected_display" "$WAYLAND_DISPLAY"
mv "$expected_display.lock" "$WAYLAND_DISPLAY.lock"
test -e "$SWAYSOCK" && test -e "$WAYLAND_DISPLAY"
'';
};
# link the graphical-session into the default target, so sway gets auto-started

View File

@@ -236,6 +236,13 @@ output $out_moby {
# scale 1.6
}
# move the wayland socket that sway implicitly created to the place which other apps expect to find it
exec --no-startup-id mv $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY $REAL_WAYLAND_DISPLAY
exec --no-startup-id mv $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY.lock $REAL_WAYLAND_DISPLAY.lock
# i'm sure there's a simpler way. not certain that this actually updates the sway environment variables anyway
# the double-$ means to set the variable at *runtime*, not at "compile-time" (so that it doesn't impact the line immediately above us
set $$WAYLAND_DISPLAY "$(echo $REAL_WAYLAND_DISPLAY)"
# manually export PATH here, since all my user services need that, and sane-sandboxed implementation depends on it.
# also, manually export XDG_DATA_DIRS. glib fails in weird ways (e.g. thinks everything is application/x-octet-stream mime type) without it.
@@ -243,8 +250,8 @@ output $out_moby {
#
# XXX: dbus-update-activation-environment --systemd is ASYNCHRONOUS. it returns before the systemd environment is actually updated.
# hence, call `systemctl import-environment` ourselves. i could probably remove the dbus stuff and be safe, but at least for now it's an OK backup.
exec --no-startup-id systemctl --user import-environment PATH XDG_DATA_DIRS DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP
exec --no-startup-id dbus-update-activation-environment --systemd PATH XDG_DATA_DIRS DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP
# exec --no-startup-id systemctl --user import-environment PATH XDG_DATA_DIRS DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP
# exec --no-startup-id dbus-update-activation-environment --systemd PATH XDG_DATA_DIRS DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP
# previously: `include /etc/sway/config.d/*` was needed for xdg-desktop-portal-* to work.
# stock nixos `programs.sway` would setup /etc/sway/config.d with additional variables to import to the dbus env.