@@ -30,6 +30,7 @@ import (
30
30
"go.jetpack.io/devbox/internal/searcher"
31
31
"go.jetpack.io/devbox/internal/shellgen"
32
32
"go.jetpack.io/devbox/internal/telemetry"
33
+ "go.jetpack.io/devbox/internal/wrapnix"
33
34
34
35
"go.jetpack.io/devbox/internal/boxcli/usererr"
35
36
"go.jetpack.io/devbox/internal/cmdutil"
@@ -67,7 +68,6 @@ type Devbox struct {
67
68
pure bool
68
69
allowInsecureAdds bool
69
70
customProcessComposeFile string
70
- OmitBinWrappersFromPath bool
71
71
72
72
// This is needed because of the --quiet flag.
73
73
stderr io.Writer
@@ -98,7 +98,6 @@ func Open(opts *devopt.Opts) (*Devbox, error) {
98
98
pure : opts .Pure ,
99
99
customProcessComposeFile : opts .CustomProcessComposeFile ,
100
100
allowInsecureAdds : opts .AllowInsecureAdds ,
101
- OmitBinWrappersFromPath : opts .OmitBinWrappersFromPath ,
102
101
}
103
102
104
103
lock , err := lock .GetFile (box )
@@ -221,6 +220,19 @@ func (d *Devbox) RunScript(ctx context.Context, cmdName string, cmdArgs []string
221
220
if err != nil {
222
221
return err
223
222
}
223
+
224
+ // By default we always remove bin wrappers when using `run`. This env var is
225
+ // for testing. Once we completely remove bin wrappers we can remove this.
226
+ // It helps simulate shell using "run".
227
+ if includeBinWrappers , _ := strconv .ParseBool (
228
+ os .Getenv ("DEVBOX_INCLUDE_BIN_WRAPPERS_IN_PATH" ),
229
+ ); ! includeBinWrappers {
230
+ env ["PATH" ] = envpath .RemoveFromPath (
231
+ env ["PATH" ],
232
+ wrapnix .WrapperBinPath (d .projectDir ),
233
+ )
234
+ }
235
+
224
236
// Used to determine whether we're inside a shell (e.g. to prevent shell inception)
225
237
// This is temporary because StartServices() needs it but should be replaced with
226
238
// better alternative since devbox run and devbox shell are not the same.
@@ -526,15 +538,21 @@ func (d *Devbox) Services() (services.Services, error) {
526
538
return result , nil
527
539
}
528
540
529
- func (d * Devbox ) StartServices (ctx context.Context , serviceNames ... string ) error {
530
- if ! d .IsEnvEnabled () {
531
- return d .RunScript (ctx , "devbox" , append ([]string {"services" , "start" }, serviceNames ... ))
541
+ func (d * Devbox ) StartServices (
542
+ ctx context.Context , runInCurrentShell bool , serviceNames ... string ) error {
543
+ if ! runInCurrentShell {
544
+ return d .RunScript (ctx , "devbox" ,
545
+ append (
546
+ []string {"services" , "start" , "--run-in-current-shell" },
547
+ serviceNames ... ,
548
+ ),
549
+ )
532
550
}
533
551
534
552
if ! services .ProcessManagerIsRunning (d .projectDir ) {
535
553
fmt .Fprintln (d .stderr , "Process-compose is not running. Starting it now..." )
536
554
fmt .Fprintln (d .stderr , "\n NOTE: We recommend using `devbox services up` to start process-compose and your services" )
537
- return d .StartProcessManager (ctx , serviceNames , true , "" )
555
+ return d .StartProcessManager (ctx , runInCurrentShell , serviceNames , true , "" )
538
556
}
539
557
540
558
svcSet , err := d .Services ()
@@ -563,9 +581,9 @@ func (d *Devbox) StartServices(ctx context.Context, serviceNames ...string) erro
563
581
return nil
564
582
}
565
583
566
- func (d * Devbox ) StopServices (ctx context.Context , allProjects bool , serviceNames ... string ) error {
567
- if ! d . IsEnvEnabled () {
568
- args := []string {"services" , "stop" }
584
+ func (d * Devbox ) StopServices (ctx context.Context , runInCurrentShell bool , allProjects bool , serviceNames ... string ) error {
585
+ if ! runInCurrentShell {
586
+ args := []string {"services" , "stop" , "--run-in-current-shell" }
569
587
args = append (args , serviceNames ... )
570
588
if allProjects {
571
589
args = append (args , "--all-projects" )
@@ -602,9 +620,10 @@ func (d *Devbox) StopServices(ctx context.Context, allProjects bool, serviceName
602
620
return nil
603
621
}
604
622
605
- func (d * Devbox ) ListServices (ctx context.Context ) error {
606
- if ! d .IsEnvEnabled () {
607
- return d .RunScript (ctx , "devbox" , []string {"services" , "ls" })
623
+ func (d * Devbox ) ListServices (ctx context.Context , runInCurrentShell bool ) error {
624
+ if ! runInCurrentShell {
625
+ return d .RunScript (ctx ,
626
+ "devbox" , []string {"services" , "ls" , "--run-in-current-shell" })
608
627
}
609
628
610
629
svcSet , err := d .Services ()
@@ -640,15 +659,21 @@ func (d *Devbox) ListServices(ctx context.Context) error {
640
659
return nil
641
660
}
642
661
643
- func (d * Devbox ) RestartServices (ctx context.Context , serviceNames ... string ) error {
644
- if ! d .IsEnvEnabled () {
645
- return d .RunScript (ctx , "devbox" , append ([]string {"services" , "restart" }, serviceNames ... ))
662
+ func (d * Devbox ) RestartServices (
663
+ ctx context.Context , runInCurrentShell bool , serviceNames ... string ) error {
664
+ if ! runInCurrentShell {
665
+ return d .RunScript (ctx , "devbox" ,
666
+ append (
667
+ []string {"services" , "restart" , "--run-in-current-shell" },
668
+ serviceNames ... ,
669
+ ),
670
+ )
646
671
}
647
672
648
673
if ! services .ProcessManagerIsRunning (d .projectDir ) {
649
674
fmt .Fprintln (d .stderr , "Process-compose is not running. Starting it now..." )
650
675
fmt .Fprintln (d .stderr , "\n Tip: We recommend using `devbox services up` to start process-compose and your services" )
651
- return d .StartProcessManager (ctx , serviceNames , true , "" )
676
+ return d .StartProcessManager (ctx , runInCurrentShell , serviceNames , true , "" )
652
677
}
653
678
654
679
// TODO: Restart with no services should restart the _currently running_ services. This means we should get the list of running services from the process-compose, then restart them all.
@@ -674,12 +699,13 @@ func (d *Devbox) RestartServices(ctx context.Context, serviceNames ...string) er
674
699
675
700
func (d * Devbox ) StartProcessManager (
676
701
ctx context.Context ,
702
+ runInCurrentShell bool ,
677
703
requestedServices []string ,
678
704
background bool ,
679
705
processComposeFileOrDir string ,
680
706
) error {
681
- if ! d . IsEnvEnabled () {
682
- args := []string {"services" , "up" }
707
+ if ! runInCurrentShell {
708
+ args := []string {"services" , "up" , "--run-in-current-shell" }
683
709
args = append (args , requestedServices ... )
684
710
if processComposeFileOrDir != "" {
685
711
args = append (args , "--process-compose-file" , processComposeFileOrDir )
@@ -853,17 +879,11 @@ func (d *Devbox) computeNixEnv(ctx context.Context, usePrintDevEnvCache bool) (m
853
879
addEnvIfNotPreviouslySetByDevbox (env , pluginEnv )
854
880
855
881
env ["PATH" ] = envpath .JoinPathLists (
882
+ filepath .Join (d .projectDir , plugin .WrapperBinPath ),
856
883
nix .ProfileBinPath (d .projectDir ),
857
884
env ["PATH" ],
858
885
)
859
886
860
- if ! d .OmitBinWrappersFromPath {
861
- env ["PATH" ] = envpath .JoinPathLists (
862
- filepath .Join (d .projectDir , plugin .WrapperBinPath ),
863
- env ["PATH" ],
864
- )
865
- }
866
-
867
887
env ["PATH" ], err = d .addUtilitiesToPath (ctx , env ["PATH" ])
868
888
if err != nil {
869
889
return nil , err
0 commit comments