#968910 sway: Logging in doesn't run ~/.profile

Package:
sway
Source:
sway
Description:
i3-compatible Wayland compositor
Submitter:
Nicholas Eckardt
Date:
2024-09-18 11:39:01 UTC
Severity:
normal
#968910#5
Date:
2020-08-23 17:36:47 UTC
From:
To:
Dear Maintainer,

*** Reporter, please consider answering these questions, where appropriate ***

   * What led up to the situation?
   	Logging into sway, my changes to $PATH were not run.
   * What exactly did you do (or not do) that was effective (or
     ineffective)?
     	I set .profile to create a new file when run.
   * What was the outcome of this action?
  	 This file is created in GNOME, but not created in sway.
   * What outcome did you expect instead?
   	I expected the file to be created in both GNOME and sway,
	thus indicating that .profile ran.

*** End of the template - remove these template lines ***

#968910#10
Date:
2020-08-23 18:28:17 UTC
From:
To:
Hi,


the `.profile` file is the configuration file for the bourne shell. It
is usually not run on login in graphical environments, so GNOME seems to
be special in that way. But you can configure sway to run the file by
adding an exec statement to your swaywm config:
`exec sh ~/.profile` or something similar should work.

For setting environment variables like $PATH there are different
approaches how to set them when starting sway, [0] lists some of them.

[0]
https://www.reddit.com/r/swaywm/comments/gpzqcg/set_environment_variables/

cheers,
Birger

#968910#15
Date:
2021-04-19 14:39:51 UTC
From:
To:
Hi,

I'm sorry I couldn't set the "In-Reply-To" header correctly here. I hope
this doesn't mess the thread order.

I just wanted to add some information to this, and maybe we can work around
this issue somehow on debian.

I ran into this issue because I wasn't able to setup my PATH variable on
sway. There, as far as I can tell, two recommended ways of setting up
environment variables: using systemd's ~/.config/environment.d/*.conf
files, and using ~/.pam_environment.

~/.pam_environment was disabled on Debian, to my knowledge, because of
CVE-2010-4708[1], so that is not an option.

Using systemd runs into an issue with how debian's `/etc/profile` overrides
the PATH[2]. A common workaround for this, as I found, is to use ~/.profile
to set PATH, but this didn't seem to work for me. The discussion in this
systemd issue seems to revolve around GNOME, and the solution there was to
use a login shell[3] when running GNOME. That explains why I couldn't use
~/.profile: the default sway.desktop does not use a login shell.

I tried the two suggestions Birger Schacht gave (sorry again about the
messy thread, but I'll quote here).

[...] But you can configure sway to run the file by
Adding this to `.config/sway/config` (if I understood the suggestion
correctly) did not work for me. Even with an `export MY_VAR=1` in my
~/.profile the variable was not in the sway environment. Maybe the `exec`
runs in a subshell or something
The approach suggested here is having a `sway` script somewhere in your
path that overrides the system's sway binary and sets the variable didn't
work for me. I think exactly because at that point PATH is fixed to what is
in Debian's /etc/profile.

The only thing that did work for me was changing the `sway.desktop` file
read by GDM to execute sway inside a login shell. This is similar to the
GNOME solution (even though I'll be the first to admit the solution in [3]
is much better and more complete). The attached patch fixed the issue for
me, as sway is now running under a login shell (so I can use ~/.profile)

This solution works, but I don't want to have this as a permanent solution
for myself since it requires changing a package provided file. Since the
workaround of needing to use ~/.profile is a result of the combination of
two debian specific behaviours, what do you think about having this
solution in the package? I know the patch I provide here is not perfect,
but if you agree I can try to work on a solution similar to GNOME's, which
supports other shells.

Cheers,
Flávio

[1]: https://security-tracker.debian.org/tracker/CVE-2010-4708
[2]: https://github.com/systemd/systemd/issues/6414
[3]:
https://gitlab.gnome.org/GNOME/gnome-session/commit/7e307f8ddb91db5d4051c4c792519a660ba67f35

#968910#20
Date:
2024-08-08 15:25:01 UTC
From:
To:
I wanted to comment that I face exactly the same problem and Flavio's patch
is the only way I have found to fix this properly ie have one .profile that
is shared across various login types.

Thanks

Will

#968910#25
Date:
2024-09-18 11:30:01 UTC
From:
To: