This guide explains how to set up SOPS (Secrets OPerationS) for encrypted secrets management in NixMox.
SOPS is Mozilla's tool for encrypting and decrypting files containing secrets. It integrates seamlessly with NixOS through the sops-nix module.
-
Install SOPS:
# On NixOS nix-env -iA nixpkgs.sops # On other systems nix-env -iA nixpkgs.sops
-
Install age (for key generation):
nix-env -iA nixpkgs.age
# Generate age key pair
age-keygen -o ~/.config/sops/age/keys.txt
# Display public key (add this to .sops.yaml)
cat ~/.config/sops/age/keys.txt | grep "public key"# Generate separate keys for different environments
age-keygen -o ~/.config/sops/age/production.txt
age-keygen -o ~/.config/sops/age/staging.txt# .sops.yaml
creation_rules:
- path_regex: \.yaml$
age: >-
age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p
age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p-
Add your SSH public keys:
nixmox: ssh_authorized_keys: - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... your-key-here"
-
Add your age public key:
nixmox: age_key: "age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p"
# Encrypt the secrets file
sops -e -i secrets/default.yaml
# Verify encryption
sops -d secrets/default.yamlThe flake already includes sops-nix, but verify:
inputs = {
sops-nix.url = "github:Mic92/sops-nix";
# ...
};# Add SOPS configuration
sops.defaultSopsFile = ../../secrets/default.yaml;
sops.age.keyFile = "/path/to/age/key.txt"; # Set this path# Deploy with encrypted secrets
./scripts/deploy-remote.sh authentik YOUR_CONTAINER_IP-
Age key not found:
# Check age key location ls -la ~/.config/sops/age/ # Update sops.age.keyFile path in flake.nix
-
SOPS not installed:
# Install on remote host nix-env -iA nixpkgs.sops -
Permission denied:
# Fix age key permissions chmod 600 ~/.config/sops/age/keys.txt
# .sops.yaml
creation_rules:
- path_regex: production\.yaml$
age: age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p
- path_regex: staging\.yaml$
age: age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p# Generate new key
age-keygen -o ~/.config/sops/age/new-key.txt
# Re-encrypt with new key
sops -e -i secrets/default.yaml- Never commit unencrypted secrets
- Use different keys for different environments
- Rotate keys regularly
- Backup age keys securely
- Use strong passwords for all services
- Add your SSH public keys to
secrets/default.yaml - Generate age keys and update
.sops.yaml - Encrypt the secrets file with
sops -e -i secrets/default.yaml - Deploy and test the configuration