Commit a1d3832
authored
Improve handling when no SHELL env-var is defined (#700)
## Summary
Previously, if `SHELL` env-var was not set, we'd return an error from
`nix.DetectShell`
and initialize an empty struct `nix.Shell{}`. Then, in `Shell.Run` we'd
see that `Shell.binPath` is empty
and call `nix-shell`.
This has the following problems:
1. Initializing an empty `nix.Shell{}` means that we drop all the other
`ShellOptions`
in the constructor.
2. In `Shell.Run`, we'd use `nix-shell` but fail if the flakes feature
was not enabled. This `nix-shell` also loses all the print-dev-env work
that we have done for Unified-Env.
To solve and/or mitigate these issues, I propose the following changes:
- Rename `nix.Shell` to `nix.DevboxShell` to make it clear that its not
a raw nix shell. TODO for future to move this out of `nix` package.
- Rename `nix.DetectShell` to `nix.NewDevboxShell` to make clear that it
is a constructor function. Decompose its functionality into helper
functions `shellPath` and `initShellBinaryFields`.
- If `SHELL` is undefined, ~we loop over a list of common shells to see
if they are accessible in the `PATH`.~ we use the bash from nix.
- Failing to find ~any recognizable shell in `PATH`,~ bash from nix, we
fail the program with an error.
- Remove the fallback to `nix-shell` in `Shell.Run`. This means we
_always_ use the Unified-Env codepath.
- Update `shell_test` for Flakes feature, since it now finds a shell
from PATH and uses that (previously, would error).
## How was it tested?
in `examples/testdata/go/go-1.19`:
```
❯ DEVBOX_DEBUG=0 SHELL= DEVBOX_FEATURE_FLAKES=0 devbox shell
Ensuring packages are installed.
Starting a devbox shell...
(devbox) Savil-Srivastavas-MacBook-Pro:go-1.19 savil$ echo $SHELL
/nix/store/1bsjl5incfnszv7scdh4d02sh45vw2w1-bash-5.1-p16/bin/bash
(devbox) Savil-Srivastavas-MacBook-Pro:go-1.19 savil$ exit
exit
❯ DEVBOX_DEBUG=0 SHELL= DEVBOX_FEATURE_FLAKES=1 devbox shell
Ensuring packages are installed.
Installing package: go_1_19.
[1/1] go_1_19
[1/1] go_1_19: Success
Starting a devbox shell...
(devbox) Savil-Srivastavas-MacBook-Pro:go-1.19 savil$ echo $SHELL
/nix/store/1bsjl5incfnszv7scdh4d02sh45vw2w1-bash-5.1-p16/bin/bash
(devbox) Savil-Srivastavas-MacBook-Pro:go-1.19 savil$
```
Also: `go test ./...` with flakes feature enabled and disabled.1 parent e12d3b6 commit a1d3832
File tree
4 files changed
+132
-86
lines changed- internal
- boxcli
- impl
- nix
4 files changed
+132
-86
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
| |||
314 | 312 | | |
315 | 313 | | |
316 | 314 | | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
| 315 | + | |
| 316 | + | |
326 | 317 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
274 | | - | |
| 274 | + | |
275 | 275 | | |
276 | | - | |
277 | | - | |
| 276 | + | |
278 | 277 | | |
279 | 278 | | |
280 | 279 | | |
| |||
358 | 357 | | |
359 | 358 | | |
360 | 359 | | |
361 | | - | |
| 360 | + | |
362 | 361 | | |
363 | 362 | | |
364 | 363 | | |
365 | | - | |
| 364 | + | |
366 | 365 | | |
367 | 366 | | |
368 | 367 | | |
| |||
381 | 380 | | |
382 | 381 | | |
383 | 382 | | |
384 | | - | |
| 383 | + | |
| 384 | + | |
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | | - | |
| 393 | + | |
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
| |||
0 commit comments