Overview
Secrets are managed using:- SOPS: For encrypting and managing secret files
- age: Modern encryption tool using SSH keys
- agenix: NixOS integration for SOPS
- agenix-shell: Development shell integration
Secret Architecture
User-Based Access
Secrets are organized by user and team access:Setting Up Secrets
Generate SSH Key (If Needed)
Create an ED25519 SSH key for encryption:This key will be used for encrypting/decrypting secrets.
Create a Secret File
Use agenix to create and encrypt a secret:This opens your
$EDITOR to input the secret value.Using Secrets
In NixOS Configuration
Reference secrets in your system configuration:In Development Shell
Secrets are automatically loaded as environment variables in the dev shell:In Home Manager
For user-level secrets:Secret Management Workflows
Adding a New Secret
Adding a New Secret
- Update
secrets.nixwith user/team access - Create the secret file:
- Commit the encrypted file:
Rotating a Secret
Rotating a Secret
- Edit the existing secret:
- Update the value and save
- Commit the change:
- Deploy to systems:
Granting Access to a User
Granting Access to a User
- Get user’s SSH public key
- Add to
secrets.nix: - Add user to team or grant individual access:
- Re-encrypt all secrets:
- Commit changes:
Revoking Access
Revoking Access
- Remove user from
secrets.nix - Re-encrypt secrets:
- Commit and deploy immediately
Secret Organization
Directory Structure
Naming Conventions
- Use lowercase with underscores:
api_key.age - Be descriptive:
cloudflare_api_token.agenotcf.age - Group by service:
postgres_password.age,postgres_user.age
Templates Integration
The empty template includes secrets configuration:secrets.nixwith base configurationshell.nixwith agenix integration- Pre-configured flake inputs for agenix