@@ -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 .ensurePackagesAreInstalledAndComputeEnv (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 .ensurePackagesAreInstalledAndComputeEnv (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 .ensurePackagesAreInstalled (ctx , ensure )
263
+ return d .ensureStateIsUpToDate (ctx , ensure )
264
264
}
265
265
266
266
func (d * Devbox ) ListScripts () []string {
@@ -274,8 +274,11 @@ func (d *Devbox) ListScripts() []string {
274
274
return keys
275
275
}
276
276
277
- func (d * Devbox ) NixEnv (ctx context.Context , opts devopt.NixEnvOpts ) (string , error ) {
278
- ctx , task := trace .NewTask (ctx , "devboxNixEnv" )
277
+ // EnvExports returns a string of the env-vars that would need to be applied
278
+ // to define a Devbox environment. The string is of the form `export KEY=VALUE` for each
279
+ // env-var that needs to be applied.
280
+ func (d * Devbox ) EnvExports (ctx context.Context , opts devopt.EnvExportsOpts ) (string , error ) {
281
+ ctx , task := trace .NewTask (ctx , "devboxEnvExports" )
279
282
defer task .End ()
280
283
281
284
var envs map [string ]string
@@ -295,9 +298,9 @@ func (d *Devbox) NixEnv(ctx context.Context, opts devopt.NixEnvOpts) (string, er
295
298
)
296
299
}
297
300
298
- envs , err = d .computeNixEnv (ctx , true /*usePrintDevEnvCache*/ )
301
+ envs , err = d .computeEnv (ctx , true /*usePrintDevEnvCache*/ )
299
302
} else {
300
- envs , err = d .ensurePackagesAreInstalledAndComputeEnv (ctx )
303
+ envs , err = d .ensureStateIsUpToDateAndComputeEnv (ctx )
301
304
}
302
305
303
306
if err != nil {
@@ -322,7 +325,7 @@ func (d *Devbox) EnvVars(ctx context.Context) ([]string, error) {
322
325
ctx , task := trace .NewTask (ctx , "devboxEnvVars" )
323
326
defer task .End ()
324
327
// this only returns env variables for the shell environment excluding hooks
325
- envs , err := d .ensurePackagesAreInstalledAndComputeEnv (ctx )
328
+ envs , err := d .ensureStateIsUpToDateAndComputeEnv (ctx )
326
329
if err != nil {
327
330
return nil , err
328
331
}
@@ -482,7 +485,7 @@ func (d *Devbox) GenerateEnvrcFile(ctx context.Context, force bool, envFlags dev
482
485
}
483
486
484
487
// generate all shell files to ensure we can refer to them in the .envrc script
485
- if err := d .ensurePackagesAreInstalled (ctx , ensure ); err != nil {
488
+ if err := d .ensureStateIsUpToDate (ctx , ensure ); err != nil {
486
489
return err
487
490
}
488
491
@@ -754,7 +757,7 @@ func (d *Devbox) StartProcessManager(
754
757
)
755
758
}
756
759
757
- // computeNixEnv computes the set of environment variables that define a Devbox
760
+ // computeEnv computes the set of environment variables that define a Devbox
758
761
// environment. The "devbox run" and "devbox shell" commands source these
759
762
// variables into a shell before executing a command or showing an interactive
760
763
// prompt.
@@ -778,11 +781,10 @@ func (d *Devbox) StartProcessManager(
778
781
// programs.
779
782
//
780
783
// Note that the shellrc.tmpl template (which sources this environment) does
781
- // some additional processing. The computeNixEnv environment won't necessarily
784
+ // some additional processing. The computeEnv environment won't necessarily
782
785
// represent the final "devbox run" or "devbox shell" environments.
783
- // TODO: Rename to computeDevboxEnv?
784
- func (d * Devbox ) computeNixEnv (ctx context.Context , usePrintDevEnvCache bool ) (map [string ]string , error ) {
785
- defer trace .StartRegion (ctx , "computeNixEnv" ).End ()
786
+ func (d * Devbox ) computeEnv (ctx context.Context , usePrintDevEnvCache bool ) (map [string ]string , error ) {
787
+ defer trace .StartRegion (ctx , "devboxComputeEnv" ).End ()
786
788
787
789
// Append variables from current env if --pure is not passed
788
790
currentEnv := os .Environ ()
@@ -896,15 +898,21 @@ func (d *Devbox) computeNixEnv(ctx context.Context, usePrintDevEnvCache bool) (m
896
898
897
899
markEnvsAsSetByDevbox (pluginEnv , configEnv )
898
900
899
- nixEnvPath := env ["PATH" ]
900
- debug .Log ("PATH after plugins and config is: %s" , nixEnvPath )
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.
907
+ devboxEnvPath := env ["PATH" ]
908
+ debug .Log ("PATH after plugins and config is: %s" , devboxEnvPath )
901
909
902
910
// We filter out nix store paths of devbox-packages (represented here as buildInputs).
903
911
// Motivation: if a user removes a package from their devbox it should no longer
904
912
// be available in their environment.
905
913
buildInputs := strings .Split (env ["buildInputs" ], " " )
906
914
var glibcPatchPath []string
907
- nixEnvPath = filterPathList (nixEnvPath , func (path string ) bool {
915
+ devboxEnvPath = filterPathList (devboxEnvPath , func (path string ) bool {
908
916
// TODO(gcurtis): this is a massive hack. Please get rid
909
917
// of this and install the package to the profile.
910
918
if strings .Contains (path , "patched-glibc" ) {
@@ -921,24 +929,24 @@ func (d *Devbox) computeNixEnv(ctx context.Context, usePrintDevEnvCache bool) (m
921
929
}
922
930
return true
923
931
})
924
- debug .Log ("PATH after filtering with buildInputs (%v) is: %s" , buildInputs , nixEnvPath )
932
+ debug .Log ("PATH after filtering with buildInputs (%v) is: %s" , buildInputs , devboxEnvPath )
925
933
926
934
// TODO(gcurtis): this is a massive hack. Please get rid
927
935
// of this and install the package to the profile.
928
936
if len (glibcPatchPath ) != 0 {
929
937
patchedPath := strings .Join (glibcPatchPath , string (filepath .ListSeparator ))
930
- nixEnvPath = envpath .JoinPathLists (patchedPath , nixEnvPath )
931
- debug .Log ("PATH after glibc-patch hack is: %s" , nixEnvPath )
938
+ devboxEnvPath = envpath .JoinPathLists (patchedPath , devboxEnvPath )
939
+ debug .Log ("PATH after glibc-patch hack is: %s" , devboxEnvPath )
932
940
}
933
941
934
942
runXPaths , err := d .RunXPaths (ctx )
935
943
if err != nil {
936
944
return nil , err
937
945
}
938
- nixEnvPath = envpath .JoinPathLists (nixEnvPath , runXPaths )
946
+ devboxEnvPath = envpath .JoinPathLists (devboxEnvPath , runXPaths )
939
947
940
948
pathStack := envpath .Stack (env , originalEnv )
941
- pathStack .Push (env , d .projectDirHash (), nixEnvPath , d .preservePathStack )
949
+ pathStack .Push (env , d .projectDirHash (), devboxEnvPath , d .preservePathStack )
942
950
env ["PATH" ] = pathStack .Path (env )
943
951
debug .Log ("New path stack is: %s" , pathStack )
944
952
@@ -958,25 +966,27 @@ func (d *Devbox) computeNixEnv(ctx context.Context, usePrintDevEnvCache bool) (m
958
966
return env , d .addHashToEnv (env )
959
967
}
960
968
961
- // ensurePackagesAreInstalledAndComputeEnv does what it says :P
962
- func (d * Devbox ) ensurePackagesAreInstalledAndComputeEnv (
969
+ // ensureStateIsUpToDateAndComputeEnv will return a map of the env-vars for the Devbox Environment
970
+ // while ensuring these reflect the current (up to date) state of the project.
971
+ // TODO: find a better name for this function.
972
+ func (d * Devbox ) ensureStateIsUpToDateAndComputeEnv (
963
973
ctx context.Context ,
964
974
) (map [string ]string , error ) {
965
975
defer debug .FunctionTimer ().End ()
966
976
967
- // When ensurePackagesAreInstalled is called with ensure=true, it always
977
+ // When ensureStateIsUpToDate is called with ensure=true, it always
968
978
// returns early if the lockfile is up to date. So we don't need to check here
969
- if err := d .ensurePackagesAreInstalled (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" ) {
970
980
return nil , err
971
981
} else if err != nil {
972
982
ux .Fwarning (d .stderr , "Error connecting to the internet. Will attempt to use cached environment.\n " )
973
983
}
974
984
975
- // Since ensurePackagesAreInstalled calls computeNixEnv when not up do date,
985
+ // Since ensureStateIsUpToDate calls computeEnv when not up do date,
976
986
// it's ok to use usePrintDevEnvCache=true here always. This does end up
977
987
// doing some non-nix work twice if lockfile is not up to date.
978
988
// TODO: Improve this to avoid extra work.
979
- return d .computeNixEnv (ctx , true /*usePrintDevEnvCache*/ )
989
+ return d .computeEnv (ctx , true /*usePrintDevEnvCache*/ )
980
990
}
981
991
982
992
func (d * Devbox ) nixPrintDevEnvCachePath () string {
0 commit comments