MCPcopy Index your code
hub / github.com/jetify-com/devbox / installNixPackagesToStore

Method installNixPackagesToStore

internal/devbox/packages.go:516–577  ·  view source on GitHub ↗

installNixPackagesToStore will install all the packages in the nix store, if mode is install or update, and we're not in a devbox environment. This is done by running `nix build` on the flake. We do this so that the packages will be available in the nix store when computing the devbox environment an

(ctx context.Context, mode installMode)

Source from the content-addressed store, hash-verified

514// packages will be available in the nix store when computing the devbox environment
515// and installing in the nix profile (even if offline).
516func (d *Devbox) installNixPackagesToStore(ctx context.Context, mode installMode) error {
517 defer debug.FunctionTimer().End()
518 packages, err := d.packagesToInstallInStore(ctx, mode)
519 if err != nil || len(packages) == 0 {
520 return err
521 }
522
523 // --no-link to avoid generating the result objects
524 flags := []string{"--no-link"}
525 if mode == update {
526 flags = append(flags, "--refresh")
527 }
528
529 args := &nix.BuildArgs{
530 Flags: flags,
531 Writer: d.stderr,
532 }
533 err = d.appendExtraSubstituters(ctx, args)
534 if err != nil {
535 return err
536 }
537
538 packageNames := lo.Map(
539 packages,
540 func(p *devpkg.Package, _ int) string { return p.Raw },
541 )
542 ux.Finfof(
543 d.stderr,
544 "Installing the following packages to the nix store: %s\n",
545 strings.Join(packageNames, ", "),
546 )
547
548 installables := map[bool][]string{false: {}, true: {}}
549 for _, pkg := range packages {
550 pkgInstallables, err := pkg.Installables()
551 if err != nil {
552 return err
553 }
554 installables[pkg.HasAllowInsecure()] = append(
555 installables[pkg.HasAllowInsecure()],
556 pkgInstallables...,
557 )
558 }
559
560 for allowInsecure, installables := range installables {
561 if len(installables) == 0 {
562 continue
563 }
564 eventStart := time.Now()
565 args.AllowInsecure = allowInsecure
566 err = nix.Build(ctx, args, installables...)
567 if err != nil {
568 return err
569 }
570 telemetry.Event(telemetry.EventNixBuildSuccess, telemetry.Metadata{
571 EventStart: eventStart,
572 Packages: packageNames,
573 })

Callers 2

installPackagesMethod · 0.95
handleInstallFailureMethod · 0.95

Calls 9

FunctionTimerFunction · 0.92
FinfofFunction · 0.92
BuildFunction · 0.92
EventFunction · 0.92
EndMethod · 0.80
InstallablesMethod · 0.80
HasAllowInsecureMethod · 0.80

Tested by

no test coverage detected