Opinion about XDG support by the Clojure tools (deps, cli)

Clojure should not rely only on the XDG_CONFIG_HOME environment variable to follow the XDG standard.

In an XDG System, XDG_CONFIG_HOME exists to allow users to override the default which is ~/.config.[1]

Defining XDG_CONFIG_HOME in my XDG system as ~/.config is redundant, but I’m forced to do it by Clojure if I want to keep all my configuration files in ~/.config.

The order for “User - cross-project configuration (typically tools)” according to the Clojure reference is:

  1. If $CLJ_CONFIG is set, then use $CLJ_CONFIG (explicit override)
  2. If $XDG_CONFIG_HOME is set, then use $XDG_CONFIG_HOME/clojure (Freedesktop conventions)
  3. Else use $HOME/.clojure (most common)

But I think the tools should find another way to determine if the System is an XDG System. Let’s say it exists, step 2 should be something like:

  1. If an XDG System, use $XDG_CONFIG_HOME if set or $HOME/.config/clojure

That predicate “is an XDG System” could be implemented (redundantly) as: Is $XDG_CONFIG_HOME set or $HOME/.config exists?.

So another more specific way to implement 2:

  1. XDG_CONFIG_HOME if set or $HOME/.config/clojure if exists.

And if it is a clean system, with no preexisting ~/.clojure nor ~/.config/clojure, the creation of .config/clojure should take precedence over .clojure if Clojure can tell if the System is an XDG System.

End of my OPINION :smiley: (just highlighting it is just an Opinion). ← Opinion

[1] “If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used” - Environment variables

For future reference, requests or problems with the Clojure CLI should be filed at https://ask.clojure.org where they can be triaged into tickets. I might see things here, but also, I might not.

Can you point to some doc references for XDG that would definitely say how to determine if it is an XDG system?

1 Like

Noted, thanks.

Sure. The XDG Base Directory Specification should be that document (version 0.8 today).

I think there is no an API or standard way to ask a System if it is an XDG system because it’s a chicken-egg problem. What I’ve seen it is mostly done is checking for the $XDG_CONFIG_HOME value and if not, checking for the $HOME/.config folder; failing that “means” not XDG.

The tool published in the Freedesktop site for scripting is a Python tool called pyxdg, and it has a module dedicated to the Base Directory specification. You can see specifically how they define the xdg_config_home as:

xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or \
            os.path.join(_home, '.config')

TLDR: The XDG Base Directory Specification should be that document.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.