Skip to content

Commit 42baf31

Browse files
authored
[minor improvement] computeNixEnv: use JoinPathLists for idempotency of LIBRARY_PATHs (#1231)
## Summary While investigating ensuring computeNixEnv idempotency, I realized that JoinPathLists goes a long way towards ensuring idempotency by dropping duplicates. This is especially useful if computeNixEnv is always appending or prepending to a path-list. ## How was it tested? compiles tests should pass
1 parent 22cfdc3 commit 42baf31

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

internal/impl/devbox.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -868,10 +868,7 @@ func (d *Devbox) computeNixEnv(ctx context.Context, usePrintDevEnvCache bool) (m
868868

869869
if !d.pure {
870870
// preserve the original XDG_DATA_DIRS by prepending to it
871-
env["XDG_DATA_DIRS"] = JoinPathLists(
872-
env["XDG_DATA_DIRS"],
873-
os.Getenv("XDG_DATA_DIRS"),
874-
)
871+
env["XDG_DATA_DIRS"] = JoinPathLists(env["XDG_DATA_DIRS"], os.Getenv("XDG_DATA_DIRS"))
875872
}
876873

877874
return env, d.addHashToEnv(env)
@@ -1042,8 +1039,9 @@ var ignoreDevEnvVar = map[string]bool{
10421039
// setCommonHelperEnvVars sets environment variables that are required by some
10431040
// common setups (e.g. gradio, rust)
10441041
func (d *Devbox) setCommonHelperEnvVars(env map[string]string) {
1045-
env["LD_LIBRARY_PATH"] = filepath.Join(d.projectDir, nix.ProfilePath, "lib") + ":" + env["LD_LIBRARY_PATH"]
1046-
env["LIBRARY_PATH"] = filepath.Join(d.projectDir, nix.ProfilePath, "lib") + ":" + env["LIBRARY_PATH"]
1042+
profileLibDir := filepath.Join(d.projectDir, nix.ProfilePath, "lib")
1043+
env["LD_LIBRARY_PATH"] = JoinPathLists(profileLibDir, env["LD_LIBRARY_PATH"])
1044+
env["LIBRARY_PATH"] = JoinPathLists(profileLibDir, env["LIBRARY_PATH"])
10471045
}
10481046

10491047
// NixBins returns the paths to all the nix binaries that are installed by

0 commit comments

Comments
 (0)