twpayne / chezmoi

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

Fallback File for When Encryption Key not Present #2711

Closed ProfessorManhattan closed 1 year ago

ProfessorManhattan commented 1 year ago

What exactly are you trying to do?

I am trying to allow the user to use encrypted_ files by default but I would also like to provide an alternate file that is used in place of the encrypted_ file if the Age key is not present on the system.

What have you tried so far?

I tried removing the encrypted_ files and replacing them with encrypted-fallback_ files but it is messy and overly complicated. I'm looking for the "Chezmoi" way of handling it.

Where else have you checked for solutions?

Additional context

I have a rather elaborate Chezmoi project and would like to give people the ability to use the project without having to set up encryption beforehand. The project is here: https://gitlab.com/megabyte-labs/install.doctor

twpayne commented 1 year ago

Interesting project, really pushing chezmoi to the limit :)

I think what you want can be achieved with a template:

{{ if stat "path/to/age/key.txt" -}}
{{   include "path/to/encrypted/file" | decrypt -}}
{{ else -}}
{{   include "path/to/fallback/file" }}
{{ end }}
ProfessorManhattan commented 1 year ago

Hey @twpayne -- yeah... Chezmoi is really cool thanks for making it... it'd be cool if we could make the scripts asynchronous

twpayne commented 1 year ago

it'd be cool if we could make the scripts asynchronous

This would make chezmoi very non-deterministic and likely cause a lot of problems due to implicit dependencies between scripts (e.g. a later script needing a package that is installed by an earlier script). You can of course already use concurrency within a single a script, e.g. have a script that runs a number of other scripts in the background and then waits for them all to finish.

twpayne commented 1 year ago

Hopefully this is now resolved. Please re-open if needed.