Skip to main content
InfraGap.com Logo
Home
Getting Started
Core Concept What is a CDE? How It Works Benefits CDE Assessment Getting Started Guide CDEs for Startups
AI & Automation
AI Coding Assistants Agentic AI AI-Native IDEs Agentic Engineering AI Agent Orchestration AI Governance AI-Assisted Architecture Shift-Left AI LLMOps Autonomous Development AI/ML Workloads GPU Computing
Implementation
Architecture Patterns DevContainers Advanced DevContainers Language Quickstarts IDE Integration CI/CD Integration Platform Engineering Developer Portals Container Registry Multi-CDE Strategies Remote Dev Protocols Nix Environments
Operations
Performance Optimization High Availability & DR Disaster Recovery Monitoring Capacity Planning Multi-Cluster Development Troubleshooting Runbooks Ephemeral Environments
Security
Security Deep Dive Zero Trust Architecture Secrets Management Vulnerability Management Network Security IAM Guide Supply Chain Security Air-Gapped Environments AI Agent Security MicroVM Isolation Compliance Guide Governance
Planning
Pilot Program Design Stakeholder Communication Risk Management Migration Guide Cost Analysis FinOps GreenOps Vendor Evaluation Training Resources Developer Onboarding Team Structure DevEx Metrics Industry Guides
Resources
Tools Comparison CDE vs Alternatives Case Studies Lessons Learned Glossary FAQ

Nix-Based Development Environments

Declarative, reproducible, and hermetic development environments using Nix, Devbox, and Devenv - the functional approach to solving dependency management in Cloud Development Environments

What is Nix and Why Does It Matter?

Nix is a purely functional package manager and build system that treats packages like values in a functional programming language. Every package is built in isolation, identified by a cryptographic hash of all its inputs, and stored in a read-only directory called the Nix store (typically /nix/store). Because packages never overwrite each other and builds are deterministic, Nix guarantees that if an environment works on one machine, it will work identically on any other machine with Nix installed.

For Cloud Development Environments, this property is transformative. Instead of relying on Dockerfiles that can produce different results depending on when they are built (because apt-get install fetches the latest version), Nix pins every dependency to an exact version, including transitive dependencies, system libraries, and even the compiler used to build them. The result is truly reproducible environments that do not drift over time.

Hermetic Builds

Every build is sandboxed with no network access and no access to undeclared dependencies. The output depends only on declared inputs.

Multiple Versions

Run Python 3.11 and Python 3.12 side by side without conflicts. Nix stores each version at a unique path in the Nix store.

Atomic Rollbacks

Every environment change creates a new generation. Roll back instantly to any previous state without rebuilding anything.

Nixpkgs: The Largest Package Repository

Nixpkgs is the largest package repository in the world with over 100,000 packages across Linux and macOS. It includes programming languages, databases, system tools, editors, and complete development toolchains. Because every package version is content-addressed, teams can pin to any revision of Nixpkgs and get byte-identical results regardless of when or where they build.

Core Nix Concepts for Developers

nix-shell / nix develop

Drop into a shell with specific tools available. When you exit, your global system is unchanged. Perfect for per-project development environments without polluting your system.

Nix Expressions

Nix uses a lazy, purely functional language to describe packages and environments. Expressions evaluate to derivations, which are build instructions that Nix executes deterministically.

Content Addressing

Every package path includes a hash of all its build inputs. Change any dependency and you get a completely new path. Two machines with the same hash are guaranteed identical outputs.

Binary Caches

Because outputs are content-addressed, Nix can substitute pre-built binaries from a cache server instead of building from source. This dramatically speeds up environment setup in CDEs.

Nix vs Docker and DevContainers

Nix and Docker solve overlapping but different problems. Docker provides process isolation and a packaging format for deployment. Nix provides dependency management and reproducible builds. Understanding where each excels helps teams make the right choice - or combine both for maximum benefit.

