Repository: mamba-org/mamba (C++)

Issue:
mamba info does not show correct/ all `env location`
### Troubleshooting docs

- [X] My problem is not solved in the Troubleshooting docs

### Anaconda default channels

- [X] I do NOT use the Anaconda default channels (pkgs/* etc.)

### How did you install Mamba?

Mambaforge or latest Miniforge

### Search tried in issue tracker

yes but `mamba info` is in all issues :shrug:

### Latest version of Mamba

- [X] My problem is not solved with the latest version

### Tried in Conda?

I do not have this problem with Conda, just with Mamba

### Describe your issue

`mamba info` shows the `env location` from the `MAMBA_ROOT_PREFIX` but not what is given in `.condarc`. It still installs to the one indicated in `.condarc`. It also does not show `env location` indicated by `CONDA_ENVS_PATH` (so somewhat related to #3654, but I'd argue this warrants a second issue). So I think mamba info should be changed to

```diff
+           env location : /home/mathause/.conda/envs
+                          /home/mathause/.mambabase
-           env location : /home/mathause/.mambabase
```

conda info shows it:

<details>

```
conda info

     active environment : base
    active env location : /home/mathause/.mambabase
            shell level : 1
       user config file : /home/mathause/.condarc
 populated config files : /home/mathause/.mambabase/.condarc
                          /home/mathause/.condarc
          conda version : 24.11.0
    conda-build version : not installed
         python version : 3.12.7.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=skylake
                          __conda=24.11.0=0
                          __glibc=2.35=0
                          __linux=6.8.0=0
                          __unix=0=0
       base environment : /home/mathause/.mambabase  (writable)
      conda av data dir : /home/mathause/.mambabase/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /home/mathause/.conda/pkgs
       envs directories : /home/mathause/.conda/envs
                          /home/mathause/.mambabase/envs
               platform : linux-64
             user-agent : conda/24.11.0 requests/2.32.3 CPython/3.12.7 Linux/6.8.0-49-generic linuxmint/21.3 glibc/2.35 solver/libmamba conda-libmamba-solver/24.11.0 libmambapy/2.0.4
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False

```
</details>











### mamba info / micromamba info

```shell
libmamba version : 2.0.4
          mamba version : 2.0.4
           curl version : libcurl/8.10.1 OpenSSL/3.4.0 zlib/1.3.1 zstd/1.5.6 libssh2/1.11.1 nghttp2/1.64.0
     libarchive version : libarchive 3.7.7 zlib/1.3.1 liblzma/5.2.6 bz2lib/1.0.8 liblz4/1.9.3 libzstd/1.5.6
       envs directories : /home/mathause/.conda/envs
          package cache : /home/mathause/.conda/pkgs
            environment : base (active)
           env location : /home/mathause/.mambabase
      user config files : /home/mathause/.mambarc
 populated config files : /home/mathause/.condarc
                          /home/mathause/.mambabase/.condarc
       virtual packages : __unix=0=0
                          __linux=6.8.0=0
                          __glibc=2.35=0
                          __archspec=1=x86_64_v3
               channels : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
       base environment : /home/mathause/.mambabase
               platform : linux-64
```


### Logs

```shell
not applicable
```


### environment.yml

```yaml
not applicable
```


### ~/.condarc

```yaml
channels:
  - conda-forge

envs_dirs:
  - /home/mathause/.conda/envs

pkgs_dirs:
  - /home/mathause/.conda/pkgs
```



Discussion: Both `conda` and `mamba` show the `env location` as `/home/mathause/.mambabase` which is the active environment location.
I don't see why there's an issue here?
Maybe I misunderstood the intention of `env location`. However, `conda info` has a `envs directories` listing which can be more than one directory - if you have environments in more than one folder (e.g. stratified by year or whatever).



Fix (patch):
diff --git a/libmamba/src/api/configuration.cpp b/libmamba/src/api/configuration.cpp
index 946992aaf6..1514c7f5c1 100644
--- a/libmamba/src/api/configuration.cpp
+++ b/libmamba/src/api/configuration.cpp
@@ -965,13 +965,17 @@ namespace mamba
             }
         }
 
-        std::vector<fs::u8path> fallback_envs_dirs_hook(const Context& context)
+        void envs_dirs_hook(const Context& context, std::vector<fs::u8path>& dirs)
         {
-            return { context.prefix_params.root_prefix / "envs" };
-        }
+            // Check that "root_prefix/envs" is already in the dirs,
+            // and append if not - to match `conda`
+            fs::u8path default_env_dir = context.prefix_params.root_prefix / "envs";
+            if (std::find(dirs.begin(), dirs.end(), default_env_dir) == dirs.end())
+            {
+                dirs.push_back(default_env_dir);
+            }
 
-        void envs_dirs_hook(std::vector<fs::u8path>& dirs)
-        {
+            // Check that the values exist as directories
             for (auto& d : dirs)
             {
                 d = fs::weakly_canonical(util::expand_home(d.string())).string();
@@ -1297,10 +1301,10 @@ namespace mamba
                    .set_rc_configurable(RCConfigLevel::kHomeDir)
                    .set_env_var_names({ "CONDA_ENVS_DIRS" })
                    .needs({ "root_prefix" })
-                   .set_fallback_value_hook<decltype(m_context.envs_dirs)>(
-                       [this] { return detail::fallback_envs_dirs_hook(m_context); }
+                   .set_post_merge_hook<decltype(m_context.envs_dirs)>(
+                       [this](decltype(m_context.envs_dirs)& value)
+                       { return detail::envs_dirs_hook(m_context, value); }
                    )
-                   .set_post_merge_hook(detail::envs_dirs_hook)
                    .description("Possible locations of named environments"));
 
         insert(Configurable("pkgs_dirs", &m_context.pkgs_dirs)
diff --git a/micromamba/src/common_options.hpp b/micromamba/src/common_options.hpp
index 40c4a3f4f2..1449d2da6d 100644
--- a/micromamba/src/common_options.hpp
+++ b/micromamba/src/common_options.hpp
@@ -40,9 +40,6 @@ init_channel_parser(CLI::App* subcom, mamba::Configuration& config);
 void
 load_channel_options(mamba::Context& ctx);
 
-void
-channels_hook(std::vector<std::string>& channels);
-
 void
 override_channels_hook(mamba::Configuration& config, bool& override_channels);