Devbox 0.4.3: Powered by Flakes

Devbox 0.4.3: Powered by Flakes

With Devbox 0.4.3, we've fully shifted our environment generation from using standard Nix expressions to using Nix Flakes, a new experimental feature in the Nix ecosystem.

While this is mostly a behind the scenes change to Devbox, we're excited about the potential this unlocks, and we wanted to share why we made this shift. In this post we'll describe why Flakes are so important, and the benefits our users should see from this change.

To install the latest version of Devbox, visit our Getting Started guide. If you already have Devbox installed, version 0.4.3 will be pushed to you automatically. You can view the full release notes on Github.

What are Flakes?

{   description: "An example Flake Schema";    # Start by defining the sources and inputs we need   # to build our project. Nix will pin these using a   # lockfile (flake.lock)    inputs = {      # Github Repo, like nixpkgs     nixpkgs.url = "github:NixOS/nixpkgs/unstable";      # A tarball on a remote server     flake-utils.url = ""      # A path to a local flake     customFlake.url = "path:./path/to/flake.nix";   };    # Now we can define the outputs we want to generate   # from our inputs. This can include development shells,    # packages, NixOS configurations, and more    outputs = {self, pkgs, flake-utils, customFlake}: {      # Create an interactive development shell      devShells."aarch64-darwin".default = {       # Nix shell derivation goes here     };      # Build a package      packages."aarch64-darwin".default = {       #Nix package derivation goes here     };   }; }
An example Flake schema. This flake takes inputs from 3 different URLs, and uses them to generate a development shell and a package for macOS on aarch64. In practice, you can define a wide range of outputs and targets using Flakes.

Flakes are a new feature in the Nix language that lets us package software and create development shells in a declarative, fully reproducible way. They provide several advantages compared to the traditional way of defining Nix environments:

  • Flakes provide a simplified, standardized format for declaring the inputs to your development environment, whether a specific commit of the Nixpkg repo, another flake, or a tarball. This standardization makes composing multiple inputs and sources into a shell much more manageable.
  • Flakes also generate a lockfile of your inputs and packages, ensuring your shell is reproducible whenever you run it. In addition to pinning the versions of your packages, the lockfile makes it easier to update your inputs atomically to newer versions.
  • Because flakes are more hermetic and reproducible, we can cache the results of evaluating them. Caching these outputs means your shell and scripts can run much faster.

With all these features, you can see why flakes are quickly becoming the preferred way to build and develop in the Nix ecosystem. For Devbox, our move to flakes means we can build faster, more reproducible development environments for all of of our user's projects.

If you're curious and want to learn more about flakes, here are a few good resources to check out:

What This Means for Users

This initial release is mainly behind the scenes, and no user workflows will change — you can keep using Devbox exactly how you’ve been using Devbox to this point. However, users should see a significant improvement in startup times as a result of this shift.

Because Flakes provide better caching of our Nix evaluations, we can start Devbox shells faster than ever. In our testing, we've seen as much as a 70% improvement in warm startup time over Devbox 0.4.2 . Below is a typical comparison run on macOS, using the Ruby example in our examples repo:

# Devbox 0.4.2 (without Flakes)
$ time devbox run -- exit
> Ensuring packages are installed.
> devbox run -- exit  0.82s user 0.24s system 60% cpu 1.763 total

# Devbox 0.4.3 (with Flakes)
$ time devbox run -- exit
> Ensuring packages are installed.
> devbox run -- exit  0.21s user 0.09s system 60% cpu 0.486 total
Devbox 0.4.3 starting a shell in less than 500 milliseconds.

That's a nearly 4x improvement as a result of moving to Flakes!

In addition to these performance improvements, the reproducibility and easy version upgrades of Flakes will unlock a lot of new features for Devbox. Some features we are planning include:

  • The ability to add packages from multiple sources, including flakes or Git repos outside of nixpkgs
  • Atomic updates to the latest versions of your packages, without having to find and change the commit hash in your shell.
  • Fast package search from the Devbox CLI

Keep in Touch

We're excited for all the new features that flakes will unlock for Devbox! If you'd like to keep up with our progress, you can follow us on Twitter, or chat with our developers on our Discord Server. We also welcome issues and pull requests on our Github Repo.