Abstract
Wayland*1 is becoming popular as Linux desktop. And Clear Linux is also going for it*2.
In migration from X11 to Wayland, user will need to find the alternative solution for ".profile" before anything else. Wayland doesn't initiate any Xorg relted files including ".profile".
Wayland does not initiate any Xorg related files
Environment variables - ArchWiki
Probably, most users use .profile for
- set environment variables.
- autostarting
"source .profile" works as usual in Wayland, though different approach will be required in initiation of desktop. This post introduces 3 approaces for it.
Wayland
Environment variables
In Wayland, environment variables are defined in the next file.
~/.config/environment.d/envvars.conf
Autostarting
Desktop entry | It works when user logins desktop |
systemctl --user | It works without desktop |
desktop entry
Desktop entry means ".desktop" file. Saving it in certain folder manages some configuration of desktop. The next file supports autostarting.
~/.config/autostart/.desktop
This corresponds to Startup in Windows. It works when user logins desktop. In other word, it doesn't work without desktop.
systemd (systemctl --user)
This is to run command with systemd user instance. It corresponds to Task Scheduler in Windows. Differently from desktop entry, it works without desktop.
Saving user unit (service file) in next folder supports autostarting.
~/.config/systemd/user/
Approach
For ".profile" anternative, there are 3 approaches.
approach 1 | desktop entry for "source .profile" |
approach 2 | envvars.conf + desktop entry |
approach 3 | envvars.conf + systemd |
Let's say ".profile" contains the following settings. Environment variables there is for PowerShell*3, and command makes Japanese input enabled*4. Approaces below make these configuration activate.
.profile
export DOTNET_ROOT=~/.dotnet export PATH=$PATH:$DOTNET_ROOT export PATH=$PATH:$DOTNET_ROOT/tools export PATH=$PATH:$DOTNET_ROOT/tools/sdk export PATH=$PATH:~/.local/bin distrobox enter -n ubuntu -- ibus-daemon -drx
Approach 1
Calling "source .profile" from desktop entry. Although this is tricky way, it is the simplest and easiest approach. Be careful that in case of switching X11 and Wayland, especially in X11 case, desktop is initiated with ".profile" duplicatedly.
Make "~/.config/autostart/.desktop" as below. Path for "Exec=" should be absolute path. Description in ".profile" is effective at next login.
~/.config/autostart/.desktop
[Desktop Entry] Comment=read .profile Exec=/bin/bash -lc 'source /home/[user name]/.profile' Name=autoexec Type=Application
Approach 2
Define environment variables in conf file, and set autostarting with desktop entry, it is the most appropriate approach especially for working when login to desktop.
Environment variables are defined in "~/.config/environment.d/envvars.conf"
~/.config/environment.d/envvars.conf
DOTNET_ROOT=/home/[user name]/.dotnet PATH=$PATH:$DOTNET_ROOT PATH=$PATH:$DOTNET_ROOT/tools PATH=$PATH:~/.local/bin
And set autostarting in "~/.config/autostart/.desktop". Path for "Exec=" should be absolute path. These configuration are effective at next login.
~/.config/autostart/.desktop
[Desktop Entry] Comment=run Mozc at login Exec=/home/[user name]/.local/bin/distrobox enter -n ubuntu -- ibus-daemon -drx Name=autoexec Type=Application
Approach 3
Although this is also right approach as well as Approach 2, it may be tricky especially for autostarting when login to desktop. It can work without desktop. Troublesomely, it may not always lead to the expected situation unlike "source .profile" manually and its inheritance to the current shell.
As well as Approach 2, environment variables are defined in "envvars.conf". Define user unit as below. Name of service file is arbitrary. And path for "ExecStart=" should be absolute path.
~/.config/systemd/user/autoexec.service
[Unit] Description=run Mozc at login [Service] ExecStart=/home/[user name]/.local/bin/distrobox enter -n ubuntu -- ibus-daemon -drx [Install] WantedBy=default.target
Set user unit with command below. User unit is effective at next login or reboot.
systemctl --user enable autoexec.service systemctl --user daemon-reload