@@ -177,7 +177,7 @@ func (d *Devbox) Shell(ctx context.Context) error {
177
177
ctx , task := trace .NewTask (ctx , "devboxShell" )
178
178
defer task .End ()
179
179
180
- envs , err := d .computeCurrentDevboxEnv (ctx )
180
+ envs , err := d .ensureStateIsUpToDateAndComputeEnv (ctx )
181
181
if err != nil {
182
182
return err
183
183
}
@@ -218,7 +218,7 @@ func (d *Devbox) RunScript(ctx context.Context, cmdName string, cmdArgs []string
218
218
return err
219
219
}
220
220
221
- env , err := d .computeCurrentDevboxEnv (ctx )
221
+ env , err := d .ensureStateIsUpToDateAndComputeEnv (ctx )
222
222
if err != nil {
223
223
return err
224
224
}
@@ -260,7 +260,7 @@ func (d *Devbox) Install(ctx context.Context) error {
260
260
ctx , task := trace .NewTask (ctx , "devboxInstall" )
261
261
defer task .End ()
262
262
263
- return d .ensureProjectStateIsCurrent (ctx , ensure )
263
+ return d .ensureStateIsUpToDate (ctx , ensure )
264
264
}
265
265
266
266
func (d * Devbox ) ListScripts () []string {
@@ -274,11 +274,11 @@ func (d *Devbox) ListScripts() []string {
274
274
return keys
275
275
}
276
276
277
- // DevboxEnvExports returns a string of the env-vars that would need to be applied
277
+ // EnvExports returns a string of the env-vars that would need to be applied
278
278
// to define a Devbox environment. The string is of the form `export KEY=VALUE` for each
279
279
// env-var that needs to be applied.
280
- func (d * Devbox ) DevboxEnvExports (ctx context.Context , opts devopt.DevboxEnvExports ) (string , error ) {
281
- ctx , task := trace .NewTask (ctx , "devboxNixEnv " )
280
+ func (d * Devbox ) EnvExports (ctx context.Context , opts devopt.EnvExportsOpts ) (string , error ) {
281
+ ctx , task := trace .NewTask (ctx , "devboxEnvExports " )
282
282
defer task .End ()
283
283
284
284
var envs map [string ]string
@@ -298,9 +298,9 @@ func (d *Devbox) DevboxEnvExports(ctx context.Context, opts devopt.DevboxEnvExpo
298
298
)
299
299
}
300
300
301
- envs , err = d .computeDevboxEnv (ctx , true /*usePrintDevEnvCache*/ )
301
+ envs , err = d .computeEnv (ctx , true /*usePrintDevEnvCache*/ )
302
302
} else {
303
- envs , err = d .computeCurrentDevboxEnv (ctx )
303
+ envs , err = d .ensureStateIsUpToDateAndComputeEnv (ctx )
304
304
}
305
305
306
306
if err != nil {
@@ -325,7 +325,7 @@ func (d *Devbox) EnvVars(ctx context.Context) ([]string, error) {
325
325
ctx , task := trace .NewTask (ctx , "devboxEnvVars" )
326
326
defer task .End ()
327
327
// this only returns env variables for the shell environment excluding hooks
328
- envs , err := d .computeCurrentDevboxEnv (ctx )
328
+ envs , err := d .ensureStateIsUpToDateAndComputeEnv (ctx )
329
329
if err != nil {
330
330
return nil , err
331
331
}
@@ -485,7 +485,7 @@ func (d *Devbox) GenerateEnvrcFile(ctx context.Context, force bool, envFlags dev
485
485
}
486
486
487
487
// generate all shell files to ensure we can refer to them in the .envrc script
488
- if err := d .ensureProjectStateIsCurrent (ctx , ensure ); err != nil {
488
+ if err := d .ensureStateIsUpToDate (ctx , ensure ); err != nil {
489
489
return err
490
490
}
491
491
@@ -757,7 +757,7 @@ func (d *Devbox) StartProcessManager(
757
757
)
758
758
}
759
759
760
- // computeDevboxEnv computes the set of environment variables that define a Devbox
760
+ // computeEnv computes the set of environment variables that define a Devbox
761
761
// environment. The "devbox run" and "devbox shell" commands source these
762
762
// variables into a shell before executing a command or showing an interactive
763
763
// prompt.
@@ -781,10 +781,10 @@ func (d *Devbox) StartProcessManager(
781
781
// programs.
782
782
//
783
783
// Note that the shellrc.tmpl template (which sources this environment) does
784
- // some additional processing. The computeDevboxEnv environment won't necessarily
784
+ // some additional processing. The computeEnv environment won't necessarily
785
785
// represent the final "devbox run" or "devbox shell" environments.
786
- func (d * Devbox ) computeDevboxEnv (ctx context.Context , usePrintDevEnvCache bool ) (map [string ]string , error ) {
787
- defer trace .StartRegion (ctx , "computeDevboxEnv " ).End ()
786
+ func (d * Devbox ) computeEnv (ctx context.Context , usePrintDevEnvCache bool ) (map [string ]string , error ) {
787
+ defer trace .StartRegion (ctx , "devboxComputeEnv " ).End ()
788
788
789
789
// Append variables from current env if --pure is not passed
790
790
currentEnv := os .Environ ()
@@ -898,6 +898,12 @@ func (d *Devbox) computeDevboxEnv(ctx context.Context, usePrintDevEnvCache bool)
898
898
899
899
markEnvsAsSetByDevbox (pluginEnv , configEnv )
900
900
901
+ // devboxEnvPath starts with the initial PATH from print-dev-env, and is
902
+ // transformed to be the "PATH of the Devbox environment"
903
+ // TODO: The prior statement is not fully true,
904
+ // since env["PATH"] is written to above and so it is already no longer "PATH
905
+ // from print-dev-env". Consider moving devboxEnvPath higher up in this function
906
+ // where env["PATH"] is written to.
901
907
devboxEnvPath := env ["PATH" ]
902
908
debug .Log ("PATH after plugins and config is: %s" , devboxEnvPath )
903
909
@@ -960,26 +966,27 @@ func (d *Devbox) computeDevboxEnv(ctx context.Context, usePrintDevEnvCache bool)
960
966
return env , d .addHashToEnv (env )
961
967
}
962
968
963
- // computeCurrentDevboxEnv will return a map of the env-vars for the Devbox Environment
969
+ // ensureStateIsUpToDateAndComputeEnv will return a map of the env-vars for the Devbox Environment
964
970
// while ensuring these reflect the current (up to date) state of the project.
965
- func (d * Devbox ) computeCurrentDevboxEnv (
971
+ // TODO: find a better name for this function.
972
+ func (d * Devbox ) ensureStateIsUpToDateAndComputeEnv (
966
973
ctx context.Context ,
967
974
) (map [string ]string , error ) {
968
975
defer debug .FunctionTimer ().End ()
969
976
970
- // When ensureProjectStateIsCurrent is called with ensure=true, it always
977
+ // When ensureStateIsUpToDate is called with ensure=true, it always
971
978
// returns early if the lockfile is up to date. So we don't need to check here
972
- if err := d .ensureProjectStateIsCurrent (ctx , ensure ); err != nil && ! strings .Contains (err .Error (), "no such host" ) {
979
+ if err := d .ensureStateIsUpToDate (ctx , ensure ); err != nil && ! strings .Contains (err .Error (), "no such host" ) {
973
980
return nil , err
974
981
} else if err != nil {
975
982
ux .Fwarning (d .stderr , "Error connecting to the internet. Will attempt to use cached environment.\n " )
976
983
}
977
984
978
- // Since ensurePackagesAreInstalled calls computeDevboxEnv when not up do date,
985
+ // Since ensureStateIsUpToDate calls computeEnv when not up do date,
979
986
// it's ok to use usePrintDevEnvCache=true here always. This does end up
980
987
// doing some non-nix work twice if lockfile is not up to date.
981
988
// TODO: Improve this to avoid extra work.
982
- return d .computeDevboxEnv (ctx , true /*usePrintDevEnvCache*/ )
989
+ return d .computeEnv (ctx , true /*usePrintDevEnvCache*/ )
983
990
}
984
991
985
992
func (d * Devbox ) nixPrintDevEnvCachePath () string {
0 commit comments