this post was submitted on 14 Aug 2023
14 points (93.8% liked)

Linux

48061 readers
718 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

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

all 25 comments
sorted by: hot top controversial new old
[–] palordrolap@kbin.social 10 points 1 year ago (1 children)

.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 points 1 year ago

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.

[–] alembiq@lemmy.sdf.org 5 points 1 year ago (1 children)

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 points 1 year ago (2 children)

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

[–] whRQla8GEMdqXW2OVCbS@lemmy.blahaj.zone 3 points 1 year ago (2 children)

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.

[–] aebletrae@hexbear.net 1 points 1 year ago

Since .bashrc is executed for all non-login shells, it shouldn't really source .profile, which is only meant for login shells, and might trigger expensive activity. (.profile might source .bashrc, but that`s fine.)

[–] liberatedGuy@lemmy.ml 0 points 1 year ago

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

[–] bahmanm@lemmy.ml 2 points 1 year ago (1 children)

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 points 1 year ago

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.

[–] pnutzh4x0r@lemmy.ndlug.org 5 points 1 year ago (1 children)

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 points 1 year ago

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

[–] jdnewmil@lemmy.ca 4 points 1 year ago (1 children)

Did you check ownership and permissions for .profile?

[–] liberatedGuy@lemmy.ml 0 points 1 year ago

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

[–] aebletrae@hexbear.net 2 points 1 year ago (1 children)

Are other lines in .profile being executed, or is the whole file ignored? Have you logged out and in again since adding these lines?

[–] liberatedGuy@lemmy.ml 1 points 1 year ago (1 children)

Thanks for the response. Adding those lines to .bashrc helped with flatpaks but not with nix.

[–] aebletrae@hexbear.net 2 points 1 year ago (1 children)

But those kinds of initialisations belong in .profile (or, if you're using a weird desktop environment, its own configuration file), particularly if you want .desktop files to work. (In .bashrc, PATH will grow longer in each subshell, which shouldn't cause problems but is wasteful.)

So, what desktop environment (GNOME, KDE, Cinnamon, etc.) are you using?

.profile is executed by login shells for the benefit of it and its subshells, and by DEs like Cinnamon for the benefit of .desktop launchers at login.

So, have you logged out and back in again since adding these lines to .profile?

And of course, the .profile has to be executed properly for its configuration to take effect, so it`s useful to know if the problem is with those specific lines, or the file as a whole.

Add:—

date >> ~/profile-execution-log-top.txt
echo $PATH >> ~/profile-execution-log-top.txt

to the top of .profile, and:—

date >> ~/profile-execution-log-end.txt
echo $PATH >> ~/profile-execution-log-end.txt

to the bottom of .profile (use alternative paths as you see fit) to monitor that activity. You can test this by sourcing .profile but the real test is logging out and in again. Look at the time when you do this so you can correlate each action with each timestamp in the log files. If .profile is executed to completion, you should have two files with matching timestamps but different PATHs. If you don't have a matching timestamp in the "end" log file, there's a problem mid-execution. If neither file is being updated, .profile isn't being executed at all.

[–] liberatedGuy@lemmy.ml 2 points 1 year ago (1 children)

Hi, Thanks for the response. Sorry for disturbing you. I have tried what you have suggested here. There are two files with matching timestamps but different PATHs. I am using i3wm in Debian 11. Please tell me how to deal with this issue.

[–] aebletrae@hexbear.net 2 points 1 year ago (1 children)

Admittedly, I have much less experience with i3, so I fired up a virtual machine with Debian 11.6 and installed i3 (along with lightdm) and was able to recreate the problem of .profile not being executed when logging in, so this isn't unique to your particular setup. Great!

Fortunately, this combination does execute commands in ~/.xsessionrc, so I added:—

. $HOME/.profile

to that file, then logged out and back in again. That did the trick for me, with the commands in .profile then successfully modifying the PATH variable (and writing additional lines to the execution log files), so I suggest you try creating/modifying .xsessionrc in the same way.

[–] liberatedGuy@lemmy.ml 1 points 1 year ago (1 children)

Oh, thanks a lot for the efforts! You really are one of a kind to conduct an experiment to help out a stranger on the internet. Yeah, this actually works. I just added those lines to .xsessionrc and all problems were solved.

If you don't mind my asking. Do you work in IT as a sysadmin or a developer or a cybersecurity expert? Or something else? I am just curious as to how may have gained such knowledge.

[–] aebletrae@hexbear.net 1 points 1 year ago (1 children)

Helping one another out is invisibilized, not rare. A good chunk of what I know comes from other people taking the time to explain why something works the way it does and how you can see that for yourself. The rest is from curiosity, experimentation, and hammering away at something until it fits. It's not professionally specialized knowledge.

@aebletrae @liberatedGuy this just happened to me today and I am forever grateful to that person for explaining it instead of "shit.just.works."

[–] mvirts@lemmy.world 2 points 1 year ago (1 children)
[–] liberatedGuy@lemmy.ml 1 points 1 year ago

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