DimensionNixDocker / DevContainers
ReproducibilityBit-for-bit reproducible. Same inputs always produce same outputs.Layer-level caching. Rebuilding a Dockerfile at different times can yield different results.
Isolation ModelBuild-time sandboxing. No runtime isolation unless combined with containers.Full process and filesystem isolation using Linux namespaces and cgroups.
Multi-version SupportNative. Multiple versions coexist in the Nix store with zero conflicts.Requires separate containers or manual path management for multiple versions.
Startup SpeedInstant shell activation. No container boot time. Cached packages load in milliseconds.Container startup adds seconds to minutes depending on image size and pull time.
Ecosystem100,000+ packages in Nixpkgs. Strong Linux and macOS support.Docker Hub has millions of images. DevContainer Features add composable tooling.
Learning CurveSteep. The Nix language and concepts require significant investment to learn well.Moderate. Dockerfiles use familiar shell commands. devcontainer.json is straightforward JSON.
IDE IntegrationGrowing. direnv integration works with most editors. Devbox adds VS Code support.Excellent. First-class support in VS Code, JetBrains, GitHub Codespaces, and most CDEs.

Nix and Docker: Better Together

Many teams use Nix inside Docker containers rather than choosing one or the other. Nix handles dependency management with perfect reproducibility while Docker provides the runtime isolation and infrastructure compatibility that CDE platforms expect. You can use nix2container or dockerTools.buildImage to create minimal Docker images from Nix expressions, getting the best of both worlds.

For DevContainers, Nix can replace the Dockerfile entirely. Define your tools with Nix, generate a container image, and reference it from devcontainer.json. This gives you DevContainer IDE integration with Nix-level reproducibility.

Nix Flakes for Reproducible Environments

Flakes are the modern way to define Nix projects. Introduced as an experimental feature and now widely adopted, flakes bring standardized project structure, lockfiles, and hermetic evaluation to the Nix ecosystem.

What Flakes Solve

  • Lock files - flake.lock pins every input to an exact Git revision, ensuring all team members use identical dependencies
  • Standard structure - every flake has inputs, outputs, and a well-defined schema that tools can parse and understand
  • Pure evaluation - flakes cannot access the local system during evaluation, preventing accidental host dependencies
  • Composability - flakes can reference other flakes as inputs, enabling modular environment definitions across repositories

Anatomy of a Flake

  • flake.nix - the main entry point declaring inputs (nixpkgs, other flakes) and outputs (devShells, packages, NixOS configurations)
  • flake.lock - auto-generated lockfile that pins every input to an exact revision and hash, similar to package-lock.json or Cargo.lock
  • devShells - the output attribute that defines development environments, activated with nix develop
  • packages - buildable outputs that can be used as dependencies by other flakes or installed directly

Flakes in CDE Workspace Templates

When building CDE workspace templates, flakes provide a powerful alternative to Dockerfiles. A workspace template can include a flake.nix that defines all development tools. When a developer creates a workspace, the CDE installs Nix, evaluates the flake, and downloads pre-built binaries from a binary cache. The result is a perfectly reproducible environment that sets up in seconds rather than minutes.

Devbox by Jetify

Devbox wraps Nix in a developer-friendly CLI that eliminates the need to learn the Nix language. It uses a simple JSON configuration file to define development environments while leveraging the full power of Nixpkgs under the hood.

Zero Nix Knowledge Required

Devbox abstracts away the Nix language entirely. Developers add packages with devbox add nodejs@20 and start working. No flake.nix, no Nix expressions, no derivations to understand.

DevContainer Generation

Devbox can generate DevContainer configurations from your devbox.json, bridging the Nix and DevContainer ecosystems. One source of truth for your environment that works in both workflows.

Shell Scripts and Services

Define init hooks, shell scripts, and background services directly in devbox.json. Start databases, seed data, and configure tools automatically when developers enter the environment.

Devbox Cloud

