Architecture
The secrets management system consists of:- agenix: Encrypts secrets with age public keys
- sops-nix: Alternative secrets backend (configured via
.sops.yaml) - secrets.nix: Centralized secrets configuration with user/team mapping
- agenix-shell: Makes secrets available in development shells
Secrets Configuration Structure
Thesecrets.nix file defines three key components:
1. User Public Keys
2. Per-User Secrets
3. Team Secrets
Adding a New Secret
Create the encrypted secret file
Use This opens your
agenix to create and edit the secret:$EDITOR to input the secret value. The file is automatically encrypted with the appropriate public keys based on your secrets.nix configuration.SOPS Configuration
The.sops.yaml file configures sops-nix with age keys for different users and systems:
Path-based Encryption Rules
SOPS uses path regex patterns to determine which keys can decrypt files:- Home secrets:
homes/<user>/files are encrypted for that user and admins - System secrets:
systems/<hostname>/files include the system’s age key
Shell Integration
Theagenix-shell integration automatically loads secrets as environment variables in your development shell:
- Converted to uppercase for environment variable names
- Only loaded for users with access
- Available in
nix developshells
Security Best Practices
Converting SSH Keys to Age
To get an age public key from an SSH key:Editing Existing Secrets
To modify an encrypted secret:Common Issues
”No decryption key found”
Ensure your private key is available:- SSH key at
~/.ssh/id_ed25519 - Age key at
~/.config/age/key.txt
”Public key not found in secrets.nix”
Add your user to theusers mapping in secrets.nix with your SSH public key.
Secrets not loading in shell
Check that:- You’re in a
nix developshell with agenix-shell enabled - Your user has access to the secret in
secrets.nix - The secret file exists at
secrets/<name>.age