@@ -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 .computeCurrentDevboxEnv (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 .computeCurrentDevboxEnv (ctx )
222
222
if err != nil {
223
223
return err
224
224
}
@@ -274,7 +274,10 @@ 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 ) {
277
+ // DevboxEnvExports 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 ) DevboxEnvExports (ctx context.Context , opts devopt.DevboxEnvExports ) (string , error ) {
278
281
ctx , task := trace .NewTask (ctx , "devboxNixEnv" )
279
282
defer task .End ()
280
283
@@ -297,7 +300,7 @@ func (d *Devbox) NixEnv(ctx context.Context, opts devopt.NixEnvOpts) (string, er
297
300
298
301
envs , err = d .computeDevboxEnv (ctx , true /*usePrintDevEnvCache*/ )
299
302
} else {
300
- envs , err = d .ensurePackagesAreInstalledAndComputeEnv (ctx )
303
+ envs , err = d .computeCurrentDevboxEnv (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 .computeCurrentDevboxEnv (ctx )
326
329
if err != nil {
327
330
return nil , err
328
331
}
@@ -895,15 +898,15 @@ func (d *Devbox) computeDevboxEnv(ctx context.Context, usePrintDevEnvCache bool)
895
898
896
899
markEnvsAsSetByDevbox (pluginEnv , configEnv )
897
900
898
- nixEnvPath := env ["PATH" ]
899
- debug .Log ("PATH after plugins and config is: %s" , nixEnvPath )
901
+ devboxEnvPath := env ["PATH" ]
902
+ debug .Log ("PATH after plugins and config is: %s" , devboxEnvPath )
900
903
901
904
// We filter out nix store paths of devbox-packages (represented here as buildInputs).
902
905
// Motivation: if a user removes a package from their devbox it should no longer
903
906
// be available in their environment.
904
907
buildInputs := strings .Split (env ["buildInputs" ], " " )
905
908
var glibcPatchPath []string
906
- nixEnvPath = filterPathList (nixEnvPath , func (path string ) bool {
909
+ devboxEnvPath = filterPathList (devboxEnvPath , func (path string ) bool {
907
910
// TODO(gcurtis): this is a massive hack. Please get rid
908
911
// of this and install the package to the profile.
909
912
if strings .Contains (path , "patched-glibc" ) {
@@ -920,24 +923,24 @@ func (d *Devbox) computeDevboxEnv(ctx context.Context, usePrintDevEnvCache bool)
920
923
}
921
924
return true
922
925
})
923
- debug .Log ("PATH after filtering with buildInputs (%v) is: %s" , buildInputs , nixEnvPath )
926
+ debug .Log ("PATH after filtering with buildInputs (%v) is: %s" , buildInputs , devboxEnvPath )
924
927
925
928
// TODO(gcurtis): this is a massive hack. Please get rid
926
929
// of this and install the package to the profile.
927
930
if len (glibcPatchPath ) != 0 {
928
931
patchedPath := strings .Join (glibcPatchPath , string (filepath .ListSeparator ))
929
- nixEnvPath = envpath .JoinPathLists (patchedPath , nixEnvPath )
930
- debug .Log ("PATH after glibc-patch hack is: %s" , nixEnvPath )
932
+ devboxEnvPath = envpath .JoinPathLists (patchedPath , devboxEnvPath )
933
+ debug .Log ("PATH after glibc-patch hack is: %s" , devboxEnvPath )
931
934
}
932
935
933
936
runXPaths , err := d .RunXPaths (ctx )
934
937
if err != nil {
935
938
return nil , err
936
939
}
937
- nixEnvPath = envpath .JoinPathLists (nixEnvPath , runXPaths )
940
+ devboxEnvPath = envpath .JoinPathLists (devboxEnvPath , runXPaths )
938
941
939
942
pathStack := envpath .Stack (env , originalEnv )
940
- pathStack .Push (env , d .projectDirHash (), nixEnvPath , d .preservePathStack )
943
+ pathStack .Push (env , d .projectDirHash (), devboxEnvPath , d .preservePathStack )
941
944
env ["PATH" ] = pathStack .Path (env )
942
945
debug .Log ("New path stack is: %s" , pathStack )
943
946
@@ -957,13 +960,14 @@ func (d *Devbox) computeDevboxEnv(ctx context.Context, usePrintDevEnvCache bool)
957
960
return env , d .addHashToEnv (env )
958
961
}
959
962
960
- // ensurePackagesAreInstalledAndComputeEnv does what it says :P
961
- func (d * Devbox ) ensurePackagesAreInstalledAndComputeEnv (
963
+ // computeCurrentDevboxEnv will return a map of the env-vars for the Devbox Environment
964
+ // while ensuring these reflect the current (up to date) state of the project.
965
+ func (d * Devbox ) computeCurrentDevboxEnv (
962
966
ctx context.Context ,
963
967
) (map [string ]string , error ) {
964
968
defer debug .FunctionTimer ().End ()
965
969
966
- // When ensurePackagesAreInstalled is called with ensure=true, it always
970
+ // When ensureProjectStateIsCurrent is called with ensure=true, it always
967
971
// returns early if the lockfile is up to date. So we don't need to check here
968
972
if err := d .ensureProjectStateIsCurrent (ctx , ensure ); err != nil && ! strings .Contains (err .Error (), "no such host" ) {
969
973
return nil , err
0 commit comments