Is there a canonical way for a package to set an environment variable?

Background:

Systemd parses files in /etc/environment.d/
Sysvinit parses the single file /etc/environment
Finit parses file in /etc/finit.d/

                                  Why can’t we all just get along?

It is easy for a package to add or remove files from /etc/environment.d/.  It 
is more tricky to edit /etc/environment.  And having to do it in (potentially) 
three locations seems inefficient.


1.  Is there some other way for a package to set a global environment 
variable?

2.  If not, would it be advisable or possible to patch Sysvinit and Finit to 
parse /etc/environment.d so this could all be handled from one place?


Specific problem prompting the question (you can skip this part unless you like 
the gory details):

Qt WebEngine is an HTML rendering engine based on the Chromium source code 
shipped as part of Qt (and KDE) that renders things like HTML documentation, 
HTML emails, and is also used by various web browsers.  Chromium uses a spell 
checking system based on Hunspell, but in their “wisdom” they decided to 
customize it by creating a binary dictionary format instead of using the plain 
text Hunspell format.  Qt WebEngine inherits this design.  Chromium ships a 
tool that converts the standard Hunspell files into the binary .bdic format.  
Trixie will release with most Hunspell packages shipping these files in /usr/
share/hunspell-bdic/.

Qt WebEngine contains a section of code that looks for these dictionaries in a 
number of locations, including individual user profiles.  One of the locations 
it checks is the directory defined by the QTWEBENGINE_DICTIONARIES_PATH 
variable.  The revelant code is at:

https://sources.debian.org/src/qt6-webengine/6.7.2%2Bdfsg2-1/src/core/
web_engine_library_info.cpp/#L243

The initial discussion about how to ship .bdic binary dictionary files in 
Debian was at:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1020387

The result of this was the following policy:

The Qt packages will install the following system-wide environment variable in 
/etc/environment.d/ so that programs that use Qt WebEngine will be able to find 
the .bdic dictionaries:

QTWEBENGINE_DICTIONARIES_PATH=/usr/share/hunspell-bdic/

https://salsa.debian.org/debian/dictionaries-common/-/blob/master/policy/dsdt-policy.xml.in?ref_type=heads#L1437

At the time we assumed that would be sufficient for any Debian system, but we 
later learned that init systems besides Systemd don’t parse /etc/
environment.d/.

There are several ways we could proceed with this particular problem.

1.  Patch Qt WebEngine on Debian to always look in /usr/share/hunspell-bdic/.
2.  Add the environment variable to /etc/environment.d/ and document in 
README.Debian that users need to handle their own environment variable with 
other init systems.
3.  Add the environment variable to all known init environment variable 
locations.
4.  Add the environment variable somewhere else, like /etc/X11/Xsession.d/.

It would be possible to do 1, but it isn’t my first choice because it would 
modify upstream Qt WebEngine behavior in a way that some user might expect not 
to be modified.  Also, this would only solve the problem for this package.  I 
assume that at some point some other Debian package will have a need to set a 
system-wide environment variable.

I have already implemented 2 for Privacy Browser, one of the packages I 
maintain.  But it seems suboptimal to require users to set this environment 
variable themselves, even for uncommon init systems.

https://salsa.debian.org/soren/privacybrowser/-/blob/master/debian/
README.Debian?ref_type=heads

Option 3 gets a bit complex, because there are two current packages providing 
Qt WebEngine that could be concurrently installed (Qt 5 WebEngine and Qt 6 
WebEngine), both of them need to set this variable.  There isn’t a problem 
with it being set twice by two separate files in /etc/environment.d/, but using 
sed or some other tool to edit /etc/environment could get a little dicey as 
one or both of the packages are installed and uninstalled.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1092726

Option 4 is fine with me in this case if it works (does Wayland parse 
environment variables from /etc/X11/Xsession.d?), but it is only a solution 
for graphical programs.  And again, I would imagine that at some point there 
will be a Debian package that needs a way to set an environment variable 
system-wide, even when no graphical environment is running.

-- 
Soren Stoutner
so...@debian.org

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to