twpayne / chezmoi

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

"config file template has changed" message when it has not #2885

Closed halostatue closed 1 year ago

halostatue commented 1 year ago

Describe the bug

I’m not entirely sure why, but it looks like I’m seeing fairly frequent reports that config file template has changed when I have made no change to $CHEZMOI_SOURCE_DIR/.chezmoi.toml.tmpl.

To reproduce

Unclear as yet. I plan on investigating, but am opening this for tracking.

Expected behavior

config file template has changed should only appear when .chezmoi.toml.tmpl has changed on disk. I’m not sure where / how this particular state piece is being kept, but it feels (no evidence any direction) that this is purely on a date comparison, not a date comparison + hash comparison.

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.32.0, commit 5ac7d4e8e6589c5deda835d84469831f345c6847, built at 2023-03-12T01:50:00Z, built by goreleaser warning latest-version v2.33.0 ok os-arch darwin/arm64 ok uname Darwin Austins-MacBook-Pro.local 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 arm64 ok go-version go1.20.2 (gc) ok executable ~/go/bin/chezmoi ok upgrade-method replace-executable ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2023-03-20T00:39:32-04:00 warning source-dir ~/.local/share/chezmoi is a git working tree (dirty) ok suspicious-entries no suspicious entries warning working-tree ~/.local/share/chezmoi is a git working tree (dirty) ok dest-dir ~ is a directory ok umask 022 ok cd-command found /opt/homebrew/bin/fish ok cd-args /opt/homebrew/bin/fish info diff-command not set ok edit-command found /opt/homebrew/bin/vim ok edit-args /opt/homebrew/bin/vim ok git-command found /opt/local/bin/git, version 2.39.2 ok merge-command found /opt/homebrew/bin/vimdiff ok shell-command found /opt/homebrew/bin/fish ok shell-args /opt/homebrew/bin/fish ok age-command found ~/go/bin/age, version 1.1.1 ok gpg-command found /usr/local/MacGPG2/bin/gpg, version 2.2.41 info pinentry-command not set ok 1password-command found /usr/local/bin/op, version 2.13.1 info bitwarden-command bw not found in $PATH info dashlane-command dcli not found in $PATH info gopass-command gopass not found in $PATH info keepassxc-command keepassxc-cli not found in $PATH info keepassxc-db not set info keeper-command keeper not found in $PATH info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info passhole-command ph not found in $PATH info rbw-command rbw not found in $PATH info vault-command vault not found in $PATH info secret-command not set ```
twpayne commented 1 year ago

chezmoi uses the SHA256 of the config file template's content only. You can see this with:

$ chezmoi state get-bucket --bucket=configState
{
  "configState": {
    "configTemplateContentsSHA256": "ad7d2ed6ea1091fd5aeeb14110eda687fd2563b87d3a82ece16ff46463288dc7"
  }
}
halostatue commented 1 year ago

I haven’t seen it since I opened this, but I know that I’ve seen it in cases where (a) I haven’t updated the inputs to the templates (my .chezmoi.toml.tmpl is probably more complex than it needs to be, but I don’t currently know the best way to simplify it, because I want my template resolution more data driven than hard-coded) and (b) I haven’t updated .chezmoi.toml.tmpl itself. There’s something going on, but I’ll need to throw some debugging in when I see this again.

twpayne commented 1 year ago

Have you seen this issue again? If not, would you mind closing this issue and re-opening it when you do see the issue again?

halostatue commented 1 year ago

No sooner than I close this and I get the message again.

    modified:   Setup/Gobin
    modified:   home/.chezmoiignore
    modified:   home/.chezmoiscripts/run_onchange_after_install-4-gobin.sh.tmpl
    renamed:    home/private_Library/Application Support/lazygit/config.yml -> home/.chezmoitemplates/lazygit_config.yml.tmpl
    new file:   home/.chezmoitemplates/programs.tmpl
    new file:   home/private_Library/Application Support/lazygit/config.yml.tmpl
    modified:   home/private_dot_config/brew/config.fish.tmpl
    modified:   home/private_dot_config/brew/config.sh.tmpl
    modified:   home/private_dot_config/git/aliases.tmpl
    modified:   home/private_dot_config/git/attributes.tmpl
    modified:   home/private_dot_config/git/diff-merge.tmpl
    new file:   home/private_dot_config/lazygit/config.yml.tmpl
    modified:   home/private_dot_config/nvim/lua/plugins/syntax.lua
    modified:   home/private_dot_gitconfig.tmpl
    modified:   home/private_dot_gpg-agent.conf.tmpl
    modified:   home/private_dot_ssh/private_config.tmpl
    modified:   home/private_dot_vim/config/plugins.vim

So, the only thing that I figure that changed which could have triggered this is home/.chezmoiignore.

Any ideas before I add some debugging to understand this?

twpayne commented 1 year ago

Any ideas before I add some debugging to understand this?

I don't know, sorry. The relevant code is here.

halostatue commented 1 year ago

Ok. I’m going to close this again for now because I did have some changes to make last night after this. Once that’s done, I’ll see if it happens again and add some debugging.