diff --git a/internal/devbox/devbox.go b/internal/devbox/devbox.go index 4c3f82421ce..45edd6f8e2f 100644 --- a/internal/devbox/devbox.go +++ b/internal/devbox/devbox.go @@ -820,6 +820,18 @@ func (d *Devbox) computeEnv( slog.Debug("computed environment PATH", "path", env["PATH"]) + // Expose the Devbox profile's share directory through XDG_DATA_DIRS so that + // data files installed by packages are discoverable inside the Devbox + // environment. Most notably this includes shell completions (which Nix + // packages install under share/bash-completion/completions), but also man + // pages, icons, and other XDG data. Tools such as bash-completion look these + // up via XDG_DATA_DIRS, so without the profile's share directory the + // completions shipped by packages like kubectl are never loaded. This is + // done even in --pure mode so completions keep working there too. + // See https://github.com/jetify-com/devbox/issues/2776 + profileShareDir := filepath.Join(d.projectDir, nix.ProfilePath, "share") + env["XDG_DATA_DIRS"] = envpath.JoinPathLists(profileShareDir, env["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")) diff --git a/testscripts/run/xdg_data_dirs.test.txt b/testscripts/run/xdg_data_dirs.test.txt new file mode 100644 index 00000000000..765ad1648bc --- /dev/null +++ b/testscripts/run/xdg_data_dirs.test.txt @@ -0,0 +1,18 @@ +# The Devbox profile's share directory must be exposed through XDG_DATA_DIRS so +# that data files installed by packages are discoverable inside the Devbox +# environment. Most importantly this lets tools like bash-completion find the +# shell completions that packages install under share/bash-completion/completions. +# https://github.com/jetify-com/devbox/issues/2776 + +exec devbox run echo '$XDG_DATA_DIRS' +stdout '\.devbox/nix/profile/default/share' + +# The profile's share directory must also be exposed in --pure mode, where the +# host's XDG_DATA_DIRS is not inherited, so completions keep working there too. +exec devbox run --pure echo '$XDG_DATA_DIRS' +stdout '\.devbox/nix/profile/default/share' + +-- devbox.json -- +{ + "packages": [] +}