Skip to content

fix(env): expose Devbox profile share dir via XDG_DATA_DIRS so package completions work#2926

Open
mikeland73 wants to merge 2 commits into
mainfrom
claude/focused-goldberg-3z42ky
Open

fix(env): expose Devbox profile share dir via XDG_DATA_DIRS so package completions work#2926
mikeland73 wants to merge 2 commits into
mainfrom
claude/focused-goldberg-3z42ky

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Summary

Fixes #2776.

Package-provided shell completions were never active inside a Devbox shell. For
example, on a fresh Ubuntu + bash setup, kubectl <TAB> does nothing even though
the kubectl Nix package ships a completion script.

Root cause

Nix packages install their bash completions under
share/bash-completion/completions/<cmd>, and bash-completion's dynamic loader
discovers them by scanning the bash-completion/completions subdirectory of
every entry in XDG_DATA_DIRS at completion time.

When computing the environment (internal/devbox/devbox.go), Devbox only
preserved the host's original XDG_DATA_DIRS:

if !envOpts.Pure {
    // preserve the original XDG_DATA_DIRS by prepending to it
    env["XDG_DATA_DIRS"] = envpath.JoinPathLists(env["XDG_DATA_DIRS"], os.Getenv("XDG_DATA_DIRS"))
}

It never added the Devbox profile's own share directory
(.devbox/nix/profile/default/share), which is where all of a project's
installed packages aggregate their data files. As a result the completions — and
other XDG data such as man pages and icons — shipped by those packages were
invisible to the shell.

Fix

Prepend the profile's share directory to XDG_DATA_DIRS while computing the
environment:

profileShareDir := filepath.Join(d.projectDir, nix.ProfilePath, "share")
env["XDG_DATA_DIRS"] = envpath.JoinPathLists(profileShareDir, env["XDG_DATA_DIRS"])
  • Done for both regular and --pure environments, so completions keep working
    in pure shells too.
  • envpath.JoinPathLists cleans, dedupes, and drops empty/relative segments, so
    this is a no-op if the entry is already present and it never introduces a
    duplicate or an unsafe relative path.
  • This mirrors how nix-env / home-manager expose the same data via
    XDG_DATA_DIRS.

How was it tested?

  • go build ./... and go vet ./internal/devbox/ — clean.
  • Added testscripts/run/xdg_data_dirs.test.txt, which asserts that
    devbox run echo '$XDG_DATA_DIRS' includes
    .devbox/nix/profile/default/share.

Manual verification of the underlying mechanism: with the profile's share
directory on XDG_DATA_DIRS, bash-completion's __load_completion finds
share/bash-completion/completions/kubectl in the Devbox profile and activates
kubectl <TAB> completion; the change is additive and does not alter any other
environment variable.

/cc @gberche-orange (issue reporter) — thanks for the clear report and the
upstream package links.

Community Contribution License

All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.

By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EuAos6xjPuVdUWNEVvCYh1


Generated by Claude Code

…etions

Package-provided shell completions were never active inside a Devbox shell
(e.g. `kubectl <TAB>` did nothing on a fresh Ubuntu + bash setup). Nix
packages install their bash completions under
`share/bash-completion/completions/`, and bash-completion's dynamic loader
discovers them by scanning the `bash-completion/completions` subdirectory of
every entry in `XDG_DATA_DIRS`.

Devbox only preserved the host's original `XDG_DATA_DIRS` and never added the
Devbox profile's own `share` directory (`.devbox/nix/profile/default/share`),
so the completions (and other XDG data like man pages and icons) shipped by
installed packages were invisible.

Prepend the profile's `share` directory to `XDG_DATA_DIRS` when computing the
environment. This is done even in `--pure` mode so completions keep working
there too, and it mirrors how nix-env / home-manager expose the same data.

Fixes #2776

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EuAos6xjPuVdUWNEVvCYh1
Copilot AI review requested due to automatic review settings July 18, 2026 14:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes missing package-provided shell completions (and other XDG data like man pages/icons) inside Devbox environments by ensuring the project profile’s share/ directory is discoverable via XDG_DATA_DIRS.

Changes:

  • Prepend .devbox/nix/profile/default/share to XDG_DATA_DIRS when computing the Devbox environment (including --pure).
  • Add a run testscript that asserts XDG_DATA_DIRS includes the profile share/ directory.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/devbox/devbox.go Prepends the Devbox profile share dir to XDG_DATA_DIRS during environment computation.
testscripts/run/xdg_data_dirs.test.txt Adds coverage to ensure XDG_DATA_DIRS exposes the profile share directory.

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

Comment on lines +7 to +9
exec devbox run echo '$XDG_DATA_DIRS'
stdout '\.devbox/nix/profile/default/share'

…e too

The fix sets XDG_DATA_DIRS for both regular and --pure environments; add a
--pure assertion so the pure-shell path is guarded against regressions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EuAos6xjPuVdUWNEVvCYh1
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.

package completions not active in devbox shells (e.g. kubectl )

3 participants