Settings environment variable system-wide in a VM

172 views
Skip to first unread message

Elias Mårtenson

unread,
Mar 19, 2018, 1:14:43 AM3/19/18
to qubes-users
How do I set an environment variable that will be accessible to all programs started in a session?

Specifically, I'm trying to set KRB5CCNAME in $HOME/.profile, and it becomes available from a terminal session as expected, but it never gets set in Nautilus, where it is needed.

Looking at /etc/X11/xinit/xinitrc, that script sources another script which in turn sources $HOME/.profile, so as far as I can tell, this should work.

Could it be that the Nautilus server isn't started by the user's session itself? If so, how do I work around this?

Unman

unread,
Mar 19, 2018, 8:06:41 AM3/19/18
to Elias Mårtenson, qubes-users
generally the Xsession wont touch .profile - there are exceptions.
It's picking up stuff from /etc/X11/Xsession.d
You can also use ~/.xsessionrc which is sourced from a file in
/etc/X11/Xsession.d
You probably dont want to source .bashrc directly, but you can create
another file to hold environment variables and source it from
.xsessionrc AND .bashrc/.profile

Elias Mårtenson

unread,
Mar 20, 2018, 12:04:57 AM3/20/18
to qubes-users
On Monday, 19 March 2018 20:06:41 UTC+8, Unman wrote:

> generally the Xsession wont touch .profile - there are exceptions.
> It's picking up stuff from /etc/X11/Xsession.d
> You can also use ~/.xsessionrc which is sourced from a file in
> /etc/X11/Xsession.d
> You probably dont want to source .bashrc directly, but you can create
> another file to hold environment variables and source it from
> .xsessionrc AND .bashrc/.profile

Thank you. I followed your recommendations but it does not seem to work.

I tried this by creating a file /etc/X11/Xsession.d/99xsession with the following content:

if [ -r "$HOME/.xsessionrc" ] ; then
. "$HOME/.xsessionrc"
fi

I then added some code in .xsessionrc that adds a log message to a file in /tmp. After this I sourced /etc/X11/Xsession.d/99xsession to confirm that the everything worked.

After rebooting the VM, the environment variable was not set, and there was no entry in the file in /tmp which is updated by the script.

From this I draw the conclusion that the scripts in /etc/X11/Xsession.d are not actually sourced when booting a VM.

Did I do something wrong, or is my analysis of the situation incorrect?

Unman

unread,
Mar 20, 2018, 9:34:38 AM3/20/18
to Elias Mårtenson, qubes-users
You dont seem to have followed my recommendations :-(

On a Debian system, sourcing user defined xessionrc is already set up -
it is in /etc/X11/Xsession.d/40x11-common_xsessionrc.
I suspect Fedora would have something similar.

If you put env variable in .bashrc,and start nautilus from command
line, the variable will be available. You can see this using script that
dumps 'env' to file, and running that script from nautilus.
If you start nautilus from menu this wont be the case - the environment
variable wont exist when you run the same script.

Create ~/.envsrc , and set a variable there.
Create .xsessionrc and source ~/.envsrc
Now shutdown the qube and start nautilus from the menu and behold, the
variable WILL be available in nautilus.
Note that this will be a GLOBAL variable, so you dont NEED to source it
from .bashrc, but you can overwrite it from there.
Also, of course, you can set the variable directly in .xsessionrc - I
just prefer to keep such variables separate.

Without knowing exactly what you put in the file, I cant comment on why
it didn't work for you.


Elias Mårtenson

unread,
Mar 20, 2018, 10:24:56 AM3/20/18
to qubes-users
On Tuesday, 20 March 2018 21:34:38 UTC+8, Unman wrote:

> You dont seem to have followed my recommendations :-(

Actually, I did. :-) Note that your recommendation works perfectly on Debian-9.
I'm using Fedora-26, and things are not as neat there.

> On a Debian system, sourcing user defined xessionrc is already set up -
> it is in /etc/X11/Xsession.d/40x11-common_xsessionrc.
> I suspect Fedora would have something similar.

Well, it doesn't seem to. On Fedroa there is only a single file in
/etc/X11/Xsession.d, and that is 60xbrlapi (which seems to have something
to do with braille output).

That's why I added my own to the fedora-26 template, with the content you
saw in my previous message.

But, even when doing this, the script wasn't run which suggests that the entire
Xsession.d mechanism does not work on Fedora-26. Again, on Debian-9 it works
exactly as you described.

Unman

unread,
Mar 20, 2018, 10:59:17 AM3/20/18
to Elias Mårtenson, qubes-users
I'm not familiar with Fedora, but setting a variable in .profile DOES
seem to expose it to nautilus, at least in a qube using a
Fedora-26-minimal template.
So can we take a step back and can you explain what variable you want
set and how you expect it to affect nautilus use? That is, how would you
judge that the variable has been set for nautilus?

Elias Mårtenson

unread,
Mar 20, 2018, 11:23:55 AM3/20/18
to qubes-users
On Tuesday, 20 March 2018 22:59:17 UTC+8, Unman wrote:

> I'm not familiar with Fedora, but setting a variable in .profile DOES
> seem to expose it to nautilus, at least in a qube using a
> Fedora-26-minimal template.
> So can we take a step back and can you explain what variable you want
> set and how you expect it to affect nautilus use? That is, how would you
> judge that the variable has been set for nautilus?

That's odd. That's not my observation on Fedora-26.

What I try to set is KRB5CCNAME. This environment variable specifies the
path to the Kerberos ticket file that is needed for authentication to
SMB fileshares (in the specific case of Nautilus).

I have proved that the environment variable does not get set first and foremost
by noting that authentication doesn't work, and also by checking /proc/PID/environ
for the Nautilus process. This file contains the environment variables for
a given process.

Unman

unread,
Mar 20, 2018, 12:01:52 PM3/20/18
to Elias Mårtenson, qubes-users
It depends how you are strating nautilus.
Have you tried using /etc/environment?
Just put:
KRB5CCNAME=foo


Reply all
Reply to author
Forward
0 new messages