(ctx context.Context, name, version string)
| 100 | } |
| 101 | |
| 102 | func resolveV2(ctx context.Context, name, version string) (*Package, error) { |
| 103 | resolved, err := searcher.Client().ResolveV2(ctx, name, version) |
| 104 | if errors.Is(err, searcher.ErrNotFound) { |
| 105 | return nil, redact.Errorf("%s@%s: %w", name, version, nix.ErrPackageNotFound) |
| 106 | } |
| 107 | if err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | |
| 111 | // /v2/resolve never returns a success with no systems. |
| 112 | sysPkg, _ := selectForSystem(resolved.Systems) |
| 113 | pkg := &Package{ |
| 114 | LastModified: sysPkg.LastUpdated.Format(time.RFC3339), |
| 115 | Resolved: sysPkg.FlakeInstallable.String(), |
| 116 | Source: devboxSearchSource, |
| 117 | Version: resolved.Version, |
| 118 | Systems: make(map[string]*SystemInfo, len(resolved.Systems)), |
| 119 | } |
| 120 | for sys, info := range resolved.Systems { |
| 121 | if len(info.Outputs) != 0 { |
| 122 | outputs := make([]Output, len(info.Outputs)) |
| 123 | for i, out := range info.Outputs { |
| 124 | outputs[i] = Output{ |
| 125 | Name: out.Name, |
| 126 | Path: out.Path, |
| 127 | Default: out.Default, |
| 128 | } |
| 129 | } |
| 130 | storePath := "" |
| 131 | if len(outputs) > 0 { |
| 132 | // We pick the first output as the store path. Note, this is sub-optimal because |
| 133 | // it may not include all the default outputs of the nix package, but is what older |
| 134 | // Devbox used to do. And this code is for backwards-compatibility. |
| 135 | // |
| 136 | // Unlike /v2/resolve, the /v1/resolve endpoint does not return the store path. It |
| 137 | // returns the commit hash and we run `nix store path-from-hash-part` to get the store path. |
| 138 | // For some packages, this would return the store path of the first default output. |
| 139 | // |
| 140 | // For example, curl has default outputs `bin` and `man`. Previously, we would only install |
| 141 | // the `bin` output as `v1/resolve`'s commit hash would match that. With /v2/resolve, we |
| 142 | // install both outputs. So, team members on older Devbox will see just `bin` installed while |
| 143 | // team members on newer Devbox will see both `bin` and `man` installed. |
| 144 | storePath = outputs[0].Path |
| 145 | } |
| 146 | pkg.Systems[sys] = &SystemInfo{ |
| 147 | Outputs: outputs, |
| 148 | StorePath: storePath, |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | return pkg, nil |
| 153 | } |
| 154 | |
| 155 | func selectForSystem[V any](systems map[string]V) (v V, err error) { |
| 156 | if v, ok := systems[nix.System()]; ok { |
no test coverage detected