Skip to content

Commit 12a29a6

Browse files
committed
Revert "[Refactor ensureStateIsUpToDate] split into two modes for when to recompute state (#1723)"
This reverts commit e0cf344.
1 parent 700d860 commit 12a29a6

File tree

2 files changed

+17
-50
lines changed

2 files changed

+17
-50
lines changed

internal/devbox/packages.go

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,13 @@ func (d *Devbox) ensureStateIsUpToDate(ctx context.Context, mode installMode) er
255255
defer trace.StartRegion(ctx, "devboxEnsureStateIsUpToDate").End()
256256
defer debug.FunctionTimer().End()
257257

258+
// if mode is install or uninstall, then we need to update the nix-profile
259+
// and lockfile, so we must continue below.
258260
upToDate, err := d.lockfile.IsUpToDateAndInstalled()
259261
if err != nil {
260262
return err
261263
}
262264

263-
// if mode is install or uninstall, then we need to compute some state
264-
// like updating the flake or installing packages locally, so must continue
265-
// below
266265
if mode == ensure {
267266
// if mode is ensure and we are up to date, then we can skip the rest
268267
if upToDate {
@@ -271,48 +270,6 @@ func (d *Devbox) ensureStateIsUpToDate(ctx context.Context, mode installMode) er
271270
fmt.Fprintln(d.stderr, "Ensuring packages are installed.")
272271
}
273272

274-
recomputeState := mode == ensure || d.IsEnvEnabled()
275-
if recomputeState {
276-
if err := d.recomputeState(ctx, mode); err != nil {
277-
return err
278-
}
279-
} else {
280-
// TODO: in the next PR, we will only `nix build` the packages that are being
281-
// added or updated. For now, we continue to call recomputeState here.
282-
if err := d.recomputeState(ctx, mode); err != nil {
283-
return err
284-
}
285-
}
286-
287-
// If we're in a devbox shell (global or project), then the environment might
288-
// be out of date after the user installs something. If have direnv active
289-
// it should reload automatically so we don't need to refresh.
290-
if d.IsEnvEnabled() && !upToDate && !d.IsDirenvActive() {
291-
ux.Fwarning(
292-
d.stderr,
293-
"Your shell environment may be out of date. Run `%s` to update it.\n",
294-
d.refreshAliasOrCommand(),
295-
)
296-
}
297-
298-
if err := d.lockfile.Save(); err != nil {
299-
return err
300-
}
301-
302-
// If we are recomputing state, then we need to update the local.lock file.
303-
// If not, we leave the local.lock in a stale state.
304-
if recomputeState {
305-
return d.lockfile.UpdateAndSaveLocalLock()
306-
}
307-
return nil
308-
}
309-
310-
// recomputeState updates the local state comprising of:
311-
// - plugins directories
312-
// - devbox.lock file
313-
// - the generated flake
314-
// - the nix-profile
315-
func (d *Devbox) recomputeState(ctx context.Context, mode installMode) error {
316273
// Create plugin directories first because packages might need them
317274
for _, pkg := range d.InstallablePackages() {
318275
if err := d.PluginManager().Create(pkg); err != nil {
@@ -353,7 +310,18 @@ func (d *Devbox) recomputeState(ctx context.Context, mode installMode) error {
353310
}
354311
}
355312

356-
return nil
313+
// If we're in a devbox shell (global or project), then the environment might
314+
// be out of date after the user installs something. If have direnv active
315+
// it should reload automatically so we don't need to refresh.
316+
if d.IsEnvEnabled() && !upToDate && !d.IsDirenvActive() {
317+
ux.Fwarning(
318+
d.stderr,
319+
"Your shell environment may be out of date. Run `%s` to update it.\n",
320+
d.refreshAliasOrCommand(),
321+
)
322+
}
323+
324+
return d.lockfile.Save()
357325
}
358326

359327
func (d *Devbox) profilePath() (string, error) {

internal/lock/lockfile.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ func (f *File) ForceResolve(pkg string) (*Package, error) {
9898
}
9999

100100
func (f *File) Save() error {
101-
return cuecfg.WriteFile(lockFilePath(f.devboxProject), f)
102-
}
103-
104-
func (f *File) UpdateAndSaveLocalLock() error {
101+
if err := cuecfg.WriteFile(lockFilePath(f.devboxProject), f); err != nil {
102+
return err
103+
}
105104
return updateLocal(f.devboxProject)
106105
}
107106

0 commit comments

Comments
 (0)