This Week #14: JSON Schemas, Devbox 0.8.3, and Non-default Outputs

This week from the Jetpack Team: JSON Schemas for devbox configs, Devbox 0.8.3 release, and how to install non-default outputs from Nix packages

JSON Schemas for Devbox Config and Plugins

While we strive to keep the schemas for devbox.json and devbox-plugin.json as simple as possible, it can still be easy to make mistakes when modifying the JSON files directly. To help simplify this, we’ve recently added new JSON Schemas to our main Devbox repo. JSON Schemas can be used to validate or even autocomplete your JSON configs while writing them.

These schemas can be sourced directly in your Devbox configs using the $schema keyword:

{
	"$schema": "https://raw.githubusercontent.com/jetpack-io/devbox/main/.schema/devbox.schema.json",
	"packages" : [
		"go@latest"
	],
  "shell": {
		"init_hook": [
			"echo 'Welcome to Devbox'"
		]
	}
}
Adding a schema to devbox.json
{
	"$schema": "https://raw.githubusercontent.com/jetpack-io/devbox/main/.schema/devbox-plugin.schema.json",
	"name": "My Plugin",
	"version": "0.0.1",
	"readme": "This is an example of a Devbox plugin"
}
Adding a schema to devbox-plugin.json

The Devbox Config and Plugin schemas are also available at Schemastore so you can use them with any IDE or other JSON schema implementation. We also automatically detect and apply the schemas in our Devbox Plugin for VSCode.

Devbox 0.8.3 Release

Our newest release of Devbox 0.8.3 has a number of improvements and enhancements based on user feedback. Some highlights from this release:

  • Fixed an incompatibility with Nix 2.19 — The latest release of Nix introduced a breaking change to how Flakes are updated, which also prevented Devbox from updating or adding new packages to existing projects. Devbox 0.8.3 uses the correct update command when Nix 2.19 is detected, while still maintaining compatibility with all versions after Nix 2.15.1.
  • Allow installing of non-default package outputs —Devbox 0.8.3 now provides a way to specify which outputs you want to include when installing a package. See the next topic for more details
  • More secure Dockerfiles — Dockerfiles generated with devbox generate dockerfile or devbox generate devcontainer now add a non-root default user and avoid using sudo when copying over your devbox configuration. This makes our containers more secure, and should prevent security scanners from triggering when analyzing your Dockerfiles.

You can view the full notes on our Github Releases page.

Installing Non-Default Nix Package Outputs

While most Nix derivations install all the binaries and libraries you need in their default output (out), some derivations split their build artifacts across multiple targets. For example, the prometheus package provides the prometheus server in the out target, while providing the docs and promtool CLI in separate outputs:

{ 
# ...
    buildGoModule rec {
      pname = "prometheus";
      inherit version;

      outputs = [ "out" "doc" "cli" ];
# ...
}

Package maintainers often separate their packages in this way to reduce the size of the default installation by removing non-essential files. Developers can install the extra outputs by requesting them from nix and installation time

When you install a package using devbox add, Devbox follows the Nix convention and only installs the binaries and files in the default out target. This works for most packages, but in some cases you may want to also install the additional outputs. As of Devbox 0.8.3, you can specify the exact outputs you want to install using flake references.

For example — here’s how you would install the promtool binary along with prometheus:

devbox add flake:nixpkgs#prometheus^out,cli

This will install the default and CLI outputs from the latest prometheus package. To install or pin a specific version, you can look up the correct reference using Nixhub. For example, to install version 2.47.2, you can run:

devbox add flake:nixpkgs/85306ef2470ba705c97ce72741d56e42d0264015#prometheus^out,cli

This initial release mostly lays the groundwork for supporting multiple or non-default outputs with Devbox. Future releases will improve the user experience further, including:

  • Exposing non-default outputs on Nixhub and devbox search
  • Supporting non-default outputs with Devbox’s packages syntax

Stay up to Date with Jetify

If you're reading this, we'd love to hear from you about how you've been using Devbox for your projects. You can follow us on Twitter, or chat with our developers live on our Discord Server. We also welcome issues and pull requests on our Github Repo.