Skip to content

Commit f65e037

Browse files
authored
Revert "[RFC][direnv-inspired] introduce export and hook commands, use in devbox shell, global and direnv (#1172)" (#1233)
## Summary Reverts #1172. While we feel architecturally this is a better approach, it would introduce some non-trivial risk. For the moment, bin-wrappers seem to have stabilized so we'll punt on this, and circle back to it later. ## How was it tested? compiles - [ ] testscripts should pass
1 parent 18bbfe9 commit f65e037

18 files changed

+38
-174
lines changed

devbox.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type Devbox interface {
2121
// Adding duplicate packages is a no-op.
2222
Add(ctx context.Context, pkgs ...string) error
2323
Config() *devconfig.Config
24-
ExportHook(shellName string) (string, error)
2524
ProjectDir() string
2625
// Generate creates the directory of Nix files and the Dockerfile that define
2726
// the devbox environment.

internal/boxcli/export.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

internal/boxcli/featureflag/prompt_hook.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

internal/boxcli/global.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func globalCmd() *cobra.Command {
2626
}
2727

2828
addCommandAndHideConfigFlag(globalCmd, addCmd())
29-
addCommandAndHideConfigFlag(globalCmd, hookCmd())
3029
addCommandAndHideConfigFlag(globalCmd, installCmd())
3130
addCommandAndHideConfigFlag(globalCmd, pathCmd())
3231
addCommandAndHideConfigFlag(globalCmd, pullCmd())
@@ -113,10 +112,7 @@ func setGlobalConfigForDelegatedCommands(
113112
}
114113

115114
func ensureGlobalEnvEnabled(cmd *cobra.Command, args []string) error {
116-
// Skip checking this for shellenv and hook sub-commands of devbox global
117-
// since these commands are what will enable the global environment when
118-
// invoked from the user's shellrc
119-
if cmd.Name() == "shellenv" || cmd.Name() == "hook" {
115+
if cmd.Name() == "shellenv" {
120116
return nil
121117
}
122118
path, err := ensureGlobalConfig(cmd)

internal/boxcli/hook.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

internal/boxcli/root.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ func RootCmd() *cobra.Command {
5353
command.AddCommand(authCmd())
5454
}
5555
command.AddCommand(createCmd())
56-
command.AddCommand(exportCmd())
5756
command.AddCommand(generateCmd())
5857
command.AddCommand(globalCmd())
59-
command.AddCommand(hookCmd())
6058
command.AddCommand(infoCmd())
6159
command.AddCommand(initCmd())
6260
command.AddCommand(installCmd())

internal/boxcli/shellenv.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ func shellEnvCmd() *cobra.Command {
3636
},
3737
}
3838

39-
registerShellEnvFlags(command, &flags)
40-
command.AddCommand(shellEnvOnlyPathWithoutWrappersCmd())
41-
42-
return command
43-
}
44-
45-
func registerShellEnvFlags(command *cobra.Command, flags *shellEnvCmdFlags) {
46-
4739
command.Flags().BoolVar(
4840
&flags.runInitHook, "init-hook", false, "runs init hook after exporting shell environment")
4941
command.Flags().BoolVar(
@@ -53,6 +45,10 @@ func registerShellEnvFlags(command *cobra.Command, flags *shellEnvCmdFlags) {
5345
&flags.pure, "pure", false, "If this flag is specified, devbox creates an isolated environment inheriting almost no variables from the current environment. A few variables, in particular HOME, USER and DISPLAY, are retained.")
5446

5547
flags.config.register(command)
48+
49+
command.AddCommand(shellEnvOnlyPathWithoutWrappersCmd())
50+
51+
return command
5652
}
5753

5854
func shellEnvFunc(cmd *cobra.Command, flags shellEnvCmdFlags) (string, error) {

internal/impl/devbox.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -817,23 +817,21 @@ func (d *Devbox) computeNixEnv(ctx context.Context, usePrintDevEnvCache bool) (m
817817

818818
addEnvIfNotPreviouslySetByDevbox(env, pluginEnv)
819819

820-
envPaths := []string{}
821-
if !featureflag.PromptHook.Enabled() {
820+
env["PATH"] = JoinPathLists(
822821
// Prepend the bin-wrappers directory to the PATH. This ensures that
823822
// bin-wrappers execute before the unwrapped binaries.
824-
envPaths = append(envPaths, filepath.Join(d.projectDir, plugin.WrapperBinPath))
825-
}
826-
// Adding profile bin path is a temporary hack. Some packages .e.g. curl
827-
// don't export the correct bin in the package, instead they export
828-
// as a propagated build input. This can be fixed in 2 ways:
829-
// * have NixBins() recursively look for bins in propagated build inputs
830-
// * Turn existing planners into flakes (i.e. php, haskell) and use the bins
831-
// in the profile.
832-
// Landau: I prefer option 2 because it doesn't require us to re-implement
833-
// nix recursive bin lookup.
834-
envPaths = append(envPaths, nix.ProfileBinPath(d.projectDir), env["PATH"])
835-
836-
env["PATH"] = JoinPathLists(envPaths...)
823+
filepath.Join(d.projectDir, plugin.WrapperBinPath),
824+
// Adding profile bin path is a temporary hack. Some packages .e.g. curl
825+
// don't export the correct bin in the package, instead they export
826+
// as a propagated build input. This can be fixed in 2 ways:
827+
// * have NixBins() recursively look for bins in propagated build inputs
828+
// * Turn existing planners into flakes (i.e. php, haskell) and use the bins
829+
// in the profile.
830+
// Landau: I prefer option 2 because it doesn't require us to re-implement
831+
// nix recursive bin lookup.
832+
nix.ProfileBinPath(d.projectDir),
833+
env["PATH"],
834+
)
837835

838836
// Include env variables in devbox.json
839837
configEnv := d.configEnvs(env)

internal/impl/generate/devcontainer_util.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"runtime/trace"
1818
"strings"
1919

20-
"go.jetpack.io/devbox/internal/boxcli/featureflag"
2120
"go.jetpack.io/devbox/internal/debug"
2221
)
2322

@@ -160,9 +159,5 @@ func getDevcontainerContent(pkgs []string) *devcontainerObject {
160159
func EnvrcContent(w io.Writer) error {
161160
tmplName := "envrcContent.tmpl"
162161
t := template.Must(template.ParseFS(tmplFS, "tmpl/"+tmplName))
163-
return t.Execute(w, struct {
164-
PromptHookEnabled bool
165-
}{
166-
PromptHookEnabled: featureflag.PromptHook.Enabled(),
167-
})
162+
return t.Execute(w, nil)
168163
}
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use_devbox() {
22
watch_file devbox.json
3-
{{ if .PromptHookEnabled }}
4-
eval "$(devbox export --init-hook --install)"
5-
{{ else }}
63
eval "$(devbox shellenv --init-hook --install)"
7-
{{ end }}
84
}
95
use devbox

0 commit comments

Comments
 (0)