This repository is a template for managing encrypted secrets with SOPS and age encryption, designed to work with nixos-dotfiles.
Create your own private repository from this template to store your encrypted secrets.
Generate your personal age key:
mkdir -p ~/.config/sops/age
age-keygen -o ~/.config/sops/age/keys.txtThe public key will be displayed - copy it for the next step.
Replace the age keys in .sops.yaml with your own:
keys:
- &ci age1vlcfusx5f235x84rx5gftfshc7twhz3ydj3mmwev4a44m0j2gdvsd9vj3n # Replace with CI key
- &yourusername age1your...publickey # Replace with your personal key
creation_rules:
- path_regex: secrets.yaml
key_groups:
- age:
- *ci
- *yourusername# Edit the secrets file with SOPS (it will re-encrypt with your keys)
sops secrets.yamlIn your fork of nixos-dotfiles, update the flake.nix to point to your private vault:
inputs = {
# ... other inputs ...
private-vault = {
url = "github:yourusername/your-vault-repo";
};
}This repository includes a GitHub Action workflow that allows you to add new age public keys and automatically re-encrypt all secrets without having access to the original age private key locally.
Store your CI age private key in GitHub Actions secrets as SOPS_AGE_KEY. This key must be one of the existing age recipients in .sops.yaml.
To add a new age public key from the GitHub Actions UI:
- Navigate to the Actions tab in your repository
- Select the Update SOPS Secrets workflow
- Click Run workflow
- Enter the new age public key when prompted
- Click Run workflow to start the process
The workflow will automatically add the new public key to .sops.yaml, re-encrypt secrets.yaml with the updated recipient list, and commit the changes back to the repository.
This approach doesn't require SSH key management.
Step 1: Create a Personal Access Token (PAT)
- Create a Personal Access Token with
reposcope - Store it in GitHub Actions secrets as
GH_TOKEN
Step 2: Use github: URLs in flake.nix
inputs.private-vault = {
url = "github:yourusername/your-vault-repo";
};Step 3: Configure authentication in workflow
env:
NIX_CONFIG: |
experimental-features = nix-command flakes
access-tokens = github.com=${{ secrets.GH_TOKEN }}This method is simpler, doesn't require SSH key management, and works seamlessly with Nix flakes.