Jetify offers Devbox Cloud, a managed CDE platform that runs Devbox environments in the cloud. Developers get instant, pre-configured workspaces accessible from a browser or VS Code. Devbox Cloud competes with GitHub Codespaces and Ona (formerly Gitpod) but differentiates by using Nix instead of Docker for environment definition, resulting in faster startup times and more predictable dependency management.

Instant cloud workspaces from any GitHub repo
Nix-powered reproducibility without learning Nix
Pre-built binary caches for fast setup
Integrated terminal, editor, and port forwarding

When to Choose Devbox vs Raw Nix

Choose Devbox when your team wants Nix reproducibility without the learning curve, when you primarily need to combine packages from Nixpkgs, or when you want DevContainer compatibility. Choose raw Nix flakes when you need custom package derivations, complex multi-language builds, NixOS module integration, or when your team already has Nix expertise.

Devenv.sh: Developer Environments Made Easy

Devenv is a Nix-based tool for defining development environments with a focus on developer experience. Unlike Devbox which hides Nix completely, Devenv uses a simplified Nix module system that gives teams more power while remaining approachable.

Key Features

Process Management

Define and manage background services like PostgreSQL, Redis, Elasticsearch, and custom daemons. Devenv starts and stops them automatically when you enter or leave the environment.

Language Support Modules

First-class modules for Python, Node.js, Go, Rust, PHP, Ruby, Java, and more. Each module configures the runtime, package manager, and common development tools with sensible defaults.

Built-in Testing

Write tests for your development environment that verify tools are installed, services are running, and configurations are correct. Run them in CI to prevent environment drift.

Container Generation

Generate OCI container images directly from your devenv configuration. Build containers that match your development environment exactly, eliminating dev/prod parity issues.

Devenv vs Devbox

DE

Devenv

Uses Nix module system (simplified Nix). More expressive. Better for teams comfortable with some Nix syntax. Stronger process management and testing story.

DB

Devbox

Uses JSON configuration. Zero Nix knowledge needed. DevContainer generation built in. Better for teams new to Nix. Managed cloud offering available.

NF

Raw Nix Flakes

Maximum flexibility and power. Full access to Nix language. Required for custom derivations and NixOS integration. Steepest learning curve.

direnv Integration

Both Devenv and Devbox integrate with direnv, which automatically activates the correct environment when you cd into a project directory. No manual shell activation needed. This makes Nix environments feel as seamless as global tool installations while keeping everything isolated.

NixOS as a CDE Base Image

NixOS is a Linux distribution built entirely on Nix. Every aspect of the system - kernel configuration, system services, user accounts, networking - is defined declaratively in Nix expressions. For CDE platforms, NixOS offers unprecedented control over the workspace operating system.

Declarative System Config

The entire OS is defined in a single configuration.nix file. System services, networking, users, kernel modules - everything is version-controlled and reproducible across workspace instances.

System Generations

Every configuration change creates a new system generation. If a workspace update breaks something, roll back to the previous generation instantly without rebuilding the entire image.

Module System

NixOS modules provide high-level abstractions for common services. Enable PostgreSQL with two lines of configuration. The module handles installation, configuration, user creation, and service management.

Minimal Images

NixOS images include only the packages you declare. No leftover packages from base images, no unnecessary system tools. This reduces image size and attack surface for CDE workspaces.

Security Patching

Nix's content-addressing means security patches propagate automatically to all dependent packages. Rebuild once, and every workspace that uses the updated Nixpkgs revision gets the fix.

CDE Platform Support

Ona uses NixOS as the base for its workspace images. Coder supports NixOS through Terraform templates. NixOS containers can run in any Kubernetes-based CDE with proper configuration.

Ona and NixOS

Ona has been one of the strongest advocates for Nix in the CDE space. Their workspace images are built on NixOS, and their environment definitions use Nix under the hood. This allows Ona to provide faster workspace startup times compared to Docker-based competitors, because Nix's content-addressed store enables more granular caching than Docker's layer-based approach. Learn more about CDE platforms on our tools comparison page.

Performance Benefits and Adoption Challenges

Nix-based environments offer measurable performance advantages over traditional Docker-based approaches, but adoption requires overcoming real hurdles. Understanding both sides helps teams plan a realistic adoption strategy.

Performance Benefits

Granular Caching

Docker caches at the layer level - change one package and the entire layer rebuilds. Nix caches individual packages. Add a single tool and only that package downloads. This reduces incremental environment updates from minutes to seconds.

Binary Substitution

The official Nix binary cache (cache.nixos.org) and private caches serve pre-built packages. Teams can run their own cache servers, reducing CDE workspace startup time to the time it takes to download compressed binaries.

Shared Store Deduplication

Multiple workspaces on the same host share a single Nix store. If ten developers use the same Node.js version, it is stored once. This reduces disk usage and speeds up workspace creation on shared infrastructure.

No Image Pull Required

Unlike Docker, which must pull a complete image before starting, Nix downloads only the specific packages needed. A 50 MB tool addition does not require pulling a 2 GB base image again.

Adoption Challenges

Learning Curve

The Nix language is unlike anything most developers have used. Lazy evaluation, functional patterns, and the derivation model take weeks to internalize. Tools like Devbox and Devenv reduce this barrier but limit flexibility.

Documentation Gaps

While improving rapidly, Nix documentation has historically been fragmented across wikis, manuals, and blog posts. The experimental status of flakes has added confusion about which approach to follow.

macOS and Linux Differences

While Nix works on macOS, the experience differs from Linux. Some packages are Linux-only. System integration on macOS requires nix-darwin, a separate project. CDE workspaces (typically Linux) avoid this issue entirely.

Disk Usage

The Nix store can grow large because every version of every package is retained until garbage collected. Teams need to configure regular garbage collection and manage store size in CDE environments.

Recommended Adoption Path

1

Start with Devbox

Add devbox.json to one project. No Nix knowledge needed. Team sees immediate value.

2

Add to CDE Templates

Integrate Devbox into your CDE workspace templates. Developers get Nix benefits automatically.

3

Explore Devenv

For projects needing services or testing, migrate to Devenv. Introduces Nix syntax gradually.

4

Full Nix Flakes

Teams with Nix expertise can write custom flakes for maximum control over environments and builds.

Nix in CDE Workspace Templates

CDE platforms like Coder, Ona, and others use workspace templates to define what developers get when they create an environment. Nix can be integrated into these templates at different levels depending on the platform and team needs.

Nix Inside Docker

Install Nix in a Docker container and use flakes or Devbox for package management. Works with any CDE that supports Docker images. The container provides isolation while Nix provides reproducibility.

Best for: Teams already using DevContainers who want better dependency management

Nix-Built Images

Use Nix to build the Docker image itself. Tools like dockerTools.buildImage create minimal OCI images containing only declared dependencies. No Dockerfile needed.

Best for: Platform teams who want reproducible base images with minimal attack surface

Native NixOS Workspaces

Run NixOS as the workspace operating system. The entire system is declaratively configured. Used by Ona natively and available in Coder through custom Terraform templates.

Best for: Teams wanting maximum reproducibility and willing to invest in Nix expertise

Platform-Specific Integration

Coder

Coder's Terraform-based templates can provision NixOS VMs or containers with Nix pre-installed. The template can include a flake.nix that defines the development environment, and Coder's startup scripts can run nix develop or devbox shell automatically.

Learn more about Coder

Ona

Ona's workspace images are NixOS-based by default. Developers define their environment in a configuration file, and Ona uses Nix to build and cache the workspace. This deep NixOS integration is a key differentiator for Ona in the CDE market.

Learn more about Ona

GitHub Codespaces

Codespaces supports Nix through DevContainer Features that install Nix in the container. Teams can then use devbox.json or flake.nix for package management while keeping the DevContainer workflow for IDE integration.

Learn more about Codespaces

DevPod

DevPod, as a client-only open-source tool, works with any container image. Teams can build Nix-based DevContainer images and use them with DevPod on any cloud provider or local Docker installation.

Learn more about DevPod