When I started to learn Nix and NixOS, I found it difficult to, on top of everything else to learn, also learn how to work with tools such as sops-nix or agenix to setup the secrets. Also, I did not want to do a mistake and put passwords into the nix store before I had become more familiar with NIxOS as a whole. Secrets is also something you can not put off to learn later, you need to find a solution early on.
So I decided to copy my passwords to files and set appropriate file permissions on them using ordinary shell scripts. I still do this, but I have streamlined this process over time. My current method is to run a command like the below
(set -e; pass nixos/secrets && cat setup-secrets.sh) | ssh hostname sudo bash -s
This concatenates the secrets and their setup mechanism to a single shell script that becomes standard input to bash, effectively executing it from one host to another without any intermediate file representation.
My secrets master is my pass store (https://www.passwordstore.org). I already use this for all my other passwords so using this also for my NixOS secrets is convenient for me.
The nixos/secrets secret should contains all my secrets formatted using shell variable syntax. Example
gmailkey=“mygmailpassword”
setup-secrets.sh contains statements such as
install -m 400 <(echo “$gmailkey”) /persist/secrets/gmailkey
This stores the gmailkey value (the password) in the designated location, with the right file permissions immediately, and I feel confident that my secrets did not leak along the way.
And then I use gmailkey in msmtp like
passwordeval = “${pkgs.coreutils}/bin/cat /persist/secrets/gmailkey”;
I am curious to hear what others think about this way to handle secrets.