@@ -177,7 +177,7 @@ func (d *Devbox) Shell(ctx context.Context) error {
177177 ctx , task := trace .NewTask (ctx , "devboxShell" )
178178 defer task .End ()
179179
180- envs , err := d .ensurePackagesAreInstalledAndComputeEnv (ctx )
180+ envs , err := d .ensureStateIsUpToDateAndComputeEnv (ctx )
181181 if err != nil {
182182 return err
183183 }
@@ -218,7 +218,7 @@ func (d *Devbox) RunScript(ctx context.Context, cmdName string, cmdArgs []string
218218 return err
219219 }
220220
221- env , err := d .ensurePackagesAreInstalledAndComputeEnv (ctx )
221+ env , err := d .ensureStateIsUpToDateAndComputeEnv (ctx )
222222 if err != nil {
223223 return err
224224 }
@@ -260,7 +260,7 @@ func (d *Devbox) Install(ctx context.Context) error {
260260 ctx , task := trace .NewTask (ctx , "devboxInstall" )
261261 defer task .End ()
262262
263- return d .ensurePackagesAreInstalled (ctx , ensure )
263+ return d .ensureStateIsUpToDate (ctx , ensure )
264264}
265265
266266func (d * Devbox ) ListScripts () []string {
@@ -274,8 +274,11 @@ func (d *Devbox) ListScripts() []string {
274274 return keys
275275}
276276
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" )
279282 defer task .End ()
280283
281284 var envs map [string ]string
@@ -295,9 +298,9 @@ func (d *Devbox) NixEnv(ctx context.Context, opts devopt.NixEnvOpts) (string, er
295298 )
296299 }
297300
298- envs , err = d .computeNixEnv (ctx , true /*usePrintDevEnvCache*/ )
301+ envs , err = d .computeEnv (ctx , true /*usePrintDevEnvCache*/ )
299302 } else {
300- envs , err = d .ensurePackagesAreInstalledAndComputeEnv (ctx )
303+ envs , err = d .ensureStateIsUpToDateAndComputeEnv (ctx )
301304 }
302305
303306 if err != nil {
@@ -322,7 +325,7 @@ func (d *Devbox) EnvVars(ctx context.Context) ([]string, error) {
322325 ctx , task := trace .NewTask (ctx , "devboxEnvVars" )
323326 defer task .End ()
324327 // this only returns env variables for the shell environment excluding hooks
325- envs , err := d .ensurePackagesAreInstalledAndComputeEnv (ctx )
328+ envs , err := d .ensureStateIsUpToDateAndComputeEnv (ctx )
326329 if err != nil {
327330 return nil , err
328331 }
@@ -482,7 +485,7 @@ func (d *Devbox) GenerateEnvrcFile(ctx context.Context, force bool, envFlags dev
482485 }
483486
484487 // 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 {
486489 return err
487490 }
488491
@@ -754,7 +757,7 @@ func (d *Devbox) StartProcessManager(
754757 )
755758}
756759
757- // computeNixEnv computes the set of environment variables that define a Devbox
760+ // computeEnv computes the set of environment variables that define a Devbox
758761// environment. The "devbox run" and "devbox shell" commands source these
759762// variables into a shell before executing a command or showing an interactive
760763// prompt.
@@ -778,11 +781,10 @@ func (d *Devbox) StartProcessManager(
778781// programs.
779782//
780783// 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
782785// 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 ()
786788
787789 // Append variables from current env if --pure is not passed
788790 currentEnv := os .Environ ()
@@ -896,15 +898,21 @@ func (d *Devbox) computeNixEnv(ctx context.Context, usePrintDevEnvCache bool) (m
896898
897899 markEnvsAsSetByDevbox (pluginEnv , configEnv )
898900
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 )
901909
902910 // We filter out nix store paths of devbox-packages (represented here as buildInputs).
903911 // Motivation: if a user removes a package from their devbox it should no longer
904912 // be available in their environment.
905913 buildInputs := strings .Split (env ["buildInputs" ], " " )
906914 var glibcPatchPath []string
907- nixEnvPath = filterPathList (nixEnvPath , func (path string ) bool {
915+ devboxEnvPath = filterPathList (devboxEnvPath , func (path string ) bool {
908916 // TODO(gcurtis): this is a massive hack. Please get rid
909917 // of this and install the package to the profile.
910918 if strings .Contains (path , "patched-glibc" ) {
@@ -921,24 +929,24 @@ func (d *Devbox) computeNixEnv(ctx context.Context, usePrintDevEnvCache bool) (m
921929 }
922930 return true
923931 })
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 )
925933
926934 // TODO(gcurtis): this is a massive hack. Please get rid
927935 // of this and install the package to the profile.
928936 if len (glibcPatchPath ) != 0 {
929937 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 )
932940 }
933941
934942 runXPaths , err := d .RunXPaths (ctx )
935943 if err != nil {
936944 return nil , err
937945 }
938- nixEnvPath = envpath .JoinPathLists (nixEnvPath , runXPaths )
946+ devboxEnvPath = envpath .JoinPathLists (devboxEnvPath , runXPaths )
939947
940948 pathStack := envpath .Stack (env , originalEnv )
941- pathStack .Push (env , d .projectDirHash (), nixEnvPath , d .preservePathStack )
949+ pathStack .Push (env , d .projectDirHash (), devboxEnvPath , d .preservePathStack )
942950 env ["PATH" ] = pathStack .Path (env )
943951 debug .Log ("New path stack is: %s" , pathStack )
944952
@@ -958,25 +966,27 @@ func (d *Devbox) computeNixEnv(ctx context.Context, usePrintDevEnvCache bool) (m
958966 return env , d .addHashToEnv (env )
959967}
960968
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 (
963973 ctx context.Context ,
964974) (map [string ]string , error ) {
965975 defer debug .FunctionTimer ().End ()
966976
967- // When ensurePackagesAreInstalled is called with ensure=true, it always
977+ // When ensureStateIsUpToDate is called with ensure=true, it always
968978 // 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" ) {
970980 return nil , err
971981 } else if err != nil {
972982 ux .Fwarning (d .stderr , "Error connecting to the internet. Will attempt to use cached environment.\n " )
973983 }
974984
975- // Since ensurePackagesAreInstalled calls computeNixEnv when not up do date,
985+ // Since ensureStateIsUpToDate calls computeEnv when not up do date,
976986 // it's ok to use usePrintDevEnvCache=true here always. This does end up
977987 // doing some non-nix work twice if lockfile is not up to date.
978988 // TODO: Improve this to avoid extra work.
979- return d .computeNixEnv (ctx , true /*usePrintDevEnvCache*/ )
989+ return d .computeEnv (ctx , true /*usePrintDevEnvCache*/ )
980990}
981991
982992func (d * Devbox ) nixPrintDevEnvCachePath () string {
0 commit comments