@@ -170,7 +170,7 @@ func (d *Devbox) Shell(ctx context.Context) error {
170
170
ctx , task := trace .NewTask (ctx , "devboxShell" )
171
171
defer task .End ()
172
172
173
- envs , err := d .ensurePackagesAreInstalledAndComputeEnv (ctx )
173
+ envs , err := d .computeCurrentDevboxEnv (ctx )
174
174
if err != nil {
175
175
return err
176
176
}
@@ -211,7 +211,7 @@ func (d *Devbox) RunScript(ctx context.Context, cmdName string, cmdArgs []string
211
211
return err
212
212
}
213
213
214
- env , err := d .ensurePackagesAreInstalledAndComputeEnv (ctx )
214
+ env , err := d .computeCurrentDevboxEnv (ctx )
215
215
if err != nil {
216
216
return err
217
217
}
@@ -267,7 +267,10 @@ func (d *Devbox) ListScripts() []string {
267
267
return keys
268
268
}
269
269
270
- func (d * Devbox ) NixEnv (ctx context.Context , opts devopt.NixEnvOpts ) (string , error ) {
270
+ // DevboxEnvExports returns a string of the env-vars that would need to be applied
271
+ // to define a Devbox environment. The string is of the form `export KEY=VALUE` for each
272
+ // env-var that needs to be applied.
273
+ func (d * Devbox ) DevboxEnvExports (ctx context.Context , opts devopt.DevboxEnvExports ) (string , error ) {
271
274
ctx , task := trace .NewTask (ctx , "devboxNixEnv" )
272
275
defer task .End ()
273
276
@@ -290,7 +293,7 @@ func (d *Devbox) NixEnv(ctx context.Context, opts devopt.NixEnvOpts) (string, er
290
293
291
294
envs , err = d .computeDevboxEnv (ctx , true /*usePrintDevEnvCache*/ )
292
295
} else {
293
- envs , err = d .ensurePackagesAreInstalledAndComputeEnv (ctx )
296
+ envs , err = d .computeCurrentDevboxEnv (ctx )
294
297
}
295
298
296
299
if err != nil {
@@ -315,7 +318,7 @@ func (d *Devbox) EnvVars(ctx context.Context) ([]string, error) {
315
318
ctx , task := trace .NewTask (ctx , "devboxEnvVars" )
316
319
defer task .End ()
317
320
// this only returns env variables for the shell environment excluding hooks
318
- envs , err := d .ensurePackagesAreInstalledAndComputeEnv (ctx )
321
+ envs , err := d .computeCurrentDevboxEnv (ctx )
319
322
if err != nil {
320
323
return nil , err
321
324
}
@@ -888,15 +891,15 @@ func (d *Devbox) computeDevboxEnv(ctx context.Context, usePrintDevEnvCache bool)
888
891
889
892
markEnvsAsSetByDevbox (pluginEnv , configEnv )
890
893
891
- nixEnvPath := env ["PATH" ]
892
- debug .Log ("PATH after plugins and config is: %s" , nixEnvPath )
894
+ devboxEnvPath := env ["PATH" ]
895
+ debug .Log ("PATH after plugins and config is: %s" , devboxEnvPath )
893
896
894
897
// We filter out nix store paths of devbox-packages (represented here as buildInputs).
895
898
// Motivation: if a user removes a package from their devbox it should no longer
896
899
// be available in their environment.
897
900
buildInputs := strings .Split (env ["buildInputs" ], " " )
898
901
var glibcPatchPath []string
899
- nixEnvPath = filterPathList (nixEnvPath , func (path string ) bool {
902
+ devboxEnvPath = filterPathList (devboxEnvPath , func (path string ) bool {
900
903
// TODO(gcurtis): this is a massive hack. Please get rid
901
904
// of this and install the package to the profile.
902
905
if strings .Contains (path , "patched-glibc" ) {
@@ -913,24 +916,24 @@ func (d *Devbox) computeDevboxEnv(ctx context.Context, usePrintDevEnvCache bool)
913
916
}
914
917
return true
915
918
})
916
- debug .Log ("PATH after filtering with buildInputs (%v) is: %s" , buildInputs , nixEnvPath )
919
+ debug .Log ("PATH after filtering with buildInputs (%v) is: %s" , buildInputs , devboxEnvPath )
917
920
918
921
// TODO(gcurtis): this is a massive hack. Please get rid
919
922
// of this and install the package to the profile.
920
923
if len (glibcPatchPath ) != 0 {
921
924
patchedPath := strings .Join (glibcPatchPath , string (filepath .ListSeparator ))
922
- nixEnvPath = envpath .JoinPathLists (patchedPath , nixEnvPath )
923
- debug .Log ("PATH after glibc-patch hack is: %s" , nixEnvPath )
925
+ devboxEnvPath = envpath .JoinPathLists (patchedPath , devboxEnvPath )
926
+ debug .Log ("PATH after glibc-patch hack is: %s" , devboxEnvPath )
924
927
}
925
928
926
929
runXPaths , err := d .RunXPaths (ctx )
927
930
if err != nil {
928
931
return nil , err
929
932
}
930
- nixEnvPath = envpath .JoinPathLists (nixEnvPath , runXPaths )
933
+ devboxEnvPath = envpath .JoinPathLists (devboxEnvPath , runXPaths )
931
934
932
935
pathStack := envpath .Stack (env , originalEnv )
933
- pathStack .Push (env , d .projectDirHash (), nixEnvPath , d .preservePathStack )
936
+ pathStack .Push (env , d .projectDirHash (), devboxEnvPath , d .preservePathStack )
934
937
env ["PATH" ] = pathStack .Path (env )
935
938
debug .Log ("New path stack is: %s" , pathStack )
936
939
@@ -950,13 +953,14 @@ func (d *Devbox) computeDevboxEnv(ctx context.Context, usePrintDevEnvCache bool)
950
953
return env , d .addHashToEnv (env )
951
954
}
952
955
953
- // ensurePackagesAreInstalledAndComputeEnv does what it says :P
954
- func (d * Devbox ) ensurePackagesAreInstalledAndComputeEnv (
956
+ // computeCurrentDevboxEnv will return a map of the env-vars for the Devbox Environment
957
+ // while ensuring these reflect the current (up to date) state of the project.
958
+ func (d * Devbox ) computeCurrentDevboxEnv (
955
959
ctx context.Context ,
956
960
) (map [string ]string , error ) {
957
961
defer debug .FunctionTimer ().End ()
958
962
959
- // When ensurePackagesAreInstalled is called with ensure=true, it always
963
+ // When ensureProjectStateIsCurrent is called with ensure=true, it always
960
964
// returns early if the lockfile is up to date. So we don't need to check here
961
965
if err := d .ensureProjectStateIsCurrent (ctx , ensure ); err != nil && ! strings .Contains (err .Error (), "no such host" ) {
962
966
return nil , err
0 commit comments