Skip to content

Support setting the --config flag via the DEVBOX_CONFIG env var#2838

Open
mikeland73 wants to merge 4 commits into
mainfrom
claude/hopeful-curie-sqn8C
Open

Support setting the --config flag via the DEVBOX_CONFIG env var#2838
mikeland73 wants to merge 4 commits into
mainfrom
claude/hopeful-curie-sqn8C

Conversation

@mikeland73
Copy link
Copy Markdown
Collaborator

Summary

Fixes #245.

The --config flag lets users point devbox at a devbox.json that lives in a non-default location. Until now there was no way to set it from the environment, which is awkward in contexts where passing the flag to every invocation is repetitive — the motivating example in the issue is a Dockerfile:

ENV DEVBOX_CONFIG=.devcontainer
RUN devbox install   # picks up DEVBOX_CONFIG automatically

This PR defaults the --config flag to the DEVBOX_CONFIG environment variable when the flag isn't passed explicitly. An explicitly passed --config/-c flag still takes precedence over the env var.

Changes

  • Add a DevboxConfig (DEVBOX_CONFIG) constant in internal/envir.
  • Use os.Getenv(DEVBOX_CONFIG) as the default value for the --config flag in both register and registerPersistent, and mention the env var in the flag usage text.
  • Add TestConfigFlagDefaultsToEnv covering: unset env, env-as-default, and explicit-flag-overrides-env.

Notes / scope

Issue #245 also mentions a --cache flag. devbox no longer exposes a --cache flag for the .devbox directory location (DEVBOX_CACHE today is used for a different purpose — the nixpkgs cache base URL), so this PR scopes the change to the --config flag, which is the part that's actionable against the current CLI. Happy to follow up if a configurable .devbox path is still desired (tracked separately in #244).

Testing

go test ./internal/boxcli/ -run TestConfigFlagDefaultsToEnv
go vet ./internal/boxcli/ ./internal/envir/

https://claude.ai/code/session_01UQSFvFRfQ4Ku4F4LXbKjFn


Generated by Claude Code

The --config flag lets users point devbox at a devbox.json in a
non-default location. There was no way to set it via the environment,
which is awkward in contexts like a Dockerfile where passing the flag
to every command is repetitive.

Default the --config flag to the DEVBOX_CONFIG environment variable when
the flag isn't passed. An explicitly passed flag still takes precedence.

Fixes #245
Copilot AI review requested due to automatic review settings May 31, 2026 17:52
@mikeland73 mikeland73 requested a review from mohsenari May 31, 2026 17:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for setting the --config flag via a new DEVBOX_CONFIG environment variable, so users can avoid passing --config repeatedly (e.g., in Dockerfiles). Explicit --config/-c still takes precedence.

Changes:

  • Introduces envir.DevboxConfig (DEVBOX_CONFIG) constant.
  • Uses os.Getenv(envir.DevboxConfig) as the default for --config in both register and registerPersistent, with usage text mentioning the env var.
  • Adds TestConfigFlagDefaultsToEnv covering unset env, env-as-default, and explicit-flag-override cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/envir/env.go Adds DevboxConfig constant with documentation.
internal/boxcli/config.go Reads DEVBOX_CONFIG as default for --config; extracts shared usage string.
internal/boxcli/config_test.go New unit tests verifying env-var default and flag override behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mohsenari
Copy link
Copy Markdown
Collaborator

Idk why cli tests fail for this PR, worth a retry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

feature request: Set config and cache flags via env variables

4 participants