Skip to content

Documentation: Set up XDG Base Directory environment variables #224525

@SuperSamus

Description

@SuperSamus

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md9.needs: documentationThis needs to be documented well.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions