From e92e5b79a01034c8d3f4fa5b4c3981b2f33bfdb8 Mon Sep 17 00:00:00 2001 From: "Guilhem C." Date: Wed, 22 Apr 2026 22:23:37 +0200 Subject: [PATCH] fix(chezmoi): seed data.xdg at init so first apply works on fresh hosts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dot_config/chezmoi/private_chezmoi.toml.tmpl is a managed file, not an init template — on a clean host, it can't populate its own config before apply, so any template that reads .xdg.* (e.g. wgetrc.tmpl) fails with "map has no entry for key \"xdg\"". Adding a source-root .chezmoi.toml.tmpl makes chezmoi init render the config before the first apply. Values fall back to XDG-spec defaults under $HOME when env vars are unset, so it works on macOS and Linux alike. Co-Authored-By: Claude Opus 4.7 (1M context) --- .chezmoi.toml.tmpl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .chezmoi.toml.tmpl diff --git a/.chezmoi.toml.tmpl b/.chezmoi.toml.tmpl new file mode 100644 index 0000000..447e0d8 --- /dev/null +++ b/.chezmoi.toml.tmpl @@ -0,0 +1,17 @@ +{{/* +Source-root init template. `chezmoi init` renders this to +~/.config/chezmoi/chezmoi.toml before any `apply` runs, seeding `.xdg.*` so +templates that reference it (e.g. dot_config/wget/wgetrc.tmpl) resolve on the +very first apply. On subsequent applies, the managed +dot_config/chezmoi/private_chezmoi.toml.tmpl overwrites this file with the full +config (adds [diff] and [merge]) — intentionally narrow here so the init +template does only what init can't defer. + +Cross-platform: XDG_* wins when set (Linux, or macOS users who export it); else +falls back to XDG-spec defaults under $HOME (typical macOS). +*/ -}} +[data.xdg] + cache = {{ env "XDG_CACHE_HOME" | default (joinPath .chezmoi.homeDir ".cache") | quote }} + config = {{ env "XDG_CONFIG_HOME" | default (joinPath .chezmoi.homeDir ".config") | quote }} + data = {{ env "XDG_DATA_HOME" | default (joinPath .chezmoi.homeDir ".local" "share") | quote }} + state = {{ env "XDG_STATE_HOME" | default (joinPath .chezmoi.homeDir ".local" "state") | quote }}