Skip to content

Commit 5ee847b

Browse files
authored
[lib-path] Add a few common env variables (#792)
## Summary Adds `LD_LIBRARY_PATH` and `LIBRARY_PATH` env vars to shellenv (pointing to profile lib directory). This is a bit of a blunt approach, so not sure if it's best. This would fix #760 and also lets us simplify the [rust plugin](https://github.com/jetpack-io/devbox/blob/main/plugins/rustup.json#L7-L7) Two questions/considerations: * I considered adding to the flake.nix file instead, but wasn't example sure how to point to the right directory (without hard coding). It might look something like `LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath...` * I also read the following: > Not setting LD_LIBRARY_PATH is usually the right choice because usually the native binaries find their libraries using RUNPATH which is specific to the binary. Setting LD_LIBRARY_PATH has an obvious problem of potentially messing up other programs. @gcurtis any idea how accurate this is? ## How was it tested? `devbox shell` and confirmed env vars are set. Also tested with this example: #710 (comment)
1 parent 0ea21dd commit 5ee847b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

internal/impl/devbox.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ func (d *Devbox) computeNixEnv(ctx context.Context) (map[string]string, error) {
546546
env["PATH"] = JoinPathLists(nixEnvPath, originalPath)
547547
debug.Log("computed environment PATH is: %s", env["PATH"])
548548

549+
d.setCommonHelperEnvVars(env)
550+
549551
return env, nil
550552
}
551553

@@ -709,3 +711,10 @@ var ignoreDevEnvVar = map[string]bool{
709711
"TZ": true,
710712
"UID": true,
711713
}
714+
715+
// setCommonHelperEnvVars sets environment variables that are required by some
716+
// common setups (e.g. gradio, rust)
717+
func (d *Devbox) setCommonHelperEnvVars(env map[string]string) {
718+
env["LD_LIBRARY_PATH"] = filepath.Join(d.projectDir, nix.ProfilePath, "lib") + ":" + env["LD_LIBRARY_PATH"]
719+
env["LIBRARY_PATH"] = filepath.Join(d.projectDir, nix.ProfilePath, "lib") + ":" + env["LIBRARY_PATH"]
720+
}

0 commit comments

Comments
 (0)