Skip to content

Commit 209c839

Browse files
authored
[print-dev-env] Skip cache if lockfile has changed (#1674)
## Summary We need to skip the PrintDevEnvCache in ComputeNixEnv if lockfile is stale. `ensurePackagesAreInstalledAndComputeEnv` had made an assumption that `ensurePackagesAreInstalled` will have called `computeNixEnv` already to ensure the PrintDevEnvCache was updated. However, after some recent refactoring, we no longer call `computeNixEnv` within `ensurePackagesAreInstalled`. So, we now need to check the lockfile status, and skip the PrintDevEnvCache if lockfile is stale. ## How was it tested? 1. Had `patch_glibc:true` for `hello` package. Did `devbox shell` and then saw that `which hello` points to the patch-glibc flake's hello. 2. exited devbox shell, and edited devbox.json to `patch_glibc:false` 3. re-started `devbox shell` and `which hello` now shows the regular nix `hello`. Previously, it would still show the patch-glibc hello since `PATH` would not have been updated to omit that.
1 parent 6b61988 commit 209c839

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

internal/impl/devbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ func (d *Devbox) ensurePackagesAreInstalledAndComputeEnv(
969969
// it's ok to use usePrintDevEnvCache=true here always. This does end up
970970
// doing some non-nix work twice if lockfile is not up to date.
971971
// TODO: Improve this to avoid extra work.
972-
return d.computeNixEnv(ctx, true)
972+
return d.computeNixEnv(ctx, true /*usePrintDevEnvCache*/)
973973
}
974974

975975
func (d *Devbox) nixPrintDevEnvCachePath() string {

internal/impl/packages.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ func (d *Devbox) ensurePackagesAreInstalled(ctx context.Context, mode installMod
289289
return err
290290
}
291291

292+
// Use the printDevEnvCache if we are adding or removing or updating any package,
293+
// AND we are not in the shellenv-enabled environment of the current devbox-project.
294+
usePrintDevEnvCache := mode != ensure && !d.IsEnvEnabled()
295+
if _, err := d.computeNixEnv(ctx, usePrintDevEnvCache); err != nil {
296+
return err
297+
}
298+
292299
// Ensure we clean out packages that are no longer needed.
293300
d.lockfile.Tidy()
294301

0 commit comments

Comments
 (0)