Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to add ~/.config/chezmoi/chezmoi.toml to chezmoi #3638

Closed
4 tasks done
youtux opened this issue Mar 9, 2024 · 12 comments
Closed
4 tasks done

Unable to add ~/.config/chezmoi/chezmoi.toml to chezmoi #3638

youtux opened this issue Mar 9, 2024 · 12 comments
Labels
support Support request

Comments

@youtux
Copy link

youtux commented Mar 9, 2024

What exactly are you trying to do?

I made a config file so that every edit I make is autocommited and pushed. I would like to have this configuration apply to all the machines I use.

What have you tried so far?

I tried to add the config file to chezmoi, but it complains saying it's protected:

❯ chezmoi add ~/.config/chezmoi/chezmoi.toml
chezmoi: /Users/youtux/.config/chezmoi/chezmoi.toml: cannot add chezmoi file to chezmoi (/Users/youtux/.config/chezmoi/chezmoi.toml is protected)

Where else have you checked for solutions?

Output of any commands you've tried with --verbose flag

chezmoi --verbose  add ~/.config/chezmoi/chezmoi.toml
chezmoi: /Users/youtux/.config/chezmoi/chezmoi.toml: cannot add chezmoi file to chezmoi (/Users/youtux/.config/chezmoi/chezmoi.toml is protected)

Output of chezmoi doctor

chezmoi doctor
RESULT   CHECK                       MESSAGE
ok       version                     v2.47.1, commit 1ce6b2eeb0caf75bd91883e5a968e713a26e7be2, built at 2024-03-03T00:47:52Z, built by Homebrew
ok       latest-version              v2.47.1
ok       os-arch                     darwin/arm64
ok       uname                       Darwin m1pro.local 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64
ok       go-version                  go1.22.0 (gc)
ok       executable                  /opt/homebrew/bin/chezmoi
ok       upgrade-method              brew-upgrade
ok       config-file                 ~/.config/chezmoi/chezmoi.toml, last modified 2024-03-09T16:12:29+01:00
ok       source-dir                  ~/.local/share/chezmoi is a git working tree (clean)
ok       suspicious-entries          no suspicious entries
ok       working-tree                ~/.local/share/chezmoi is a git working tree (clean)
ok       dest-dir                    ~ is a directory
ok       umask                       022
ok       cd-command                  found /bin/zsh
ok       cd-args                     /bin/zsh
info     diff-command                not set
ok       edit-command                found ~/.local/bin/codew
ok       edit-args                   ~/.local/bin/codew
ok       git-command                 found /opt/homebrew/bin/git, version 2.44.0
ok       merge-command               found /opt/homebrew/bin/vimdiff
ok       shell-command               found /bin/zsh
ok       shell-args                  /bin/zsh
info     age-command                 age not found in $PATH
ok       gpg-command                 found /opt/homebrew/bin/gpg, version 2.4.4
info     pinentry-command            not set
ok       1password-command           found /opt/homebrew/bin/op, version 2.24.0
info     bitwarden-command           bw not found in $PATH
info     bitwarden-secrets-command   bws not found in $PATH
info     dashlane-command            dcli not found in $PATH
info     doppler-command             doppler 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     vlt-command                 vlt not found in $PATH
info     secret-command              not set

Additional context

Add any other context about the problem here.

@youtux youtux added the support Support request label Mar 9, 2024
@bradenhilton
Copy link
Collaborator

You need to use .chezmoi.$FORMAT.tmpl. In your case it would be .chezmoi.toml.tmpl.

You can use your existing config by simply moving/renaming it.

Running chezmoi init will execute this template and generate a config.

@youtux
Copy link
Author

youtux commented Mar 9, 2024

shouldn't then I be able to run chezmoi add --template ~/.config/chezmoi/chezmoi.toml?
It still gives me the same error. If this is an allowed way, why would chezomoi not allow that operation?

@bradenhilton
Copy link
Collaborator

That command would create ~/.local/share/chezmoi/dot_config/chezmoi/chezmoi.toml.tmpl which is still incorrect.

We prevent this because allowing this means that any changes you make to your config would always be one chezmoi apply behind the rest of your dotfiles.

You can move ~/.config/chezmoi/chezmoi.toml to ~/.local/share/chezmoi/.chezmoi.toml.tmpl then run chezmoi init.

Every time you change your config template you must also run chezmoi init to regenerate your config.

@youtux
Copy link
Author

youtux commented Mar 9, 2024

I wish the docs would describe this specific use case, it was not immediate to me how this works.

For posterity, I solved the issue running the following:

mv ~/.config/chezmoi/chezmoi.toml "$(chezmoi source-path)/.chezmoi.toml.tmpl"
chezmoi apply
chezmoi init

@halostatue
Copy link
Collaborator

They do:

If you have some suggestions for improving the documentation to make this easier to find, we will happily accept either pull requests or new issues with those suggestions. But it is in the documentation.

We do request that people search all issues before opening a new one, as a closely related question was asked two days ago (#3634), which has pointers to #3405, #2854, and #3285—the latter two of which have the text from the error in their title and/or body.

@youtux
Copy link
Author

youtux commented Mar 10, 2024

Ah sorry, I only used google assuming it would have indexed issues with that string.
What I was suggesting was to add this to a more visible place in the docs, like the FAQs, since this seem to be a frequently asked question :) maybe even including this error message for better indexing.

Or, why not allowing that file to be just added to the dotfiles, since one can already workaround it by adding the .chezmoi.toml.tmpl?

@halostatue
Copy link
Collaborator

Ah sorry, I only used google assuming it would have indexed issues with that string. What I was suggesting was to add this to a more visible place in the docs, like the FAQs, since this seem to be a frequently asked question :) maybe even including this error message for better indexing.

Or, why not allowing that file to be just added to the dotfiles, since one can already workaround it by adding the .chezmoi.toml.tmpl?

The issues linked above have the reasons why this cannot be resolved, but #3405 (comment) (and probably other linked issues) explains why it has to be handled differently.

@halostatue halostatue pinned this issue Mar 10, 2024
@youtux
Copy link
Author

youtux commented Mar 10, 2024

got it. One last suggestion then: maybe it would be worth to have the error message from chezmoi add ~/.config/chezmoi/chezmoi.toml would link to the page that explains how to add chezmoi config to the tracked dotfiles.

@twpayne
Copy link
Owner

twpayne commented Mar 10, 2024

One last suggestion then: maybe it would be worth to have the error message from chezmoi add ~/.config/chezmoi/chezmoi.toml

Good idea. Implemented in #3644. I've used text instead of a URL (as the URL might change over time), but the text should be a sufficient clue for future users.

@twpayne
Copy link
Owner

twpayne commented Mar 10, 2024

BTW @youtux you should remove this file from your dotfiles repo.

@bradenhilton
Copy link
Collaborator

That entire chezmoi directory should be removed.

@twpayne do we not also protect against chezmoi add */.chezmoiignore?

@twpayne
Copy link
Owner

twpayne commented Mar 10, 2024

@twpayne do we not also protect against chezmoi add */.chezmoiignore?

Not at the moment. At the moment, chezmoi protects against adding files in its config (~/.config/chezmoi), state (~/.local/share/chezmoi), and cache (~/.cache/chezmoi) directories. .chezmoiignore files have no effect outside of chezmoi's state.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
support Support request
Projects
None yet
Development

No branches or pull requests

4 participants