twpayne / chezmoi

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

`chezmoi apply` causing errors on `promptString` #2610

Closed evanrittenhouse closed 1 year ago

evanrittenhouse commented 1 year ago

What exactly are you trying to do?

I've recently added a {{ $email := promptString "email" - }} block to my chezmoi.yaml.tmpl file, similar to the reference guide. When I run chezmoi apply, I get

chezmoi: template: dot_config/chezmoi/chezmoi.yaml.tmpl:1: function "promptString" not defined

I understand that promptString can only be ran when running chezmoi init - is there a way to keep this line in my chezmoi.yaml.tmpl file without seeing the error every time I run chezmoi apply? Describe in as much detail as possible.

What have you tried so far?

Above Describe what you have tried so far. Above

Where else have you checked for solutions?

Github, Google

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

$ chezmoi --verbose $COMMAND

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.17.1, commit 565cbbe117746aa6bfec5f2cee20ae4cbbb5e645, built at 2022-05-30T10:24:34Z, built by goreleaser warning latest-version v2.27.2 ok os-arch linux/amd64 (Ubuntu 22.04.1 LTS (Jammy Jellyfish)) ok uname Linux laptop 5.15.0-53-generic #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux ok go-version go1.18.2 (gc) ok executable ~/bin/chezmoi ok upgrade-method replace-executable ok config-file ~/.config/chezmoi/chezmoi.yaml ok source-dir ~/.local/share/chezmoi is a directory warning suspicious-entries ~/.local/share/chezmoi/.chezmoidata_template.yaml and ~/.local/share/chezmoi/dot_config/chezmoi/chezmoi.yaml.tmpl ok working-tree ~/.local/share/chezmoi is a directory ok dest-dir ~ is a directory ok shell-command found /home/linuxbrew/.linuxbrew/bin/fish ok shell-args /home/linuxbrew/.linuxbrew/bin/fish ok cd-command found /home/linuxbrew/.linuxbrew/bin/fish ok cd-args /home/linuxbrew/.linuxbrew/bin/fish ok edit-command found /home/linuxbrew/.linuxbrew/bin/nvim ok edit-args nvim info diff-command not set ok umask 002 ok git-command found /usr/bin/git, version 2.34.1 warning merge-command vimdiff not found in $PATH info age-command age not found in $PATH ok gpg-command found /usr/bin/gpg, version 2.2.27 info pinentry-command not set info 1password-command op not found in $PATH info bitwarden-command bw not found in $PATH info gopass-command gopass not found in $PATH info keepassxc-command keepassxc-cli not found in $PATH info keeper-command keeper not found in $PATH info keepassxc-db not set info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info vault-command vault not found in $PATH info secret-command not set ```

Additional context

Add any other context about the problem here.

twpayne commented 1 year ago

You need to use a config file template, which will live in .local/share/chezmoi/.chezmoi.yaml.tmpl.

The config file is special because if you were to treat it as a normal dotfile (as you are currently doing with ~/.local/share/chezmoi/chezmoi.yaml.tmpl) it does not work because the config file is only updated after chezmoi runs.

Please also check the other warnings in the output of chezmoi doctor, as they indicate other problems with your setup.

twpayne commented 1 year ago

Hopefully this answers your question. Please re-open if needed.