Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information