MCPcopy Create free account
hub / github.com/jetify-com/devbox / appendExtraSubstituters

Method appendExtraSubstituters

internal/devbox/packages.go:579–625  ·  view source on GitHub ↗
(ctx context.Context, args *nix.BuildArgs)

Source from the content-addressed store, hash-verified

577}
578
579func (d *Devbox) appendExtraSubstituters(ctx context.Context, args *nix.BuildArgs) error {
580 creds, err := nixcache.CachedCredentials(ctx)
581 if errors.Is(err, auth.ErrNotLoggedIn) {
582 return nil
583 }
584 if err != nil {
585 ux.Fwarningf(d.stderr, "Devbox was unable to authenticate with the Jetify Nix cache. Some packages might be built from source.\n")
586 return nil //nolint:nilerr
587 }
588
589 caches, err := nixcache.CachedReadCaches(ctx)
590 if err != nil {
591 slog.Error("error getting list of caches from the Jetify API, assuming the user doesn't have access to any", "err", err)
592 return nil
593 }
594 if len(caches) == 0 {
595 return nil
596 }
597
598 err = nixcache.Configure(ctx)
599 if errors.Is(err, setup.ErrAlreadyRefused) {
600 slog.Debug("user previously refused to configure nix cache, not re-prompting")
601 return nil
602 }
603 if errors.Is(err, setup.ErrUserRefused) {
604 ux.Finfof(d.stderr, "Skipping cache setup. Run `devbox cache configure` to enable the cache at a later time.\n")
605 return nil
606 }
607 var daemonErr *nix.DaemonError
608 if errors.As(err, &daemonErr) {
609 // Error here to give the user a chance to restart the daemon.
610 return usererr.New("Devbox configured Nix to use a new cache. Please restart the Nix daemon and re-run Devbox.")
611 }
612 // Other errors indicate we couldn't update nix.conf, so just warn and
613 // continue by building from source if necessary.
614 if err != nil {
615 slog.Error("error configuring nix cache", "err", err)
616 ux.Fwarningf(d.stderr, "Devbox was unable to configure Nix to use the Jetify Nix cache. Some packages might be built from source.\n")
617 return nil
618 }
619
620 for _, cache := range caches {
621 args.ExtraSubstituters = append(args.ExtraSubstituters, cache.GetUri())
622 }
623 args.Env = append(args.Env, creds.Env()...)
624 return nil
625}
626
627func (d *Devbox) packagesToInstallInStore(ctx context.Context, mode installMode) ([]*devpkg.Package, error) {
628 defer debug.FunctionTimer().End()

Callers 1

Calls 9

CachedCredentialsFunction · 0.92
FwarningfFunction · 0.92
CachedReadCachesFunction · 0.92
ConfigureFunction · 0.92
FinfofFunction · 0.92
NewFunction · 0.92
IsMethod · 0.80
EnvMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected