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

Method execPrintDevEnv

internal/devbox/devbox.go:623–676  ·  view source on GitHub ↗
(ctx context.Context, usePrintDevEnvCache bool)

Source from the content-addressed store, hash-verified

621}
622
623func (d *Devbox) execPrintDevEnv(ctx context.Context, usePrintDevEnvCache bool) (map[string]string, error) {
624 var spinny *spinner.Spinner
625 if !usePrintDevEnvCache {
626 spinny = spinner.New(spinner.CharSets[11], 100*time.Millisecond, spinner.WithWriter(d.stderr))
627 spinny.FinalMSG = "✓ Computed the Devbox environment.\n"
628 spinny.Suffix = " Computing the Devbox environment...\n"
629 spinny.Start()
630 }
631
632 vaf, err := d.nix.PrintDevEnv(ctx, &nix.PrintDevEnvArgs{
633 FlakeDir: d.flakeDir(),
634 PrintDevEnvCachePath: d.nixPrintDevEnvCachePath(),
635 UsePrintDevEnvCache: usePrintDevEnvCache,
636 })
637 if spinny != nil {
638 spinny.Stop()
639 }
640 if err != nil {
641 return nil, err
642 }
643
644 // Add environment variables from "nix print-dev-env" except for a few
645 // special ones we need to ignore.
646 env := map[string]string{}
647 for key, val := range vaf.Variables {
648 // We only care about "exported" because the var and array types seem to only be used by nix-defined
649 // functions that we don't need (like genericBuild). For reference, each type translates to bash as follows:
650 // var: export VAR=VAL
651 // exported: export VAR=VAL
652 // array: declare -a VAR=('VAL1' 'VAL2' )
653 if val.Type != "exported" {
654 continue
655 }
656
657 // SSL_CERT_FILE is a special-case. We only ignore it if it's
658 // set to a specific value. This emulates the behavior of
659 // "nix develop".
660 if key == "SSL_CERT_FILE" && val.Value.(string) == "/no-cert-file.crt" {
661 continue
662 }
663
664 // Certain variables get set to invalid values after Nix builds
665 // the shell environment. For example, HOME=/homeless-shelter
666 // and TMPDIR points to a missing directory. We want to ignore
667 // those values and just use the values from the current
668 // environment instead.
669 if ignoreDevEnvVar[key] {
670 continue
671 }
672
673 env[key] = val.Value.(string)
674 }
675 return env, nil
676}
677
678// computeEnv computes the set of environment variables that define a Devbox
679// environment. The "devbox run" and "devbox shell" commands source these

Callers 2

computeEnvMethod · 0.95

Calls 3

flakeDirMethod · 0.95
PrintDevEnvMethod · 0.65

Tested by

no test coverage detected