Skip to content

Commit be10969

Browse files
authored
Turn off auto-detection for language on devbox shell (#222)
## Summary Turn off auto-detection for language on devbox shell. This means: 1. `devbox plan` outputs plan for build only 2. `devbox shell` does not automatically add packages based on the project 3. `devbox shell` no longer automatically sets init hooks (python can potentially be the biggest one being affected by this change, but as far as I know, it wasn't being used before) I also added a `devbox.json` to the root of this project, because I need go 1.19 and I have go 1.18 on my personal machine. ## How was it tested? devbox shell devbox build go test ./...
1 parent e70e25e commit be10969

File tree

9 files changed

+22
-29
lines changed

9 files changed

+22
-29
lines changed

boxcli/plan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func runPlanCmd(cmd *cobra.Command, args []string) error {
3131
return errors.WithStack(err)
3232
}
3333

34-
plan, err := box.ShellPlan()
34+
plan, err := box.BuildPlan()
3535
if err != nil {
3636
return errors.WithStack(err)
3737
}

devbox.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,9 @@ func (d *Devbox) Build(flags *docker.BuildFlags) error {
137137

138138
// Plan creates a plan of the actions that devbox will take to generate its
139139
// shell environment.
140-
func (d *Devbox) ShellPlan() (*plansdk.Plan, error) {
141-
userPlan := d.convertToPlan()
142-
shellPlan, err := planner.GetShellPlan(d.srcDir)
143-
if err != nil {
144-
return nil, err
145-
}
146-
return plansdk.MergeUserPlan(userPlan, shellPlan)
140+
func (d *Devbox) ShellPlan() *plansdk.Plan {
141+
// TODO: Move shell plan to a separate struct from build plan.
142+
return d.convertToPlan()
147143
}
148144

149145
// Plan creates a plan of the actions that devbox will take to generate its
@@ -172,24 +168,17 @@ func (d *Devbox) Generate() error {
172168
// Shell generates the devbox environment and launches nix-shell as a child
173169
// process.
174170
func (d *Devbox) Shell() error {
175-
176171
if err := d.ensurePackagesAreInstalled(install); err != nil {
177172
return err
178173
}
179174

180-
plan, err := d.ShellPlan()
181-
if err != nil {
182-
return errors.WithStack(err)
183-
}
184-
185175
profileDir, err := d.profileDir()
186176
if err != nil {
187177
return err
188178
}
189179

190180
nixShellFilePath := filepath.Join(d.srcDir, ".devbox/gen/shell.nix")
191181
sh, err := nix.DetectShell(
192-
nix.WithPlanInitHook(plan.ShellInitHook),
193182
nix.WithProfile(profileDir),
194183
nix.WithHistoryFile(filepath.Join(d.srcDir, shellHistoryFile)),
195184
)
@@ -245,14 +234,7 @@ func (d *Devbox) convertToPlan() *plansdk.Plan {
245234
}
246235

247236
func (d *Devbox) generateShellFiles() error {
248-
shellPlan, err := d.ShellPlan()
249-
if err != nil {
250-
return errors.WithStack(err)
251-
}
252-
if shellPlan.Invalid() {
253-
return shellPlan.Error()
254-
}
255-
return generate(d.srcDir, shellPlan, shellFiles)
237+
return generate(d.srcDir, d.ShellPlan(), shellFiles)
256238
}
257239

258240
func (d *Devbox) generateBuildFiles() error {

devbox.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"packages": [
3+
"go_1_19"
4+
],
5+
"shell": {
6+
"init_hook": null
7+
}
8+
}

devbox_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,18 @@ func testExample(t *testing.T, testPath string) {
4848
box.srcDir, err = filepath.Rel(currentDir, box.srcDir)
4949
assert.NoErrorf(err, "expect to construct relative path from %s relative to base %s", box.srcDir, currentDir)
5050

51-
plan, err := box.ShellPlan()
51+
plan, err := box.BuildPlan()
52+
buildErrorExpectedFile := filepath.Join(baseDir, "build_error_expected")
53+
hasBuildErrorExpectedFile := fileExists(buildErrorExpectedFile)
54+
if hasBuildErrorExpectedFile {
55+
assert.NotNil(err)
56+
// Since build error is expected, skip the rest of the test
57+
return
58+
}
5259
assert.NoError(err, "devbox plan should not fail")
5360

54-
generateErrorFile := filepath.Join(baseDir, "has_generate_error")
55-
hasGenerateErrorFile := fileExists(generateErrorFile)
5661
err = box.Generate()
57-
if !hasGenerateErrorFile {
58-
assert.NoError(err, "devbox generate should not fail")
59-
}
62+
assert.NoError(err, "devbox generate should not fail")
6063

6164
if !hasGoldenFile {
6265
assert.NotEmpty(plan.DevPackages, "the plan should have dev packages")

0 commit comments

Comments
 (0)