File tree Expand file tree Collapse file tree 3 files changed +55
-3
lines changed Expand file tree Collapse file tree 3 files changed +55
-3
lines changed Original file line number Diff line number Diff line change @@ -57,11 +57,11 @@ func runScriptCmd(args []string, flags runCmdFlags) error {
57
57
}
58
58
59
59
if devbox .IsDevboxShellEnabled () {
60
- return errors .New ("You are already in an active devbox shell.\n Run 'exit' before calling devbox run again. Shell inception is not supported yet." )
60
+ err = box .RunScriptInShell (script )
61
+ } else {
62
+ err = box .RunScript (script )
61
63
}
62
64
63
- err = box .RunScript (script )
64
-
65
65
var exitErr * exec.ExitError
66
66
if errors .As (err , & exitErr ) {
67
67
return nil
Original file line number Diff line number Diff line change @@ -265,6 +265,32 @@ func (d *Devbox) Shell() error {
265
265
return shell .Run (nixShellFilePath )
266
266
}
267
267
268
+ func (d * Devbox ) RunScriptInShell (scriptName string ) error {
269
+ profileDir , err := d .profileDir ()
270
+ if err != nil {
271
+ return err
272
+ }
273
+
274
+ script := d .cfg .Shell .Scripts [scriptName ]
275
+ if script == nil {
276
+ return errors .Errorf ("unable to find a script with name %s" , scriptName )
277
+ }
278
+
279
+ shell , err := nix .DetectShell (
280
+ nix .WithProfile (profileDir ),
281
+ nix .WithHistoryFile (filepath .Join (d .configDir , shellHistoryFile )),
282
+ nix .WithUserScript (scriptName , script .String ()),
283
+ nix .WithConfigDir (d .configDir ),
284
+ )
285
+
286
+ if err != nil {
287
+ fmt .Print (err )
288
+ shell = & nix.Shell {}
289
+ }
290
+
291
+ return shell .RunInShell ()
292
+ }
293
+
268
294
// TODO: consider unifying the implementations of RunScript and Shell.
269
295
func (d * Devbox ) RunScript (scriptName string ) error {
270
296
if err := d .ensurePackagesAreInstalled (install ); err != nil {
Original file line number Diff line number Diff line change @@ -265,6 +265,32 @@ func (s *Shell) execCommand() string {
265
265
return strings .Join (args , " " )
266
266
}
267
267
268
+ func (s * Shell ) RunInShell () error {
269
+ env := append (
270
+ os .Environ (),
271
+ // Prevent the user's shellrc from re-sourcing nix-daemon.sh
272
+ // inside the devbox shell.
273
+ "__ETC_PROFILE_NIX_SOURCED=1" ,
274
+ )
275
+ debug .Log ("Running inside devbox shell with environment: %v" , env )
276
+ cmd := exec .Command (s .execCommandInShell ())
277
+ cmd .Env = env
278
+ cmd .Stdin = os .Stdin
279
+ cmd .Stdout = os .Stdout
280
+ cmd .Stderr = os .Stderr
281
+ debug .Log ("Executing command from inside devbox shell: %v" , cmd .Args )
282
+ return errors .WithStack (cmd .Run ())
283
+ }
284
+
285
+ func (s * Shell ) execCommandInShell () (string , string , string ) {
286
+ args := []string {}
287
+
288
+ if s .ScriptCommand != "" {
289
+ args = append (args , "-ic" )
290
+ }
291
+ return s .binPath , strings .Join (args , " " ), s .ScriptCommand
292
+ }
293
+
268
294
func (s * Shell ) writeDevboxShellrc () (path string , err error ) {
269
295
if s .userShellrcPath == "" {
270
296
// If this happens, then there's a bug with how we detect shells
You can’t perform that action at this time.
0 commit comments