sway: /etc/profile is never sourced when launching sway from GDM

Hi,

I found that when launching Sway from GDM on Archlinux, the /etc/profile file never gets sourced. I’m not sure if this counts as a bug, as the behaviour is the same for other wayland sessions that I tried, like Weston (but not Gnome, for some reason), and its only a problem when launching from a graphical login manager, as otherwise the profile is sourced already (e.g. when logging into a TTY). My sway version:

sway version 1.0-beta.1-157-g994c35e3 (Nov  6 2018, branch 'master')

To verify, you could do something like edit /etc/profile and add export MY_VARIABLE=1 to that file. Then login via GDM with Sway, launch a terminal and check to see if MY_VARIABLE is set. In my tests, it is not.

I have been able to solve this by changing the Exec=sway line in sway.desktop to Exec=bash -l -c sway. This launches a login shell (which sources the profile) and then runs sway inside of the shell. This is enough for my purposes, but I’m not sure if this is the correct way to fix this (or even if this warrants fixing) … at any rate I figured I would report it.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 15 (6 by maintainers)

Commits related to this issue

Most upvoted comments

This happens because GDM doesn’t start a shell. This is normal behaviour, and we can’t do anything about it.

Why do you need to source /etc/profile?

Is there any plan to support this officially in any way? Starting out interacting with a new WM by having to manually edit the .desktop file installed by the package manager isn’t the greatest experience. Or is the correct solution to use another login manager - if so, which one?

I feel like this should be supported in some sense because as I understand it, ~/.profile is the standard way to set env vars for all login environments, not just shells. I use it mainly to modify my PATH so that any/all programs installed in ~/.local/bin will be available to launch, and I thought this was fairly standard. Not a super drop in replacement for i3 if I can’t even launch my app launcher because it’s no longer in my path.

Apologies if this is a bit ranting - I appreciate sway existing, and I don’t mean to rag on this one thing. Just a bit annoying to try a new thing & immediately run into a closed issue where the solution is modifying system files installed by sway.

This is a display manager bug. Users logging in via fbcon get their profile sourced, the same should happen when running from a display manager.

FWIW, display managers aren’t officially supported by Sway because of bugs like this.

The reason I wanted this sourced is that on Arch Linux, a bunch of environment vars get set by files in /etc/profile.d (mostly not too important, but there is the occasional thing of significance in there, like setting up Java paths). However, if you feel this is not Sway’s job to fix, I understand.

This shouldn’t matter, because when you run exec in the sway config, a shell is used so the profile is sourced.

I thought this environment.d based “solution” might be useful in this context. It avoids *profile* altogether: https://github.com/swaywm/sway/issues/5160#issuecomment-645487492

I moved all reasonable environment definitions (PATH(s), EDITOR, etc) in ~/.config/environment.d/*.conf files.

Is there any working example? I tried:

cat /usr/share/wayland-sessions/sway.desktop                                                                                                                                         :(
[Desktop Entry]
Name=Sway
Comment=An i3-compatible Wayland compositor
Exec=/usr/bin/zsh -l -c sway
Type=Application

Without success.

I am using:

Desktop file:

[Desktop Entry]
Name=Sway (in login shell)
Comment=SirCmpwn's Wayland window manager
Exec=/usr/local/bin/sway-in-shell
Type=Application

/usr/local/bin/sway-in-shell:

#!/bin/sh

if [ "x$XDG_SESSION_TYPE" = "xwayland" ] &&
   [ "x$XDG_SESSION_CLASS" != "xgreeter" ] &&
   [  -n "$SHELL" ] &&
   grep -q "$SHELL" /etc/shells &&
   ! (echo "$SHELL" | grep -q "false") &&
   ! (echo "$SHELL" | grep -q "nologin"); then
  if [ "$1" != '-l' ]; then
    exec bash -c "exec -l '$SHELL' -c '$0 -l $*'"
  else
    shift
  fi
fi

exec /usr/bin/sway "$@"

sway-in-shell is more or less a carbon copy of the equivalent GNOME file.