MCPcopy
hub / github.com/jetify-com/devbox / packagesToInstallInStore

Method packagesToInstallInStore

internal/devbox/packages.go:627–667  ·  view source on GitHub ↗
(ctx context.Context, mode installMode)

Source from the content-addressed store, hash-verified

625}
626
627func (d *Devbox) packagesToInstallInStore(ctx context.Context, mode installMode) ([]*devpkg.Package, error) {
628 defer debug.FunctionTimer().End()
629 // First, get and prepare all the packages that must be installed in this project
630 // and remove non-nix packages from the list
631 packages := lo.Filter(d.InstallablePackages(), devpkg.IsNix)
632 if err := devpkg.FillNarInfoCache(ctx, packages...); err != nil {
633 return nil, err
634 }
635
636 // Second, check which packages are not in the nix store
637 packagesToInstall := []*devpkg.Package{}
638 storePathsForPackage := map[*devpkg.Package][]string{}
639 for _, pkg := range packages {
640 if mode == update && d.isBeingUpdated(pkg) {
641 packagesToInstall = append(packagesToInstall, pkg)
642 continue
643 }
644 var err error
645 storePathsForPackage[pkg], err = pkg.GetStorePaths(ctx, d.stderr)
646 if err != nil {
647 return nil, err
648 }
649 }
650
651 // Batch this for perf
652 storePathMap, err := nix.StorePathsAreInStore(ctx, lo.Flatten(lo.Values(storePathsForPackage)))
653 if err != nil {
654 return nil, err
655 }
656
657 for pkg, storePaths := range storePathsForPackage {
658 for _, storePath := range storePaths {
659 if !storePathMap[storePath] {
660 packagesToInstall = append(packagesToInstall, pkg)
661 break
662 }
663 }
664 }
665
666 return lo.Uniq(packagesToInstall), nil
667}
668
669func (d *Devbox) isBeingUpdated(pkg *devpkg.Package) bool {
670 for _, u := range d.packagesBeingUpdated {

Callers 1

Calls 7

InstallablePackagesMethod · 0.95
isBeingUpdatedMethod · 0.95
FunctionTimerFunction · 0.92
FillNarInfoCacheFunction · 0.92
StorePathsAreInStoreFunction · 0.92
EndMethod · 0.80
GetStorePathsMethod · 0.80

Tested by

no test coverage detected