Skip to content

Commit 7535691

Browse files
authored
[perf] Make PkgInfo faster by using non-flakes lookup (#553)
## Summary Use legacy search for now to make `info` and `add` much faster. (first add is about 20 seconds faster) ## How was it tested? ``` devbox info php devbox add curl ```
1 parent 156fdb7 commit 7535691

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

internal/nix/nix.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import (
1111
"strings"
1212

1313
"github.com/pkg/errors"
14+
"go.jetpack.io/devbox/internal/boxcli/featureflag"
1415
"go.jetpack.io/devbox/internal/boxcli/usererr"
1516
"go.jetpack.io/devbox/internal/debug"
17+
"go.jetpack.io/devbox/internal/planner/plansdk"
1618
)
1719

1820
// ProfilePath contains the contents of the profile generated via `nix-env --profile ProfilePath <command>`
@@ -47,6 +49,22 @@ func Exec(path string, command []string, env []string) error {
4749
}
4850

4951
func PkgInfo(nixpkgsCommit, pkg string) (*Info, bool) {
52+
if featureflag.Flakes.Enabled() {
53+
return flakesPkgInfo(nixpkgsCommit, pkg)
54+
}
55+
return legacyPkgInfo(nixpkgsCommit, pkg)
56+
}
57+
58+
func legacyPkgInfo(nixpkgsCommit, pkg string) (*Info, bool) {
59+
info, err := plansdk.GetNixpkgsInfo(nixpkgsCommit)
60+
if err != nil {
61+
return nil, false
62+
}
63+
cmd := exec.Command("nix-env", "-qa", "-A", pkg, "-f", info.URL, "--json")
64+
return pkgInfo(cmd, pkg)
65+
}
66+
67+
func flakesPkgInfo(nixpkgsCommit, pkg string) (*Info, bool) {
5068
exactPackage := fmt.Sprintf("nixpkgs/%s#%s", nixpkgsCommit, pkg)
5169
if nixpkgsCommit == "" {
5270
exactPackage = fmt.Sprintf("nixpkgs#%s", pkg)
@@ -55,6 +73,10 @@ func PkgInfo(nixpkgsCommit, pkg string) (*Info, bool) {
5573
cmd := exec.Command("nix", "search",
5674
"--extra-experimental-features", "nix-command flakes",
5775
"--json", exactPackage)
76+
return pkgInfo(cmd, pkg)
77+
}
78+
79+
func pkgInfo(cmd *exec.Cmd, pkg string) (*Info, bool) {
5880
cmd.Env = DefaultEnv()
5981
cmd.Stderr = os.Stderr
6082
debug.Log("running command: %s\n", cmd)

0 commit comments

Comments
 (0)