(raw string, isInstallable func() bool, locker lock.Locker)
| 133 | } |
| 134 | |
| 135 | func newPackage(raw string, isInstallable func() bool, locker lock.Locker) *Package { |
| 136 | pkg := &Package{ |
| 137 | Raw: raw, |
| 138 | lockfile: locker, |
| 139 | isInstallable: sync.OnceValue(isInstallable), |
| 140 | } |
| 141 | |
| 142 | // The raw string is either a Devbox package ("name" or "name@version") |
| 143 | // or it's a flake installable. In some cases they're ambiguous |
| 144 | // ("nixpkgs" is a devbox package and a flake). When that happens, we |
| 145 | // assume a Devbox package. |
| 146 | parsed, err := flake.ParseInstallable(raw) |
| 147 | if err != nil || pkgtype.IsAmbiguous(raw, parsed) { |
| 148 | // TODO: This sets runx packages as devbox packages. Not sure if that's what we want. |
| 149 | pkg.IsDevboxPackage = true |
| 150 | pkg.resolve = sync.OnceValue(func() error { return resolve(pkg) }) |
| 151 | return pkg |
| 152 | } |
| 153 | |
| 154 | pkg.resolve = sync.OnceValue(func() error { |
| 155 | // Don't lock flakes that are local paths. |
| 156 | if parsed.Ref.Type == flake.TypePath { |
| 157 | return nil |
| 158 | } |
| 159 | return resolve(pkg) |
| 160 | }) |
| 161 | pkg.setInstallable(parsed, locker.ProjectDir()) |
| 162 | pkg.outputs = outputs{selectedNames: strings.Split(parsed.Outputs, ",")} |
| 163 | pkg.Patch = pkgNeedsPatch(pkg.CanonicalName(), configfile.PatchAuto) |
| 164 | return pkg |
| 165 | } |
| 166 | |
| 167 | // resolve is the implementation of Package.resolve, where it is wrapped in a |
| 168 | // sync.OnceValue function. It should not be called directly. |
no test coverage detected