mirror of
https://github.com/nmasur/dotfiles
synced 2025-07-05 15:00:14 +00:00
new secrets management system
This commit is contained in:
19
apps/encrypt-secret.nix
Normal file
19
apps/encrypt-secret.nix
Normal file
@ -0,0 +1,19 @@
|
||||
{ pkgs, ... }: {
|
||||
|
||||
# nix run github:nmasur/dotfiles#encrypt-secret > private/mysecret.age
|
||||
|
||||
type = "app";
|
||||
|
||||
program = builtins.toString (pkgs.writeShellScript "encrypt-secret" ''
|
||||
printf "\nEnter the secret data to encrypt for all hosts...\n\n" 1>&2
|
||||
read -p "Secret: " secret
|
||||
printf "\nEncrypting...\n\n" 1>&2
|
||||
tmpfile=$(mktemp)
|
||||
echo "''${secret}" > ''${tmpfile}
|
||||
${pkgs.age}/bin/age --encrypt --armor --recipients-file ${
|
||||
builtins.toString ../hosts/public-keys
|
||||
} $tmpfile
|
||||
rm $tmpfile
|
||||
'');
|
||||
|
||||
}
|
27
apps/reencrypt-secrets.nix
Normal file
27
apps/reencrypt-secrets.nix
Normal file
@ -0,0 +1,27 @@
|
||||
{ pkgs, ... }: {
|
||||
|
||||
# nix run github:nmasur/dotfiles#reencrypt-secrets ./private
|
||||
|
||||
type = "app";
|
||||
|
||||
program = builtins.toString (pkgs.writeShellScript "reencrypt-secrets" ''
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Must provide directory to reencrypt."
|
||||
exit 1
|
||||
fi
|
||||
encrypted=$1
|
||||
for encryptedfile in ''${1}/*; do
|
||||
tmpfile=$(mktemp)
|
||||
echo "Decrypting ''${encryptedfile}..."
|
||||
${pkgs.age}/bin/age --decrypt \
|
||||
--identity ~/.ssh/id_ed25519 $encryptedfile > $tmpfile
|
||||
echo "Encrypting ''${encryptedfile}..."
|
||||
${pkgs.age}/bin/age --encrypt --armor --recipients-file ${
|
||||
builtins.toString ../hosts/public-keys
|
||||
} $tmpfile > $encryptedfile
|
||||
rm $tmpfile
|
||||
done
|
||||
echo "Finished."
|
||||
'');
|
||||
|
||||
}
|
Reference in New Issue
Block a user