devenv - Declarative Nix Developer Environments Cheatsheet
devenv (by Cachix) builds fast, declarative, reproducible, and composable developer environments using Nix directly. Unlike tools that hide Nix behind JSON, devenv embraces the Nix language for its config, which gives you more power and flexibility: languages, packages, services (databases, caches), long-running processes, scripts, environment variables, and pre-commit/git hooks — all defined in one devenv.nix. It is the choice when you want full Nix capability with a batteries-included, developer-friendly layer.
Installation
| Method | Command |
|---|
| Requirement | Nix with flakes enabled |
| Install | nix profile install nixpkgs#devenv (or via Cachix instructions) |
| Cachix | recommended for fast binary caching |
| Verify | devenv version |
Getting Started
| Command | Description |
|---|
devenv init | Scaffold devenv.nix + devenv.yaml |
devenv shell | Enter the environment |
devenv up | Start defined processes/services |
devenv test | Run configured tests/checks |
devenv update | Update inputs (pin newer versions) |
devenv gc | Garbage-collect old environments |
The Config (devenv.nix)
{ pkgs, ... }:
{
# Packages available in the shell
packages = [ pkgs.git pkgs.jq ];
# Languages (managed toolchains)
languages.javascript.enable = true;
languages.python = {
enable = true;
version = "3.12";
};
# Services
services.postgres.enable = true;
services.redis.enable = true;
# Env vars
env.APP_ENV = "development";
# Scripts
scripts.hello.exec = "echo hello from devenv";
# Long-running processes
processes.web.exec = "npm run dev";
# Git hooks (pre-commit)
pre-commit.hooks = {
prettier.enable = true;
ruff.enable = true;
};
}
Key Building Blocks
| Block | Purpose |
|---|
packages | Arbitrary Nix packages in the shell |
languages.* | First-class language support (node, python, go, rust, …) |
services.* | Databases/caches (postgres, redis, mysql, mongodb, …) |
processes.* | Long-running commands managed by devenv up |
scripts.* | Named commands runnable in the shell |
env.* | Environment variables |
pre-commit.hooks.* | Git pre-commit integrations |
Services & Processes
| Command | Description |
|---|
devenv up | Start all processes and services |
devenv up -d | Start in the background |
devenv processes down | Stop processes |
services.postgres.enable = true; | Add a managed Postgres |
services.postgres.initialDatabases | Seed databases on start |
Git Hooks (pre-commit)
devenv integrates pre-commit hooks declaratively — enable a hook and it runs on commit.
| Hook example | Runs |
|---|
prettier.enable | Format JS/TS/etc. |
ruff.enable | Lint Python |
nixpkgs-fmt.enable | Format Nix |
shellcheck.enable | Lint shell scripts |
CI & Containers
| Use | How |
|---|
| CI | devenv test / devenv shell -- <cmd> for identical envs |
| Containers | devenv container build produces OCI images |
| direnv | .envrc with use devenv auto-enters on cd |
| Flakes | Composable with the wider Nix flake ecosystem |
Common Workflows
# Reproducible full-stack env: language + database + process
devenv init
# edit devenv.nix: enable python, services.postgres, processes.web
devenv shell # tools available
devenv up # postgres + web process running
# Build a container from the same definition
devenv container build web
devenv vs Devbox vs raw Nix
| Aspect | devenv | Devbox | Nix (raw) |
|---|
| Config | Nix language | JSON | Nix language |
| Power | High (full Nix) | Medium | Highest |
| Services/processes | Built-in, rich | Basic services | DIY |
| Learning curve | Moderate (Nix) | Gentle | Steep |
| Best for | Powerful declarative envs | Easy reproducible envs | Total control |
If Nix syntax is a barrier, Devbox offers a JSON-based alternative over the same foundation; see Nix for the base.
Resources