-
-
Notifications
You must be signed in to change notification settings - Fork 17.1k
Description
Problem
XDG Base Directories are environment variables that allow to organize the location of configuration, data, etc. in the home directory.
Even with the default values, they make the user's $HOME much cleaner: for example, Git by default stores its configuration in ~/.gitconfig, but with XDG_CONFIG_HOME set then it will be stored in XDG_CONFIG_HOME/git/config.
The problem is: in NixOS, how does one set up these environment variables declaratively?
A solution could be Home Manager, which has the option programs.xdg.enable (which needs to be combined with programs.<shell>.enable in order to work). However, using Home Manager for such a simple thing is a bit overkill.
Another solution, according to the Arch Wiki, would appear to be:
environment.sessionVariables = {
XDG_CACHE_HOME = "@{HOME}/.cache";
XDG_CONFIG_HOME = "@{HOME}/.config";
XDG_DATA_HOME = "@{HOME}/.local/share";
XDG_STATE_HOME = "@{HOME}/.local/state";
}However, environment.sessionVariables doesn't support @{HOME}. You could use \${HOME} instead, however it may not be initialized when pam_env sets up these environment variables. It happens for example when logging in via TTY to a Fish shell.
Basically, every way I found to set up these variables has a flaw.
Proposal
Maybe creating some NixOS options specifically for setting up the XDG Base Directories?
Checklist
- checked latest Nixpkgs manual (source) and latest NixOS manual (source)
- checked open documentation issues for possible duplicates
- checked open documentation pull requests for possible solutions