From 63a3de8ccae99d33b93e73d430140f8f77f75353 Mon Sep 17 00:00:00 2001 From: Savil Srivastava <676452+savil@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:45:33 -0700 Subject: [PATCH 1/4] [lockfile] When updating store-paths, we should also update the resolved field --- devbox.lock | 10 +++++----- internal/impl/update.go | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/devbox.lock b/devbox.lock index 4ee4fc76b35..977dcf634c0 100644 --- a/devbox.lock +++ b/devbox.lock @@ -3,21 +3,21 @@ "packages": { "go@latest": { "last_modified": "2023-09-10T10:53:27Z", - "resolved": "github:NixOS/nixpkgs/78058d810644f5ed276804ce7ea9e82d92bee293#go_1_21", + "resolved": "github:NixOS/nixpkgs/46688f8eb5cd6f1298d873d4d2b9cf245e09e88e#go_1_21", "source": "devbox-search", "version": "1.21.1", "systems": { "aarch64-darwin": { - "store_path": "/nix/store/0xy4l28cjaji04jp2la3s5wzh0n4yb5y-go-1.21.1" + "store_path": "/nix/store/jkhg33806wygpwpix47d2h5scfgn01i8-go-1.21.1" }, "aarch64-linux": { - "store_path": "/nix/store/mji19qaxy6xd8vlk5j0jk83yslq0lqil-go-1.21.1" + "store_path": "/nix/store/sgkkfw6saficch0mviqyqyw6nj64kzf9-go-1.21.1" }, "x86_64-darwin": { - "store_path": "/nix/store/7rgm1xhrmf9ygdk0c1qcgjsraxhzjj3g-go-1.21.1" + "store_path": "/nix/store/w67nj5iqgnz0msi8i12kyh9nhsp2ci9n-go-1.21.1" }, "x86_64-linux": { - "store_path": "/nix/store/vnbz45plc7is6j5pk33dbcq14fbvb658-go-1.21.1" + "store_path": "/nix/store/jk0bqfsjijia52vks1wxqnn4s6dxaiqp-go-1.21.1" } } }, diff --git a/internal/impl/update.go b/internal/impl/update.go index eaa97990332..8a011f00b22 100644 --- a/internal/impl/update.go +++ b/internal/impl/update.go @@ -155,6 +155,9 @@ func (d *Devbox) mergeResolvedPackageToLockfile( } } if updated { + // if we are updating the system info, then we should also update the resolved path + lockfile.Packages[pkg.Raw].Resolved = resolved.Resolved + ux.Finfo(d.stderr, "Updated system information for %s\n", pkg) return nil } From c08fe1ecfb07c801a509dac5e3e49502a1a24e6c Mon Sep 17 00:00:00 2001 From: Savil Srivastava <676452+savil@users.noreply.github.com> Date: Wed, 4 Oct 2023 17:00:35 -0700 Subject: [PATCH 2/4] update all fields of package, when updating system-infos --- devbox.lock | 2 +- internal/impl/update.go | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/devbox.lock b/devbox.lock index 977dcf634c0..5fc15b1cba0 100644 --- a/devbox.lock +++ b/devbox.lock @@ -2,7 +2,7 @@ "lockfile_version": "1", "packages": { "go@latest": { - "last_modified": "2023-09-10T10:53:27Z", + "last_modified": "2023-09-15T06:49:28Z", "resolved": "github:NixOS/nixpkgs/46688f8eb5cd6f1298d873d4d2b9cf245e09e88e#go_1_21", "source": "devbox-search", "version": "1.21.1", diff --git a/internal/impl/update.go b/internal/impl/update.go index 8a011f00b22..137a2fe0259 100644 --- a/internal/impl/update.go +++ b/internal/impl/update.go @@ -121,8 +121,7 @@ func (d *Devbox) mergeResolvedPackageToLockfile( // sync the profile so we don't need to do this manually. ux.Fwarning(d.stderr, "Failed to remove %s from profile: %s\n", pkg, err) } - resolved.AllowInsecure = existing.AllowInsecure - lockfile.Packages[pkg.Raw] = resolved + useResolvedPackageInLockfile(lockfile, pkg, resolved, existing) return nil } @@ -133,30 +132,33 @@ func (d *Devbox) mergeResolvedPackageToLockfile( lockfile.Packages[pkg.Raw].Systems = map[string]*lock.SystemInfo{} } + newSystems := map[string]*lock.SystemInfo{} userSystem := nix.System() updated := false for sysName, newSysInfo := range resolved.Systems { + newSystems[sysName] = newSysInfo + + // Check whether we are actually updating any system info. if sysName == userSystem { // The resolved pkg has a system info for the user's system, so add/overwrite it. if !newSysInfo.Equals(existing.Systems[userSystem]) { // We only guard this so that the ux messaging is accurate. We could overwrite every time. - lockfile.Packages[pkg.Raw].Systems[userSystem] = newSysInfo updated = true } } else { // Add other system infos if they don't exist, or if we have a different StorePath. This may - // overwrite an existing CAPath, but to ensure correctness we should ensure that all StorePaths + // overwrite an existing StorePath, but to ensure correctness we should ensure that all StorePaths // come from the same package version. existingSysInfo, exists := existing.Systems[sysName] if !exists || existingSysInfo.StorePath != newSysInfo.StorePath { - lockfile.Packages[pkg.Raw].Systems[sysName] = newSysInfo updated = true } } } if updated { - // if we are updating the system info, then we should also update the resolved path - lockfile.Packages[pkg.Raw].Resolved = resolved.Resolved + // if we are updating the system info, then we should also update the other fields + useResolvedPackageInLockfile(lockfile, pkg, resolved, existing) + lockfile.Packages[pkg.Raw].Systems = newSystems ux.Finfo(d.stderr, "Updated system information for %s\n", pkg) return nil @@ -193,3 +195,13 @@ func (d *Devbox) attemptToUpgradeFlake(pkg *devpkg.Package) error { return nil } + +func useResolvedPackageInLockfile( + lockfile *lock.File, + pkg *devpkg.Package, + resolved *lock.Package, + existing *lock.Package, +) { + lockfile.Packages[pkg.Raw] = resolved + lockfile.Packages[pkg.Raw].AllowInsecure = existing.AllowInsecure +} From 4848303cdb153b9181beb18054af36f7bf1aa4d6 Mon Sep 17 00:00:00 2001 From: Savil Srivastava <676452+savil@users.noreply.github.com> Date: Wed, 4 Oct 2023 17:12:15 -0700 Subject: [PATCH 3/4] simplify --- internal/impl/update.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/impl/update.go b/internal/impl/update.go index 137a2fe0259..0fc43759ee3 100644 --- a/internal/impl/update.go +++ b/internal/impl/update.go @@ -132,11 +132,9 @@ func (d *Devbox) mergeResolvedPackageToLockfile( lockfile.Packages[pkg.Raw].Systems = map[string]*lock.SystemInfo{} } - newSystems := map[string]*lock.SystemInfo{} userSystem := nix.System() updated := false for sysName, newSysInfo := range resolved.Systems { - newSystems[sysName] = newSysInfo // Check whether we are actually updating any system info. if sysName == userSystem { @@ -158,7 +156,6 @@ func (d *Devbox) mergeResolvedPackageToLockfile( if updated { // if we are updating the system info, then we should also update the other fields useResolvedPackageInLockfile(lockfile, pkg, resolved, existing) - lockfile.Packages[pkg.Raw].Systems = newSystems ux.Finfo(d.stderr, "Updated system information for %s\n", pkg) return nil From 60ded144cb656944ef2579602b5217ac9ea6aa3d Mon Sep 17 00:00:00 2001 From: Savil Srivastava <676452+savil@users.noreply.github.com> Date: Wed, 4 Oct 2023 17:21:38 -0700 Subject: [PATCH 4/4] lint fix --- internal/impl/update.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/impl/update.go b/internal/impl/update.go index 0fc43759ee3..0bd9f38cae2 100644 --- a/internal/impl/update.go +++ b/internal/impl/update.go @@ -135,7 +135,6 @@ func (d *Devbox) mergeResolvedPackageToLockfile( userSystem := nix.System() updated := false for sysName, newSysInfo := range resolved.Systems { - // Check whether we are actually updating any system info. if sysName == userSystem { // The resolved pkg has a system info for the user's system, so add/overwrite it.