parseEnvAndExcludeSpecialCases converts env as []string to map[string]string In case of pure shell, it leaks HOME and it leaks PATH with some modifications
(currentEnv []string, pure bool)
| 1115 | // parseEnvAndExcludeSpecialCases converts env as []string to map[string]string |
| 1116 | // In case of pure shell, it leaks HOME and it leaks PATH with some modifications |
| 1117 | func (d *Devbox) parseEnvAndExcludeSpecialCases(currentEnv []string, pure bool) (map[string]string, error) { |
| 1118 | env := make(map[string]string, len(currentEnv)) |
| 1119 | for _, kv := range currentEnv { |
| 1120 | key, val, found := strings.Cut(kv, "=") |
| 1121 | if !found { |
| 1122 | return nil, errors.Errorf("expected \"=\" in keyval: %s", kv) |
| 1123 | } |
| 1124 | if ignoreCurrentEnvVar[key] { |
| 1125 | continue |
| 1126 | } |
| 1127 | // handling special cases for pure shell |
| 1128 | // - HOME required for devbox binary to work |
| 1129 | // - PATH to find the nix installation. It is cleaned for pure mode below. |
| 1130 | // - TERM to enable colored text in the pure shell |
| 1131 | if !pure || key == "HOME" || key == "PATH" || key == "TERM" { |
| 1132 | env[key] = val |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | // handling special case for PATH |
| 1137 | if pure { |
| 1138 | // Setting a custom env variable to differentiate pure and regular shell |
| 1139 | env["DEVBOX_PURE_SHELL"] = "1" |
| 1140 | // Finding nix executables in path and passing it through |
| 1141 | // As well as adding devbox itself to PATH |
| 1142 | // Both are needed for devbox commands inside pure shell to work |
| 1143 | nixPath, err := exec.LookPath("nix") |
| 1144 | if err != nil { |
| 1145 | return nil, errors.New("could not find any nix executable in PATH. Make sure Nix is installed and in PATH, then try again") |
| 1146 | } |
| 1147 | nixPath = filepath.Dir(nixPath) |
| 1148 | env["PATH"] = envpath.JoinPathLists(nixPath, dotdevboxBinPath(d)) |
| 1149 | } |
| 1150 | return env, nil |
| 1151 | } |
| 1152 | |
| 1153 | func (d *Devbox) PluginManager() *plugin.Manager { |
| 1154 | return d.pluginManager |
no test coverage detected