Closed haroldojunios closed 1 year ago
Use include
. This is untested, but it should work.
.chezmoiignore
:
.ssh/work-ssh.id_rsa.enc
.ssh/home-ssh.id_rsa.enc
private_dot_ssh/private_id_rsa.tmpl
:
{{- /* private_dot_ssh/private_id_rsa.tmpl */ -}}
{{- if .isWork -}}
{{- include "./work-ssh.id_rsa.enc" -}}
{{- else -}}
{{- include "./home-ssh.id_rsa.enc" -}}
{{- end -}}
private_dot_ssh/work-ssh.id_rsa.enc
:
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBSd21valRHL0VzaVFPajlU ...
-----END AGE ENCRYPTED FILE-----
private_dot_ssh/home-ssh.id_rsa.enc
:
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBtbHdSeUlDOStZQjZBK2dk ...
-----END AGE ENCRYPTED FILE-----
Thank you for the fast reply. I tried it, but:
private_dot_ssh/private_id_rsa.tmpl
from .
to private_dot_ssh
, it was giving the error: chezmoi: template: private_dot_ssh/private_id_rsa.tmpl:4:4: executing "private_dot_ssh/private_id_rsa.tmpl" at <include "./home-ssh.id_rsa.enc">: error calling include: open /home/haroldo/.local/share/chezmoi/home-ssh.id_rsa.enc: no such file or directory
;encrypted_
to the file private_dot_ssh/private_id_rsa.tmpl
it gives the same error about the age header.Is there some way to decrypt the .enc
files before the template substitution?
There is: decrypt, complete with an example that does exactly what you want.
Thanks @halostatue, it worked!
For reference:
.chezmoiignore:
.ssh/work-ssh.id_rsa.age
.ssh/home-ssh.id_rsa.age
private_dot_ssh/private_id_rsa.tmpl:
{{- /* private_dot_ssh/private_id_rsa.tmpl */ -}}
{{- if .isWork -}}
{{ joinPath .chezmoi.sourceDir "private_dot_ssh/work-ssh.id_rsa.age" | include | decrypt }}
{{- else -}}
{{ joinPath .chezmoi.sourceDir "private_dot_ssh/home-ssh.id_rsa.age" | include | decrypt }}
{{- end -}}
private_dot_ssh/work-ssh.id_rsa.age:
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBSd21valRHL0VzaVFPajlU ...
-----END AGE ENCRYPTED FILE-----
private_dot_ssh/home-ssh.id_rsa.age:
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBtbHdSeUlDOStZQjZBK2dk ...
-----END AGE ENCRYPTED FILE-----
What exactly are you trying to do?
I have 2 machines, one personal and one for work. I want to have different
~/.ssh/id_rsa
files, in wich they are encrypted on my dotfiles repo.What have you tried so far?
I tried adding the
~/.ssh/id_rsa
file from my home computer usingchezmoi add --encrypt -T ~/.ssh/id_rsa
and templating it with another ssh-key, resulting in:But when I run
chezmoi apply
is gives me:I suspect that the decryption is happening before the template substitution.
Where else have you checked for solutions?
Output of any commands you've tried with
--verbose
flagOutput of
chezmoi doctor
Additional context
Add any other context about the problem here. My
.chezmoi.toml
: