Skip to content

Commit d120b4d

Browse files
authored
[info] Ensure devbox info works with versioned packages (#997)
## Summary `devbox info php@8` now works correctly ## How was it tested? ```bash devbox info php devbox info php@8 devbox info php@latest ```
1 parent 2350684 commit d120b4d

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

internal/impl/devbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func (d *Devbox) ShellEnvHash(ctx context.Context) (string, error) {
317317
}
318318

319319
func (d *Devbox) Info(pkg string, markdown bool) error {
320-
info := nix.PkgInfo(d.cfg.Nixpkgs.Commit, pkg)
320+
info := nix.PkgInfo(pkg, d.lockfile)
321321
if info == nil {
322322
_, err := fmt.Fprintf(d.writer, "Package %s not found\n", pkg)
323323
return errors.WithStack(err)

internal/impl/global.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (d *Devbox) RemoveGlobal(pkgs ...string) error {
9292
return err
9393
}
9494
for _, pkg := range lo.Intersect(d.cfg.Packages, pkgs) {
95-
if err := nix.ProfileRemove(profilePath, plansdk.DefaultNixpkgsCommit, pkg); err != nil {
95+
if err := nix.ProfileRemove(profilePath, pkg, d.lockfile); err != nil {
9696
if errors.Is(err, nix.ErrPackageNotInstalled) {
9797
removed = append(removed, pkg)
9898
} else {

internal/nix/profile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ func ProfileInstall(args *ProfileInstallArgs) error {
255255
return nil
256256
}
257257

258-
func ProfileRemove(profilePath, nixpkgsCommit, pkg string) error {
259-
info := PkgInfo(nixpkgsCommit, pkg)
258+
func ProfileRemove(profilePath, pkg string, lock lock.Locker) error {
259+
info := PkgInfo(pkg, lock)
260260
if info == nil {
261261
return ErrPackageNotFound
262262
}

internal/nix/search.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ func (i *Info) String() string {
3131
return fmt.Sprintf("%s-%s", i.PName, i.Version)
3232
}
3333

34-
func PkgInfo(nixpkgsCommit, pkg string) *Info {
35-
exactPackage := fmt.Sprintf("%s#%s", FlakeNixpkgs(nixpkgsCommit), pkg)
36-
if nixpkgsCommit == "" {
37-
exactPackage = fmt.Sprintf("nixpkgs#%s", pkg)
34+
func PkgInfo(pkg string, lock lock.Locker) *Info {
35+
locked, err := lock.Resolve(pkg)
36+
if err != nil {
37+
return nil
3838
}
3939

40-
results := search(exactPackage)
40+
results := search(locked.Resolved)
4141
if len(results) == 0 {
4242
return nil
4343
}

testscripts/info/info.test.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ exec devbox init
22
exec devbox info hello
33
stdout hello-.
44

5+
exec devbox init
6+
exec devbox info hello@latest
7+
stdout hello-.
8+
59
exec devbox init
610
exec devbox info notapackage
711
stdout 'Package notapackage not found'

0 commit comments

Comments
 (0)