Skip to content

[bin-wrappers] Don't use wrappers on run #1361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions internal/boxcli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ func runScriptCmd(cmd *cobra.Command, args []string, flags runCmdFlags) error {
}
// Check the directory exists.
box, err := devbox.Open(&devopt.Opts{
Dir: path,
Writer: cmd.ErrOrStderr(),
Pure: flags.pure,
Env: env,
Dir: path,
Writer: cmd.ErrOrStderr(),
Pure: flags.pure,
Env: env,
OmitBinWrappersFromPath: true,
})
if err != nil {
return redact.Errorf("error reading devbox.json: %w", err)
Expand Down
20 changes: 9 additions & 11 deletions internal/impl/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Devbox struct {
pure bool
allowInsecureAdds bool
customProcessComposeFile string
OmitBinWrappersFromPath bool

// Possible TODO: hardcode this to stderr. Allowing the caller to specify the
// writer is error prone. Since it is almost always stderr, we should default
Expand Down Expand Up @@ -93,6 +94,7 @@ func Open(opts *devopt.Opts) (*Devbox, error) {
pure: opts.Pure,
customProcessComposeFile: opts.CustomProcessComposeFile,
allowInsecureAdds: opts.AllowInsecureAdds,
OmitBinWrappersFromPath: opts.OmitBinWrappersFromPath,
}

lock, err := lock.GetFile(box)
Expand Down Expand Up @@ -848,21 +850,17 @@ func (d *Devbox) computeNixEnv(ctx context.Context, usePrintDevEnvCache bool) (m
addEnvIfNotPreviouslySetByDevbox(env, pluginEnv)

env["PATH"] = JoinPathLists(
// Prepend the bin-wrappers directory to the PATH. This ensures that
// bin-wrappers execute before the unwrapped binaries.
filepath.Join(d.projectDir, plugin.WrapperBinPath),
// Adding profile bin path is a temporary hack. Some packages .e.g. curl
// don't export the correct bin in the package, instead they export
// as a propagated build input. This can be fixed in 2 ways:
// * have NixBins() recursively look for bins in propagated build inputs
// * Turn existing planners into flakes (i.e. php, haskell) and use the bins
// in the profile.
// Landau: I prefer option 2 because it doesn't require us to re-implement
// nix recursive bin lookup.
Comment on lines -848 to -858
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is in computeNixEnv which is called in both devbox run and devbox shell.
Is this change not going to affect devbox shell?

Copy link
Collaborator

@savil savil Aug 10, 2023

Choose a reason for hiding this comment

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

for callers other than devbox run, the d.OmitBinWrappersFromPath defaults to false, so this change is a no-op and hence safe for them

nix.ProfileBinPath(d.projectDir),
env["PATH"],
)

if !d.OmitBinWrappersFromPath {
env["PATH"] = JoinPathLists(
filepath.Join(d.projectDir, plugin.WrapperBinPath),
env["PATH"],
)
}

// Include env variables in devbox.json
configEnv := d.configEnvs(env)
addEnvIfNotPreviouslySetByDevbox(env, configEnv)
Expand Down
1 change: 1 addition & 0 deletions internal/impl/devopt/devboxopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Opts struct {
Pure bool
IgnoreWarnings bool
CustomProcessComposeFile string
OmitBinWrappersFromPath bool
Writer io.Writer
}

Expand Down