Devbox

repository·main·Indexed 11 days ago

https://github.com/jetify-com/devbox

A command-line tool for creating isolated, predictable, and portable development environments. Devbox uses Nix to manage operating-system level packages and allows developers to define toolchains in a `devbox.json` file for sharing across teams and deployment contexts like Docker or Devcontainers.

Tokens
22.8K
Snippets
121
Records
167
Agent score
95%

What's inside Devbox

  1. Explore Devbox example environments

    main

    Devbox provides a variety of pre-configured example environments to demonstrate how to set up specific development stacks. You can explore the following categories of examples:

    • databases: Examples of popular databases such as MariaDB, Postgres, and Redis.
    • development: Shells tailored for developing in different programming languages.
    • flakes: Examples demonstrating how to use Nix Flakes with Devbox.
    • servers: Examples of server configurations, such as Apache and Nginx.
    • stacks: Full project setups and web stacks, including LAMP and Drupal.
  2. How Devbox works

    main

    Devbox is a command-line tool that creates isolated development environments by defining a list of required packages in a devbox.json file.

    Unlike traditional package managers that install tools globally, Devbox manages operating-system level packages (similar to brew or apt-get) using nix under the hood. This allows you to:

    • Isolate environments: Tools are only available within the Devbox shell.
    • Avoid version conflicts: Run different versions of the same binary for different projects.
    • Ensure portability: The devbox.json definition can be used to generate local shells, VSCode Devcontainers, Dockerfiles, or remote cloud environments.
  3. How the Ruby Plugin manages environment variables

    main

    When you install Ruby via Devbox, the built-in Ruby plugin automatically configures several environment variables. This ensures that Gems are installed locally within your project directory rather than globally, preventing pollution of your host system.

    The following variables are set (where {PROJECT_DIR} is your current project root):

    • RUBY_CONFDIR: {PROJECT_DIR}/.devbox/virtenv/ruby
    • GEMRC: {PROJECT_DIR}/.devbox/virtenv/ruby/.gemrc
    • GEM_HOME: {PROJECT_DIR}/.devbox/virtenv/ruby
    • PATH: {PROJECT_DIR}/.devbox/virtenv/ruby/bin:$PATH
  4. Configure NGINX via helper files and environment variables

    main

    When NGINX is added, Devbox creates several helper files in your project directory to manage configuration and web content:

    • devbox.d/nginx/nginx.conf: The main NGINX configuration file.
    • devbox.d/nginx/fastcgi.conf: FastCGI configuration.
    • devbox.d/web/index.html: Default web root content.

    Important: By default, NGINX is configured with ./devbox.d/web as the root directory. To change the web root, modify ./devbox.d/nginx/nginx.conf.

    You can customize NGINX behavior by setting environment variables in your shell's init_hook.

  5. Configure themes for Drupal multisite environments

    main

    In a multisite configuration, you can control theme availability and precedence using the following directory patterns:

    1. Global Availability: Themes placed in the main web/themes directory are available to all sites in the multisite installation.
    2. Theme Precedence: If a theme exists in both sites/all/themes and the main web/themes directory, the version in sites/all/themes takes precedence.
    3. Site-Specific Restriction: To restrict themes to a specific site instance only, use the sites/your_site_name/themes directory pattern.
  6. How Devbox plugins work

    main

    Devbox plugins are Go JSON Template files that simplify the setup of packages requiring additional configuration. They allow you to define environment variables, create configuration files, and run initialization hooks. Plugins are activated automatically when a package name matches the plugin's match regex, or when explicitly included in a project's devbox.json via the include section.

    Plugin Lifecycle:

    1. Plugin env: Plugin-defined environment variables are loaded.
    2. User env: User-defined environment variables are loaded.
    3. Plugin init_hook: Plugin bash commands run.
    4. User Init Hook: User bash commands run.
    5. Shell/Service Start: The interactive shell, scripts, or services are started.
    ---
    title: Devbox Shell Lifecycle
    ---
    flowchart TD
       A[Plugin env] --> B
       B[User env] --> C
       C[Plugin init_hook] --> D[User Init Hook]
       D -->  E{Start Shell}
       E --> F & G & H
       F[Interactive Shell]
       G[Run Scripts]
       H[Start Services]
  7. Configure Apache DocumentRoot and files

    main

    When Apache is installed via Devbox, the plugin automatically generates configuration and web files in your project directory.

    By default, the DocumentRoot is set to ./devbox.d/web.

    Generated Files:

    • {PROJECT_DIR}/devbox.d/apacheHttpd/httpd.conf: The Apache configuration file.
    • {PROJECT_DIR}/devbox.d/web/index.html: The default web entry point.

    Customization: To change the DocumentRoot, you must copy and modify the default ./devbox.d/apacheHttpd/httpd.conf file. It is recommended to copy httpd.conf to a new directory and update the HTTPD_CONFDIR environment variable if you perform significant modifications.