twpayne / chezmoi

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

[Chezmoi template] include files from destination directory that is ignored in the source dir #3312

Closed bonecountysheriff closed 10 months ago

bonecountysheriff commented 10 months ago

What exactly are you trying to do?

There's a folder in the destination directory that I cannot include in the dotfiles because of security reasons (my dotfiles need to be publicly hosted). This directory is a collection of text config files and I need to include them in a chezmoi template file.

I need to know if this is possible using chezmoi templates.

\<source-dir>/config.txt.tmpl

# usual file contents which are public
.
.
.
.

[Include <destination-dir>/ignored-dir/*]

When applied, this should lead to the following destination config file.

\<destination-dir>/config.txt

# usual file contents which are public
.
.
.
.

# contents from <destination-dir>/ignored-dir/file1
.
.

# contents from <destination-dir>/ignored-dir/file2
.
.

# contents from <destination-dir>/ignored-dir/file3
.
.

What have you tried so far?

I have gone through https://www.chezmoi.io/user-guide/include-files-from-elsewhere/, but I'm not sure it is what I am looking for since it mentions web hosted files but not local ones.

Where else have you checked for solutions?

twpayne commented 10 months ago

A couple of options:

1) Store the private parts of the file in your password manager and use a password manager template function to retrieve them. I use this approach. 2) Encrypt the private parts of the file and use the decrypt template function to decrypt them. 3) Include the parts as separate files in either .chezmoitemplates or .chezmoidata in your source directory and use .gitignore to avoid storing them in your git repo. You'll then need to distribute and update the files manually.