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

Some variables from .chezmoi.config are still inaccessible in templates #3582

Closed
juliuswz opened this issue Feb 19, 2024 · 2 comments · Fixed by #3597
Closed

Some variables from .chezmoi.config are still inaccessible in templates #3582

juliuswz opened this issue Feb 19, 2024 · 2 comments · Fixed by #3597
Labels
bug Something isn't working

Comments

@juliuswz
Copy link

Describe the bug

After digging into #2940, #2942, and #2943, I am still encountering issues with the .chezmoi.config template variables being inaccessible.

It seems that not all variables are accessible, such as identity from age.

To reproduce

.chezmoi.toml.tmpl:

{{- $identity := promptStringOnce . ".chezmoi.config.age.identity" "Encryption key path (age)" -}}

encryption = "age"

[age]
identity = {{ $identity | quote }}
symmetric = true

chezmoi init output:

chezmoi: template: chezmoi.toml:11:17: executing "chezmoi.toml" at <promptStringOnce . ".chezmoi.config.age.identity" "Encryption key path (age)">: error calling promptStringOnce: empty path element at index 0

The error occurs even if I pre-populate ~/.config/chezmoi/chezmoi.toml:

encryption = "age"

[age]
identity = "~/some/path"
symmetric = true

Expected behavior

$ chezmoi execute-template '{{ .chezmoi.config.age.identity }}'
~/some/path

Additional context

Even the chezmoi data command does not return the values:

"age": {
        "args": null,
        "command": "age",
        "identities": null,
        "identity": {},
        "passphrase": false,
        "recipient": "",
        "recipients": null,
        "recipientsFile": {},
        "recipientsFiles": null,
        "suffix": ".age",
        "symmetric": true,
        "useBuiltin": false
      }
$ chezmoi --version 
chezmoi version v2.46.1, built at 2024-02-12T09:19:56Z
@twpayne
Copy link
Owner

twpayne commented Feb 23, 2024

Re:

{{- $identity := promptStringOnce . ".chezmoi.config.age.identity" "Encryption key path (age)" -}}

I think this should be

{{- $identity := promptStringOnce . "chezmoi.config.age.identity" "Encryption key path (age)" -}}

i.e. remove the leading .. The second argument to promptStringOnce is a path to a field in an object, not a template expression.

@twpayne twpayne added support Support request bug Something isn't working and removed support Support request labels Feb 23, 2024
@twpayne
Copy link
Owner

twpayne commented Feb 24, 2024

Sorry, there is also a bug in chezmoi. It is the same bug as #3593.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants