I have recently installed Manjaro Sway and I want to use the Guix package manager with it. I’ve installed Guix and it’s working fine, but the problem is that, to make the installed packages available in the path some environment setup needs to be done at login. I’ve got the necessary lines of code in ~/.profile but it’s not running at login. After opening a terminal the Guix installed apps are not found, but then if I run source .profile they become available.
This info might be relevant:
Before I noticed this problem, I was experimenting with using fish as my shell, and I managed to get the Guix environment setup properly in that, but since fish wasn’t playing well with the foot terminal emulator I went back to zsh by running chsh -s /bin/zsh
The fresh install of Manjaro Sway uses zsh, but also comes with a ~/.profile file and not a ~.zprofile file. one of the lines in ~/.profile is export SHELL=/usr/bin/zsh which makes me think the login shell is something else to begin with, then gets changed to zsh as this runs?
Profile files are only read for login shells. When you start a shell in a terminal in an existing session (screen, X terminal, Emacs terminal buffer, a shell inside another, etc.), you get an interactive, non-login shell.
OK, but I also want the Guix installed apps to available in my Rofi launcher. There’s a script at /etc/profile.d/zzz-guix.sh which is supposed to make that work, but it doesn’t seem to be. This is why I’m interested in what is being run at login, nit when opening a terminal.
actually the /etc/profile.d/zzz-guix.sh file wasn’t setting the XDG_DATA_DIRS variable so wasn’t doing what I expected it to. I just added that to the script and now the apps are coming into the Rofil launcher. So it seems /etc/profile.d/* is being run on login after all.
For those interested, this is the line I added to the file:
Things reverted for me and I’m not getting my Guix apps integrated to my desktop anymore. I’m getting very confused by this so I made various profile init scripts log to a file when they ran and discovered that even though I’m using zsh, .zprofile does not run at all but .profile does at login (it may be that Manjaro Sway has configured zsh to behave this way?). The scripts in etc/profile.d/ also run at login and .zsgrc along with .zshenv run each time a terminal is opened.
But still the path I need to get into XDG_DATA_DIRS at login is not getting there.
I’m trying to get these two paths into my XDG_DATA_DIRS variable at login:
/home/toby/.config/guix/current/share
/home/toby/.guix-profile/share
this is what I have at the bottom of .profile:
for profile in "$HOME/.guix-profile" "$HOME/.config/guix/current"
do
<snip some irrelevant code here>
if [ -d "$profile/share" ]
then
XDG_DATA_DIRS="$profile/share${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"
fi
done
export XDG_DATA_DIRS
(yes, both locations have a share directory in them)
That environment variable is not mentioned anywhere esle in the file.
I’ve installed Manjaro Sway and I’m using zsh in a foot terminal. I thought that if I enter export TEST=testing
then open another terminal session and enter echo $TEST I should get the output testing but I get no output. Am I misunderstanding how export is supposed to work?
The variable needs to be available when initiating another session.
As you’ve only defined it in the previous session, it’s not available to another concurrent session; as each new shell inherits the environment from which the shell was initiated.
The best way to achieve what you want is to add the export line to your ~/.zshrc file (or ~/.bashrc if you opt to use bash instead or in ~/.bash_profile as an alternative).
echo export CHEESE=Swiss >> ~/.zshrc
would insert the variable into ~/.zshrc, for example.
At next login the variable should then be available for all subsequent shells launched, until that variable is removed.
You could override the variable when needed:
echo export CHEESE=Cheddar >> ~/.zshrc
I hope this is helpful.
Cheers.
Edit:- Examples changed to ~/.zshrc as zsh shell is used.
in ~/.profile there’s a bunch of export statements, but I don’t see any env statements. This runs at login and then all the shells after that get the exported variables. Is it right to assume then that whatever system service runs the .profile also follows up by doing something equivalent to the env statement?
The reason I’m asking about this is in followup to Environment variables set in ~/.profile not persisted after login - #15 by toby1kenobi where I’ve reached a dead end. I’ve been trying to set environment variables in .profile and after login they are not available in my shell, but become available in the current session when I run source .profile, but not elsewhere. I’ve checked the .profile does indeed run at login (I’ve made it log some activity into a file) but it fails to export the environment variables that I added to it to other shell sessions (other environment variables in there are exported fine), and I don’t know how to debug that.