Skip to content

Commit 3c9691b

Browse files
committed
devbox add fallthrough and fallback for packages not handled by search
1 parent 14ab456 commit 3c9691b

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

internal/impl/packages.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ func (d *Devbox) Add(ctx context.Context, pkgsNames ...string) error {
4242
// replace it.
4343
pkgs := []*devpkg.Package{}
4444
for _, pkg := range devpkg.PackageFromStrings(lo.Uniq(pkgsNames), d.lockfile) {
45-
versioned := pkg.Versioned()
46-
4745
// If exact versioned package is already in the config, skip.
48-
if slices.Contains(d.cfg.Packages, versioned) {
46+
if slices.Contains(d.cfg.Packages, pkg.Versioned()) {
4947
continue
5048
}
5149

@@ -59,18 +57,15 @@ func (d *Devbox) Add(ctx context.Context, pkgsNames ...string) error {
5957
}
6058
}
6159

62-
pkgs = append(pkgs, devpkg.PackageFromString(versioned, d.lockfile))
63-
d.cfg.Packages = append(d.cfg.Packages, versioned)
64-
}
65-
66-
// Check packages are valid before adding.
67-
for _, pkg := range pkgs {
68-
ok, err := pkg.ValidateExists()
69-
if err != nil {
70-
return err
71-
}
72-
if !ok {
73-
return errors.Wrap(nix.ErrPackageNotFound, pkg.Raw)
60+
// validate that the versioned package exists in the search endpoint.
61+
// if not, fallback to legacy vanilla nix.
62+
versionedPkg := devpkg.PackageFromString(pkg.Versioned(), d.lockfile)
63+
ok, err := versionedPkg.ValidateExists()
64+
if err == nil && ok {
65+
d.cfg.Packages = append(d.cfg.Packages, pkg.Versioned())
66+
} else {
67+
// fallthrough and treat package as a legacy package.
68+
d.cfg.Packages = append(d.cfg.Packages, pkg.Raw)
7469
}
7570
}
7671

0 commit comments

Comments
 (0)