Skip to content

Commit 39e3a24

Browse files
committed
Add source field in lock file and handle devbox update command
1 parent 3c9691b commit 39e3a24

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

internal/devpkg/package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func (p *Package) Versioned() string {
403403
}
404404

405405
func (p *Package) IsLegacy() bool {
406-
return p.isDevboxPackage() && !p.isVersioned()
406+
return p.isDevboxPackage() && !p.isVersioned() && p.lockfile.Source(p.Raw) == ""
407407
}
408408

409409
func (p *Package) LegacyToVersioned() string {

internal/impl/update.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ func (d *Devbox) Update(ctx context.Context, pkgs ...string) error {
3131
if err := d.Remove(ctx, pkg.Raw); err != nil {
3232
return err
3333
}
34-
if err := d.lockfile.ResolveToCurrentNixpkgCommitHash(
35-
pkg.LegacyToVersioned(),
36-
); err != nil {
37-
return err
38-
}
39-
if err := d.Add(ctx, pkg.LegacyToVersioned()); err != nil {
34+
// Calling Add function with the original package names, since
35+
// Add will automatically append @latest if search is able to handle that.
36+
// If not, it will fallback to the nixpkg format.
37+
if err := d.Add(ctx, pkg.Raw); err != nil {
4038
return err
4139
}
4240
} else {

internal/lock/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ type Locker interface {
1414
LegacyNixpkgsPath(string) string
1515
ProjectDir() string
1616
Resolve(string) (*Package, error)
17+
Source(string) string
1718
}

internal/lock/lockfile.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import (
1717
)
1818

1919
const lockFileVersion = "1"
20+
const (
21+
NixpkgSource string = "nixpkg"
22+
DevboxSearchSource = "devbox-search"
23+
)
2024

2125
// Lightly inspired by package-lock.json
2226
type File struct {
@@ -32,6 +36,7 @@ type Package struct {
3236
LastModified string `json:"last_modified,omitempty"`
3337
PluginVersion string `json:"plugin_version,omitempty"`
3438
Resolved string `json:"resolved,omitempty"`
39+
Source string `json:"source,omitempty"`
3540
Version string `json:"version,omitempty"`
3641
// Systems is keyed by the system name
3742
Systems map[string]*SystemInfo `json:"systems,omitempty"`
@@ -97,7 +102,10 @@ func (l *File) Resolve(pkg string) (*Package, error) {
97102
} else if IsLegacyPackage(pkg) {
98103
// These are legacy packages without a version. Resolve to nixpkgs with
99104
// whatever hash is in the devbox.json
100-
locked = &Package{Resolved: l.LegacyNixpkgsPath(pkg)}
105+
locked = &Package{
106+
Resolved: l.LegacyNixpkgsPath(pkg),
107+
Source: NixpkgSource,
108+
}
101109
}
102110
l.Packages[pkg] = locked
103111
}
@@ -117,7 +125,10 @@ func (l *File) ResolveToCurrentNixpkgCommitHash(pkg string) error {
117125
"only allowed version is @latest. Otherwise we can't guarantee the " +
118126
"version will resolve")
119127
}
120-
l.Packages[pkg] = &Package{Resolved: l.LegacyNixpkgsPath(name)}
128+
l.Packages[pkg] = &Package{
129+
Resolved: l.LegacyNixpkgsPath(name),
130+
Source: NixpkgSource,
131+
}
121132
return nil
122133
}
123134

@@ -133,6 +144,14 @@ func (l *File) LegacyNixpkgsPath(pkg string) string {
133144
)
134145
}
135146

147+
func (l *File) Source(pkg string) string {
148+
entry, hasEntry := l.Packages[pkg]
149+
if !hasEntry || entry.Resolved == "" {
150+
return ""
151+
}
152+
return entry.Source
153+
}
154+
136155
// This probably belongs in input.go but can't add it there because it will
137156
// create a circular dependency. We could move Input into own package.
138157
func IsLegacyPackage(pkg string) bool {

internal/lock/resolve.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func (l *File) FetchResolvedPackage(pkg string) (*Package, error) {
5757
packageInfo.AttrPaths[0],
5858
),
5959
Version: packageInfo.Version,
60+
Source: DevboxSearchSource,
6061
Systems: sysInfos,
6162
}, nil
6263
}

0 commit comments

Comments
 (0)