Is there a way to detect if the System is XDG independently of the environment variables?

Simon McVittie smcv at collabora.com
Mon Apr 15 13:26:44 UTC 2024


On Fri, 29 Mar 2024 at 14:48:35 -0230, Jesús Gómez wrote:
> I understand that the XDG_* environment variables are options for the users to
> customize their system, but the lack of them doesn't mean that the system is
> not following XDG.

Correct. If none of the XDG environment variables are set, they all have
documented fallbacks (with the possible exception of XDG_RUNTIME_DIR,
which behaves rather differently, and so there is not necessarily any
single correct fallback).

> I've been thinking about this, and the more I read the specifications, it seems
> to me that "Systems" don't have that responsibility and it is just an decision
> of the applications to follow the specifications or not.

Where you say "applications", strictly speaking it's more like
"applications and libraries", but otherwise yes.

On Linux, I'd say that well-behaved applications and libraries should
use the XDG paths, unless they have reasons not to. For example, older
applications and libraries often have a traditional/legacy path that
they prefer to use, and that can be a valid reason - but even then, it
can make sense to use the XDG paths in addition to a traditional/legacy
path, like the way git supports both $XDG_CONFIG_HOME/git/config and
the more traditional ~/.gitconfig.

On other open source Unix platforms (*BSD, Hurd, etc.) the same behaviour
as Linux makes sense. Ditto on proprietary Unix platforms, if any are still
practically relevant.

In fact, I'd go so far as to say that the only platforms where the
XDG paths would *not* be appropriate are the ones that have their own
well-known directory layout - such as Windows, the macOS/iOS/etc. family,
and Android - on which the right paths to use are the ones that you can
discover from appropriate OS APIs.

Good examples to follow on this include GLib, Qt and SDL, all of which
have their own "give me the right path for..." APIs with separate code
paths for at least Unix (XDG) and Windows.

On Wed, 10 Apr 2024 at 21:02:13 -0230, Jesús Gómez wrote:
> """ Your process runs in a system following XDG if the environment variable
> XDG_CONFIG_DIRS is defined OR the folder /etc/xdg exists.  """

No, please don't assume that. If there has not yet been any need to
configure XDG apps/libraries on a system-wide basis, then /etc/xdg might
not exist at all.

    smcv


More information about the xdg mailing list