• Canonical way for a package to set an environment variable

    From Soren Stoutner@21:1/5 to Debian Developers on Thu Jan 16 13:01:03 2025
    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
    soren@debian.org
    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEEJKVN2yNUZnlcqOI+wufLJ66wtgMFAmeJZX8ACgkQwufLJ66w tgOgtA//Yav6kOv9R6pZTfgZg2j5EdO6ccFQdlMfeonV4el70cT/gFXOPlbHlTT1 rHyf2fR5iVFeyjCVBF46qJaUE8NuumkpAs19ea36fXcOj2pYrEE6T5Ip1SjWI4Dk 1EhHf1lqk0HwssSeE67Zj4Ukhq1uFoZvXh5AabrvOWWbMTCEl5wSy/CwwPW97hQ/ UPOUc5UYavnfdbtf18txdss1cjBXk8wE0am61lx2XiAeFSRPs0xdne6w2MOuhkWq wb9iMRaIF8IGjFCN5IlZfoXMkKcV80qyK4wQ2T+BZ+W01MldCuhg21YaDIDNrWrw 0qx94owwBXhmjzAF9XSjIZqhgFwPwfwX2nvDRi8OjvWPNdlTmAgP24pqxE36QsHx uXEICOw9RmNj4u75+vuUV+DJ6EVgD060oizRQQqrvtYG5QMHdYxdSChRVA94SW2N xyOpHtF44fUp88Z8juCLQvFO0nhtuRbm7SRHpHZXo42a/4OnylTpZI0v0YU4F4Yv WR9MDsDrnJ17sw4cWyb48wTRXK1yk0h2woJPJ3kAMhByiZPd02csTBPqUNkXRjXJ jgKQcC5dDdUZQ0hMWqezLefvf26eT97eNUWCxrTv47nI7fadg0/vH5oCY/v5zj2u QO9ucGQ/tYq6+NIsTXgtousesp/ciG9NzXjGRGxnYYD6elXMdlA=
    =af4g
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Santiago Vila@21:1/5 to All on Thu Jan 16 22:00:01 2025
    El 16/1/25 a las 21:01, Soren Stoutner escribió:
    Is there a canonical way for a package to set an environment variable?

    You should try to find another way, because Debian Policy 9.9 says this:

    Programs installed on the system PATH (/bin, /usr/bin, /sbin, /usr/sbin, or similar directories) must not > depend on custom environment variable settings to get reasonable defaults.

    Thanks.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Soren Stoutner@21:1/5 to All on Thu Jan 16 14:21:20 2025
    Santiago,

    On Thursday, January 16, 2025 1:50:15 PM MST Santiago Vila wrote:
    El 16/1/25 a las 21:01, Soren Stoutner escribió:
    Is there a canonical way for a package to set an environment variable?

    You should try to find another way, because Debian Policy 9.9 says this:
    Programs installed on the system PATH (/bin, /usr/bin, /sbin, /usr/sbin,
    or
    similar directories) must not > depend on custom environment variable settings to get reasonable defaults.

    Thanks for the Debian policy reference. I will patch the Qt WebEngine source to achieve this without the need for an environment variable.

    --
    Soren Stoutner
    soren@debian.org
    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEEJKVN2yNUZnlcqOI+wufLJ66wtgMFAmeJeFAACgkQwufLJ66w tgNrqxAArBh7Fv+9QyXPORE4bv71DQQawkCAVyTVmbFJ7n5rjNr/sAdQhJlsMhHR 5rCUPQy8JuZjDNCZNn7fPEK7MhkMyYr6Q39qmBt0sCfPitT3nIUMOWsVQEZs+8Uw ew6voD1Nc97DBcvgy9tm0QQ88JR/jijDN8Z8TW6C+8IgdKD0OsjxguoRNqlCKuuI /b4km+ByUQIP+WC7Bb+TweIHQzCaV0Np356RRnRWwstDdI/2jd0nfiLLdVqAG492 WiBQoZg1Z7mKKZElFs7/skesEPzdxIrWDaTATomPJlNw40FGuxporgNRBPjF/y77 lWC95s9UOraJqBkGMztK3SK1Lfwh0dbkWdqAWmXFqqLxkq8eUWMUzfOrtoEJqReM MbcUvTIUyUOszTW7B5uiJUH9ZnSgUNkd1tkbjEVRSWegzjqw7vZZAnwvNJVQELCN ZeQ8RsLgn5QuK8bQ5WSRo+UVloBra6VITvMucbxdW1eHpu/x4yPGlJb1Cr+VwMAv /j8AZSBW85+AwmiNXyjnECmja5hbv5J5ABC3yhxHRSBc2BjYE2OKuRH2D3uw4AHu HlPkyEnJ4JIC6lbExZQ++B6+zTqOsWZ014Z0u+Yy2TYPTMvsvU5bDTNcwGeP4M+M EL5IYeKVRH59XlKE2BjaiHDcEJ0wT1ik46nZ+Aorynv1uKpcJ1A=
    =P+NY
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)