Nix Deployment
Deploy Aya using Nix for fully reproducible builds and declarative infrastructure configuration.Why Nix?
Reproducible
Same input = same output, always
Declarative
Infrastructure as code
Atomic
Rollbacks are instant and safe
Development Environment
Aya includes aflake.nix that provides all development tools:
flake.nix
Entering the Shell
- Exact versions of all tools (Go 1.25, Node 20, Deno, etc.)
- Same environment on macOS, Linux, NixOS
- No global installation pollution
- Instant rollback to previous versions
NixOS Module
For NixOS servers, create a module for Aya:/etc/nixos/modules/aya.nix
Aya Package Definition
/etc/nixos/modules/aya-package.nix
NixOS Configuration
/etc/nixos/configuration.nix
Docker with Nix
Build Docker images using Nix for reproducibility:flake.nix (extended)
- Bit-for-bit reproducible images
- Layer caching optimized by Nix
- No Dockerfile needed
- Smaller images (only runtime dependencies)
Secrets Management
agenix (Recommended)
Use agenix for encrypted secrets:sops-nix (Alternative)
Use sops-nix for YAML-based secrets:secrets.yaml
Deployment Workflow
Using deploy-rs
deploy-rs enables declarative deployments:flake.nix (extended)
CI/CD with Nix
GitHub Actions
.github/workflows/deploy.yml
Monitoring with Nix
Prometheus + Grafana
/etc/nixos/monitoring.nix
Advantages of Nix Deployment
Reproducibility
Same flake.lock = identical builds across all environments
Atomic Rollbacks
Instant rollback to any previous version
No Drift
Declarative config prevents configuration drift
Efficient Updates
Binary cache eliminates rebuild times
Troubleshooting
Hash mismatch errors
Hash mismatch errors
Update hashes after changing dependencies:
Service fails to start
Service fails to start
Check systemd logs:
Nix store disk space
Nix store disk space
Garbage collect old generations:
Next Steps
Docker Deployment
Alternative deployment with Docker Compose
Environment Variables
Configuration reference
Development Setup
Local development with Nix
Architecture
Understand the system design