Repository: conda/conda

Issue:
conda is broken if your home directory is read-only
Conda currently requires the user's home directory to be writable.

If the directory conda is installed into is writable (say a tmpfs) then you can get along way by using 
```shell
		./Miniconda3-latest-Linux-x86_64.sh -p $CONDA_DIR -b -f
		conda config --system --set always_yes yes
		conda config --system --set changeps1 no
		conda config --system --add envs_dirs $CONDA_DIR/envs
		conda config --system --add pkgs_dirs $CONDA_DIR/pkgs
```

However, this is foiled by the following line -> https://github.com/conda/conda/blob/7616b87ad87b80da16b8263011c9c708be98147c/conda/core/envs_manager.py#L18

```python
USER_ENVIRONMENTS_TXT_FILE = expand(join('~', '.conda', 'environments.txt'))
```

I'm not sure if this would even work on Windows?



Discussion:
Could we have an environment variable to override where conda stores any user files?
The environment variables you want are `CONDA_PKGS_DIRS` and `CONDA_ENVS_DIRS`.  Look at the output of `conda config --describe`.  Any configuration parameter is also accessible as an environment variable by prepending `CONDA_` and making the key all-caps.  Since those two config parameters are sequences, there's a string delimiter that probably depends on platform.  `conda config --describe` should tell you what you need to know.
Ohhhhhh.  I see the problem now.
I'm waffling back-and-forth on whether we should just swallow `EACCES` when we try to write to that file.  I'm not sure we want to make its location configurable.  The reason is that, especially on unix, when you're UID `0`, `conda info --envs` (which should really be `conda list --envs` 😖) will look for that file in all known user home directories.  That way a sysadmin can discover all environments on a machine and scan environments for outdated packages (like e.g. openssl).
> I'm not sure if this would even work on Windows?

Python's `os.path.expanduser('~')` has no issues on Windows.

Resolving patch:
diff --git a/conda/core/envs_manager.py b/conda/core/envs_manager.py
--- a/conda/core/envs_manager.py
+++ b/conda/core/envs_manager.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 from __future__ import absolute_import, division, print_function, unicode_literals
 
+from errno import EACCES
 from logging import getLogger
 from os import listdir
 from os.path import dirname, isdir, isfile, join, normpath, split as path_split
@@ -29,9 +30,17 @@ def register_env(location):
         # Nothing to do. Location is already recorded in a known environments.txt file.
         return
 
-    with open(USER_ENVIRONMENTS_TXT_FILE, 'a') as fh:
-        fh.write(ensure_text_type(location))
-        fh.write('\n')
+    try:
+        with open(USER_ENVIRONMENTS_TXT_FILE, 'a') as fh:
+            fh.write(ensure_text_type(location))
+            fh.write('\n')
+    except EnvironmentError as e:
+        if e.errno == EACCES:
+            log.warn("Unable to register environment. Path not writable.\n"
+                     "  environment location: %s\n"
+                     "  registry file: %s", location, USER_ENVIRONMENTS_TXT_FILE)
+        else:
+            raise
 
 
 def unregister_env(location):
@@ -111,6 +120,6 @@ def _rewrite_environments_txt(environments_txt_file, prefixes):
         with open(environments_txt_file, 'w') as fh:
             fh.write('\n'.join(prefixes))
             fh.write('\n')
-    except (IOError, OSError) as e:
+    except EnvironmentError as e:
         log.info("File not cleaned: %s", environments_txt_file)
         log.debug('%r', e, exc_info=True)


Test patch: