@@ -26,6 +26,7 @@ import (
26
26
"go.jetpack.io/devbox/internal/boxcli/featureflag"
27
27
"go.jetpack.io/devbox/internal/boxcli/generate"
28
28
"go.jetpack.io/devbox/internal/boxcli/usererr"
29
+ "go.jetpack.io/devbox/internal/cmdutil"
29
30
"go.jetpack.io/devbox/internal/conf"
30
31
"go.jetpack.io/devbox/internal/cuecfg"
31
32
"go.jetpack.io/devbox/internal/debug"
@@ -383,7 +384,7 @@ func (d *Devbox) GenerateEnvrc(force bool, source string) error {
383
384
)
384
385
}
385
386
// confirm .envrc doesn't exist and don't overwrite an existing .envrc
386
- if commandExists ("direnv" ) {
387
+ if cmdutil . Exists ("direnv" ) {
387
388
// prompt for direnv allow
388
389
var result string
389
390
isInteractiveMode := isatty .IsTerminal (os .Stdin .Fd ())
@@ -815,22 +816,26 @@ var nixEnvCache map[string]string
815
816
// Note that this is in-memory cache of the final environment, and not the same
816
817
// as the nix print-dev-env cache which is stored in a file.
817
818
func (d * Devbox ) nixEnv (ctx context.Context ) (map [string ]string , error ) {
818
- var err error
819
- if nixEnvCache == nil {
820
- usePrintDevEnvCache := false
821
-
822
- // If lockfile is up-to-date, we can use the print-dev-env cache.
823
- if lock , err := lock .Local (d ); err != nil {
824
- return nil , err
825
- } else if upToDate , err := lock .IsUpToDate (); err != nil {
826
- return nil , err
827
- } else if upToDate {
828
- usePrintDevEnvCache = true
829
- }
819
+ if nixEnvCache != nil {
820
+ return nixEnvCache , nil
821
+ }
830
822
831
- nixEnvCache , err = d .computeNixEnv (ctx , usePrintDevEnvCache )
823
+ usePrintDevEnvCache := false
824
+
825
+ // If lockfile is up-to-date, we can use the print-dev-env cache.
826
+ lockFile , err := lock .Local (d )
827
+ if err != nil {
828
+ return nil , err
832
829
}
833
- return nixEnvCache , err
830
+ upToDate , err := lockFile .IsUpToDate ()
831
+ if err != nil {
832
+ return nil , err
833
+ }
834
+ if upToDate {
835
+ usePrintDevEnvCache = true
836
+ }
837
+
838
+ return d .computeNixEnv (ctx , usePrintDevEnvCache )
834
839
}
835
840
836
841
func (d * Devbox ) ogPathKey () string {
@@ -947,11 +952,6 @@ func (d *Devbox) configEnvs(computedEnv map[string]string) map[string]string {
947
952
return conf .OSExpandEnvMap (d .cfg .Env , computedEnv , d .ProjectDir ())
948
953
}
949
954
950
- func commandExists (command string ) bool { // TODO: move to a utility package
951
- _ , err := exec .LookPath (command )
952
- return err == nil
953
- }
954
-
955
955
// ignoreCurrentEnvVar contains environment variables that Devbox should remove
956
956
// from the slice of [os.Environ] variables before sourcing them. These are
957
957
// variables that are set automatically by a new shell.
@@ -1042,7 +1042,6 @@ func addHashToEnv(env map[string]string) error {
1042
1042
hash , err := cuecfg .Hash (env )
1043
1043
if err == nil {
1044
1044
env [devboxShellEnvHashVarName ] = hash
1045
-
1046
1045
}
1047
1046
return err
1048
1047
}
0 commit comments