Bash not sourcing .profile automatically in Debian 11

So, in order to avoid typing "flatpak run", every time I need to run a flatpak program from the terminal, to have gui programs installed using nix appear in my applications menu(rofi, in this case), and to avoid typing the entire path to my .local/bin, I had added the following lines to my .profile:

set PATH so it includes user's private bin if it exists

if [ -d "$HOME/bin" ] ; then export PATH="$HOME/bin:$PATH" fi

set PATH so it includes user's private bin if it exists

if [ -d "$HOME/.local/bin" ] ; then export PATH="$HOME/.local/bin:$PATH" fi

for desktop entries for packages installed using Nix

export XDG_DATA_DIRS="/home/guest/.nix-profile/share:$XDG_DATA_DIRS"

set PATH so it includes user's private bin if it exists

if [ -d "/var/lib/flatpak/exports/bin" ] ; then export PATH="/var/lib/flatpak/exports/bin:$PATH" fi

if [ -d "/.local/share/flatpak/exports/bin" ] ; then export PATH="/.local/share/flatpak/exports/bin:$PATH" fi

However, for some weird reason, I cannot take advantage of the above lines unless I am in a tmux session or I explicitly type the following command:

source .profile

Any ideas on how to fix this?

EDIT: Adding the following line to .xsessionrc fixed the issue (haven't checked for wayland sessions though).

. $HOME/.profile

#Debian #Debian11 #foss #floss #libre_software #applications #desktop #gui #nix #flatpak #flatpaks #gnu #linux #opensource #open_source #tmux #bash #profile #shell #terminal

14 points · 15 comments · view on lemmy.world

15 Comments

palordrolap@kbin.social · 9 pts · 3y (1 reply)

.profileis only sourced when the shell is a login shell. Most shells started by terminal emulators under a GUI are not login shells.

Depending on how you connect to a machine, you may or may not get a login shell. Through SSH or similar may well get you a login shell. Using the text-console (usually through Ctrl+Alt+F1 through F6 on modern distros) also yields a login shell.

Try putting things in your .bashrc instead. That one is sourced regardless of login shell or not.

If you're not using bash, substitute the relevant file. .zshrc and .config/fish are the main two.

liberatedGuy@lemmy.ml · 0 pts · 3y

Thanks, that works with the flatpaks. However, it doesn't seem to work with nix packages. I mean rofi doesn't detect the .desktop files for packages installed using nix.

pnutzh4x0r@lemmy.ndlug.org · 5 pts · 3y (1 reply)

Do you have anything else your ~/.bashrc that is perhaps overwriting the PATH?

One thing you can do is just add echos to your .profile to see if it is getting sourced and what the state of PATH is as it gets loaded. That might help you trace what is happening.

liberatedGuy@lemmy.ml · 0 pts · 3y

Thanks for the response. I will try to as you have advised. Adding those lines to .bashrc helped with flatpaks but not with nix.

alembiq@lemmy.sdf.org · 3 pts · 3y (5 replies)

I had a similar issue some time ago, not sure which distro it was. The solution was to rename the .profile to .bash_profile :)

liberatedGuy@lemmy.ml · 1 pts · 3y (4 replies)

Thanks for the response. But in my case, even that does not work as well.

whRQla8GEMdqXW2OVCbS@lemmy.blahaj.zone · 3 pts · 3y (1 reply)

Does your .bashrc actually source .bash_profile? Add [ ! -f "~/.bash_profile" ] || . "~/.bash_profile" (.bash_profile doesn't exist or source it) to the end if not.

liberatedGuy@lemmy.ml · 0 pts · 3y

Adding those lines to .bashrc helped with flatpaks but not with nix.

bahmanm@lemmy.ml · 2 pts · 3y (1 reply)

You've probably already checked it out but make sure you've got only one of .profile, .bash_profile, .bashprofile. bash will only execute one of them in case there's more than one (not sure which one off the top of my head.)

liberatedGuy@lemmy.ml · 1 pts · 3y

I only have .profile. Actually adding those lines as to .bashrc as suggested by @palordrolap@kbin.social helped for the flatpak commands. But the issue with .desktop files for programs installed using nix still persists.

tekeous@apollo.town · 2 pts · 3y (1 reply)
[ removed ]
liberatedGuy@lemmy.ml · 0 pts · 3y

Thanks for the response. But that does not work as well.

mvirts@lemmy.world · 2 pts · 3y (1 reply)

https://serverfault.com/questions/261802/what-are-the-functional-differences-between-profile-bash-profile-and-bashrc

May be relevant, but it sounds like the behavior you see is not completely accounted for.

liberatedGuy@lemmy.ml · 1 pts · 3y

Thanks, I will check it out. Adding those lines to .bashrc helped with flatpaks but not with nix.

jdnewmil@lemmy.ca · 1 pts · 3y (1 reply)

Did you check ownership and permissions for .profile?

liberatedGuy@lemmy.ml · 0 pts · 3y

Changed it allow execution for the owner. Still no results. Tried with both .profile and .bash_profile.