ensureStateIsUpToDateAndComputeEnv will return a map of the env-vars for the Devbox Environment while ensuring these reflect the current (up to date) state of the project.
( ctx context.Context, envOpts devopt.EnvOptions, )
| 835 | // ensureStateIsUpToDateAndComputeEnv will return a map of the env-vars for the Devbox Environment |
| 836 | // while ensuring these reflect the current (up to date) state of the project. |
| 837 | func (d *Devbox) ensureStateIsUpToDateAndComputeEnv( |
| 838 | ctx context.Context, |
| 839 | envOpts devopt.EnvOptions, |
| 840 | ) (map[string]string, error) { |
| 841 | defer debug.FunctionTimer().End() |
| 842 | |
| 843 | upToDate, err := d.lockfile.IsUpToDateAndInstalled(isFishShell()) |
| 844 | if err != nil { |
| 845 | return nil, err |
| 846 | } |
| 847 | if !upToDate { |
| 848 | if envOpts.Hooks.OnStaleState != nil { |
| 849 | envOpts.Hooks.OnStaleState() |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | if !envOpts.SkipRecompute { |
| 854 | // When ensureStateIsUpToDate is called with ensure=true, it always |
| 855 | // returns early if the lockfile is up to date. So we don't need to check here |
| 856 | if err := d.ensureStateIsUpToDate(ctx, ensure); isConnectionError(err) { |
| 857 | if !fileutil.Exists(d.nixPrintDevEnvCachePath()) { |
| 858 | ux.Ferrorf( |
| 859 | d.stderr, |
| 860 | "Error connecting to the internet and no cached environment found. Aborting.\n", |
| 861 | ) |
| 862 | return nil, err |
| 863 | } |
| 864 | ux.Fwarningf( |
| 865 | d.stderr, |
| 866 | "Error connecting to the internet. Will attempt to use cached environment.\n", |
| 867 | ) |
| 868 | } else if err != nil { |
| 869 | // Some other non connection error, just return it. |
| 870 | return nil, err |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | // Since ensureStateIsUpToDate calls computeEnv when not up do date, |
| 875 | // it's ok to use usePrintDevEnvCache=true here always. This does end up |
| 876 | // doing some non-nix work twice if lockfile is not up to date. |
| 877 | // TODO: Improve this to avoid extra work. |
| 878 | return d.computeEnv(ctx, true /*usePrintDevEnvCache*/, envOpts) |
| 879 | } |
| 880 | |
| 881 | func (d *Devbox) nixPrintDevEnvCachePath() string { |
| 882 | return filepath.Join(d.projectDir, ".devbox/.nix-print-dev-env-cache") |
no test coverage detected