Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions internal/boxcli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"go.jetpack.io/devbox/internal/boxcli/featureflag"
"go.jetpack.io/devbox/internal/boxcli/midcobra"
"go.jetpack.io/devbox/internal/cloud/openssh/sshshim"
"go.jetpack.io/devbox/internal/cmdutil"
"go.jetpack.io/devbox/internal/debug"
"go.jetpack.io/devbox/internal/telemetry"
"go.jetpack.io/devbox/internal/vercheck"
Expand Down Expand Up @@ -113,6 +114,7 @@ func Execute(ctx context.Context, args []string) int {

func Main() {
timer := debug.Timer(strings.Join(os.Args, " "))
setSystemBinaryPaths()
ctx := context.Background()
if strings.HasSuffix(os.Args[0], "ssh") ||
strings.HasSuffix(os.Args[0], "scp") {
Expand Down Expand Up @@ -146,3 +148,12 @@ func listAllCommands(cmd *cobra.Command, indent string) {
listAllCommands(childCmd, indent+"\t")
}
}

func setSystemBinaryPaths() {
if os.Getenv("DEVBOX_SYSTEM_BASH") == "" {
os.Setenv("DEVBOX_SYSTEM_BASH", cmdutil.GetPathOrDefault("bash", "/bin/bash"))
}
if os.Getenv("DEVBOX_SYSTEM_SED") == "" {
os.Setenv("DEVBOX_SYSTEM_SED", cmdutil.GetPathOrDefault("sed", "/usr/bin/sed"))
}
}
16 changes: 14 additions & 2 deletions internal/wrapnix/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import (
"go.jetpack.io/devbox/internal/xdg"
)

// Avoid wrapping bash and sed to prevent accidentally creating a recursive loop
// We use DEVBOX_SYSTEM_BASH and DEVBOX_SYSTEM_SED so normally we won't use
// user versions, but we want to be extra careful.
// This also has minor performance benefits.
var dontWrap = map[string]bool{
"bash": true,
"sed": true,
}

type CreateWrappersArgs struct {
NixBins []string
ShellEnvHash string
Expand All @@ -47,14 +56,17 @@ func CreateWrappers(ctx context.Context, args CreateWrappersArgs) error {
destPath := filepath.Join(wrapperBinPath(args.ProjectDir))
_ = os.MkdirAll(destPath, 0o755)

bashPath := cmdutil.GetPathOrDefault("bash", "/bin/bash")
sedPath := cmdutil.GetPathOrDefault("sed", "sed")
bashPath := cmdutil.GetPathOrDefault(os.Getenv("DEVBOX_SYSTEM_BASH"), "/bin/bash")
sedPath := cmdutil.GetPathOrDefault(os.Getenv("DEVBOX_SYSTEM_SED"), "/usr/bin/sed")

if err := CreateDevboxSymlinkIfPossible(); err != nil {
return err
}

for _, bin := range args.NixBins {
if dontWrap[filepath.Base(bin)] {
continue
}
if err := createWrapper(&createWrapperArgs{
WrapperBinPath: destPath,
CreateWrappersArgs: args,
Expand Down