twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
13.36k stars 493 forks source link

.chezmoidata.d? #3008

Closed jeslinmx closed 1 year ago

jeslinmx commented 1 year ago

Is your feature request related to a problem? Please describe.

My .chezmoidata.yaml is getting fairly cluttered, as I'm using variables for all sorts of things:

Describe the solution you'd like

A drop-in directory, unimaginatively named .chezmoidata.d, to supplement the existing .chezmoidata.<format> files. Imagined in the context of the existing template data mechanism:

These come from a variety of sources (later data overwrite earlier ones):

  • Variables populated by chezmoi are in .chezmoi, for example .chezmoi.os.

  • Variables created by you in the .chezmoidata.$FORMAT configuration file. The various supported formats (json, jsonc, toml and yaml) are read in alphabetical order.

  • *Variables created by you in the .chezmoidata.d/.$FORMAT drop-in configuration files. The various files and supported formats are read in alphabetical order.**

  • Variables created by you in the data section of the configuration file.

Describe alternatives you've considered

Additional context

I'd appreciate any alternative perspectives on whether I'm using .chezmoidata.<format> wrongly or against best practice.

twpayne commented 1 year ago

Thanks for the suggestion. This is implemented in #3009. The name of the directory is .chezmoidata (note there is no .d at the end). The lack of .d is because chezmoi doesn't use .d anywhere else. For example, .chezmoitemplates is a directory, not .chezmoitemplates.d.

jeslinmx commented 1 year ago

I get

chezmoi: stat ($HOME)/.chezmoidata: no such file or directory

when running chezmoi apply with the latest release. The only change I've made is converting my monolithic .chezmoidata.yaml into subfiles under .chezmoidata/

twpayne commented 1 year ago

Thank you for testing. However, I am unable to reproduce your issue:

$ podman pull ubuntu:latest
...
$ podman run -it ubuntu:latest /bin/bash
# apt update && apt install -y curl
...
# sh -c "$(curl -fsSL get.chezmoi.io)" -- init jeslinmx
info found version 2.34.0 for latest/linux/arm64
info installed ./bin/chezmoi
GitHub username? jeslinmx
Perform headless setup (no kitty, fonts, etc.)? y
Manage SSH authorized_keys? n
Manage local bin? n
# chezmoi data | grep -A1 -v '^ '
aliases:
    cm: chezmoi
--
authorizedKeys: false
battery:
    colors:
--
bin:
    starship:
--
chezmoi:
    arch: arm64
--
color:
    - '#282a2e'
--
colors:
    background: '#1d1f21'
--
env:
    EDITOR: nvim
--
githubUsername: jeslinmx
headless: true
manageBin: false

Do you have a way to reproduce the chezmoi: stat ($HOME)/.chezmoidata: no such file or directory error?

jeslinmx commented 1 year ago

Yes. It occurs upon apply:

root@ff853746e6e7:/# sh -c "$(curl -fsSL get.chezmoi.io)" -- init --apply jeslinmx
info found version 2.34.1 for latest/linux/amd64
info installed ./bin/chezmoi
Cloning into '/root/.local/share/chezmoi'...
remote: Enumerating objects: 489, done.
remote: Counting objects: 100% (58/58), done.
remote: Compressing objects: 100% (42/42), done.
remote: Total 489 (delta 22), reused 42 (delta 11), pack-reused 431
Receiving objects: 100% (489/489), 4.50 MiB | 11.66 MiB/s, done.
Resolving deltas: 100% (224/224), done.
chezmoi: stat /root/.chezmoidata: no such file or directory
root@ff853746e6e7:/#
jeslinmx commented 1 year ago

Looking at the debug output, I think this is the issue:

2023-06-11T01:33:06+08:00 INF ReadFile component=system data="### COLOR SCHEME ###\n\ncolors:\n  background:    &background    '#..." name=/var/home/jeslinmx/.local/share/chezmoi/.chezmoidata/colors.yaml size=1016
2023-06-11T01:33:06+08:00 ERR Lstat error="lstat /var/home/jeslinmx/.chezmoidata/colors.yaml: no such file or directory" component=system name=/var/home/jeslinmx/.chezmoidata/colors.yaml
2023-06-11T01:33:06+08:00 INF Get bucket=entryState component=persistentState key=/var/home/jeslinmx/.chezmoidata/colors.yaml value=
2023-06-11T01:33:06+08:00 INF defaultPreApplyFunc actualEntryState={"ContentsSHA256":"","Mode":0,"Type":"remove"} lastWrittenEntryState={} targetEntryState={"ContentsSHA256":"4ef8a7badf1dcff1c580449673932762628f56bed2ba8b9d84de037599bd9acd","Mode":420,"Type":"file","contents":"### COLOR SCHEME ###\n\ncolors:\n  background:    \u0026background    '#..."} targetRelPath=.chezmoidata/colors.yaml
2023-06-11T01:33:06+08:00 ERR WriteFile error="stat /var/home/jeslinmx/.chezmoidata: no such file or directory" component=system data="### COLOR SCHEME ###\n\ncolors:\n  background:    &background    '#1d1f21'\n  foreground:    &foreground    '#c5c8c6'\n  black:         &black         '#282a2e'\n  red:           &red           '#a54242'\n  green:         &green         '#8c9440'\n  yellow:        &yellow        '#de935f'\n  blue:          &blue          '#5f819d'\n  magenta:       &magenta       '#85678f'\n  cyan:          &cyan          '#5e8d87'\n  white:         &white         '#707880'\n  brightBlack:   &brightBlack   '#373b41'\n  brightRed:     &brightRed     '#cc6666'\n  brightGreen:   &brightGreen   '#b5bd68'\n  brightYellow:  &brightYellow  '#f0c674'\n  brightBlue:    &brightBlue    '#81a2be'\n  brightMagenta: &brightMagenta '#b294bb'\n  brightCyan:    &brightCyan    '#8abeb7'\n  brightWhite:   &brightWhite   '#c5c8c6'\n\ncolor:\n  - *black\n  - *red\n  - *green\n  - *yellow\n  - *blue\n  - *magenta\n  - *cyan\n  - *white\n  - *brightBlack\n  - *brightRed\n  - *brightGreen\n  - *brightYellow\n  - *brightBlue\n  - *brightMagenta\n  - *brightCyan\n  - *brightWhite\n" name=/var/home/jeslinmx/.chezmoidata/colors.yaml perm=420 size=1016

It finds the file in the chezmoi folder, but then tries to find it again in $HOME.