Skip to content

devenv - Declarative Nix Developer Environments Cheatsheet

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

MethodCommand
RequirementNix with flakes enabled
Installnix profile install nixpkgs#devenv (or via Cachix instructions)
Cachixrecommended for fast binary caching
Verifydevenv version

Getting Started

CommandDescription
devenv initScaffold devenv.nix + devenv.yaml
devenv shellEnter the environment
devenv upStart defined processes/services
devenv testRun configured tests/checks
devenv updateUpdate inputs (pin newer versions)
devenv gcGarbage-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

BlockPurpose
packagesArbitrary 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

CommandDescription
devenv upStart all processes and services
devenv up -dStart in the background
devenv processes downStop processes
services.postgres.enable = true;Add a managed Postgres
services.postgres.initialDatabasesSeed databases on start

Git Hooks (pre-commit)

devenv integrates pre-commit hooks declaratively — enable a hook and it runs on commit.

Hook exampleRuns
prettier.enableFormat JS/TS/etc.
ruff.enableLint Python
nixpkgs-fmt.enableFormat Nix
shellcheck.enableLint shell scripts

CI & Containers

UseHow
CIdevenv test / devenv shell -- <cmd> for identical envs
Containersdevenv container build produces OCI images
direnv.envrc with use devenv auto-enters on cd
FlakesComposable 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

AspectdevenvDevboxNix (raw)
ConfigNix languageJSONNix language
PowerHigh (full Nix)MediumHighest
Services/processesBuilt-in, richBasic servicesDIY
Learning curveModerate (Nix)GentleSteep
Best forPowerful declarative envsEasy reproducible envsTotal control

If Nix syntax is a barrier, Devbox offers a JSON-based alternative over the same foundation; see Nix for the base.

Resources