Why Nix?
- Reproducible builds: Exact same toolchain across all machines via
flake.lock - Zero configuration: PostgreSQL, PostGIS, Prisma engines auto-configured
- Multi-platform: Works on Linux (x86_64/aarch64) and macOS (x86_64/Apple Silicon)
- Version pinning: Matches production PostgreSQL/PostGIS versions exactly
- No Docker required: Native processes for better performance
Installation
Install Nix with flakes enabled:This installer automatically enables flakes and other recommended features. It works on Linux, macOS, and WSL2.
Quick start
Enter the development shell
Database modes
Local database via Nix (default)
Starts PostgreSQL + PostGIS as native processes usingprocess-compose:
- ✅ Automatic migrations and seeding
- ✅ Prisma Studio on port 5555
- ✅ Matches production PostGIS version (3.3.5)
- ✅ No Docker required
- ✅ Fast startup and hot-reload
.data/postgres/
Remote database
Connects toDATABASE_URL from .env:
--migrate: Run migrations before starting app--no-studio: Disable Prisma Studio
Local database via Docker
Starts dockerized PostgreSQL + PostGIS:Use this if you prefer Docker or need to match exact Docker Compose behavior. Requires Docker Engine installed.
External database (explicit URLs)
Connect to any database without.env:
Process Compose TUI
Thenix run .#dev command launches a terminal UI that manages multiple processes:
TUI controls
- Tab: Switch between processes
- Arrows: Scroll logs
- q: Quit (stops all processes)
- r: Restart selected process
Log files
Copy/paste-friendly logs are saved to:Advanced options
Fast mode (skip PostGIS version lock)
Use pre-built PostGIS from Nix binary cache (faster first build, but may not match production):LAN access for mobile testing
By default, the dev server binds to0.0.0.0 for mobile preview:
iptables (requires sudo once) and closes it on exit.
Preview database (PR testing)
Connect to a preview deployment’s database locally:- Detects isolated vs shared staging database
- Opens SSH tunnel if needed
- Skips local PostgreSQL
Preview tasks (task server testing)
Connect to a remote task server preview and expose your local app via ngrok:- Validates task server connection and API key
- Starts ngrok tunnel for callbacks
- Updates
NEXTAUTH_URLandTASK_API_URL
First-time ngrok users: Run
ngrok config add-authtoken <TOKEN> before using --preview-tasks. Get your token from ngrok dashboard.Port configuration
Customize ports via environment variables:Database operations
Prisma CLI
The dev shell includes Prisma CLI:Prisma Studio (standalone)
Run Prisma Studio outside the TUI:PostgreSQL CLI (psql)
The dev shell includespsql with automatic configuration:
PSQL_URL is automatically set by the dev shell. It’s the same as DATABASE_URL but with query parameters stripped (psql doesn’t need them).Reset local database
Delete local database and Next.js cache:.data/postgres/(database files).next/(Next.js build cache)
nix run .#dev to create a fresh database with seed data.
Production builds
Build a production-ready package:result/:
- Standalone Next.js output (minimal dependencies)
- Bundled Prisma schema and engines
- Optimized client bundles
- Seed script (for deployment seeding)
Version management
Lock file (flake.lock)
Nix flakes use flake.lock as the single source of truth for versions:
- nixpkgs commit (determines Node.js, PostgreSQL, etc. versions)
- Prisma engines version
- PostGIS version (via override)
flake.lock gets identical toolchains.
Updating dependencies
Update nixpkgs to get newer packages:Prisma version matching
The Prisma engines from nixpkgs must match the Prisma JavaScript packages inpackage.json.
When upgrading Prisma:
- Update
prismaand@prisma/clientinpackage.json - Update
flake.lockto a nixpkgs version with matching engines - Test migrations and queries
Troubleshooting
Port conflicts
The runner auto-selects ports. If you pin a port manually:Database initialization failed
If.data/postgres/ exists but is corrupted:
Prisma engine version mismatch
Verify engine versions:flake.lock to match package.json versions.
Build cache issues
Clear Nix build cache:Next steps
Environment setup
Configure environment variables
Database setup
Migrations and seeding