Skip to content

devenv - Development and CI Environments

devenv can define a whole development/CI environment. “Fast, Declarative, Reproducible, and Composable Developer Environments”

Manage development and CI environments across machines and easily share them with others.

You create devenvs in .nix files to declare their attributes.

devenv uses Nix to make the environments declarative and reproducible.

  • programming language integration (example: Python, JavaScript, Rust)
  • platform integration
    • Examples: Android development, Codespaces Devcontainer, GitHub Actions continuous integration (CI) platform, WordPress development
  • tasks
    • Example: general tasks, tasks running on a condition like file changes
  • git hooks
    • Example: running formatters on commits
  • processes
  • services
    • Example: run databases, services with their configuration and ports open for use
      • Ports can be uses as variables in other parts of the devenv, like running a test when a port is available
      • Many services are available like HTTP servers, various databases, search, networking, monitoring or you can define your own
  • containers
    • Example: Build equivalent container to the shell environment, processes, services
  • multiple profiles
  • packages, using nix packages
  • ad-hoc environments
  • environment variables
  • profiles
    • Example: options depending on use case like stages of development, user of the environment, different machines
  • scripts
    • Example: Can use any scripting language
  • secrets management using secretspec
    • Example: Secret names defined and retrieved using secrets providers. Secret provide logic is separate from the devenv

It is similar to shell.nix for Nix and adds more features and integration.

Example devenv for Rust and additional services

Section titled “Example devenv for Rust and additional services”

Example devenv.nix at devenv.sh for Rust development, Postgres database, Redis cache, task runner, secrets management, and others packages required in the environment

devenv.sh/languages/rust/
{ pkgs, ... }: {
languages = {
rust = {
enable = true;
channel = "stable";
};
};
services = {
# devenv.sh/services/postgres/
postgres = {
enable = true;
initialDatabases = [{ name = "app"; }];
};
# devenv.sh/services/redis/
redis.enable = true;
};
# devenv.sh/tasks/
tasks."app:test".exec = "cargo test";
# devenv.sh/integrations/secretspec/
processes.api.exec =
"secretspec run -- cargo run";
packages = [
# devenv.sh/packages/
pkgs.docker
];
}