     ; Restore paths
     (setenv "PATH" (assoc-default 'path-backup hsenv-active-environment))
     (setq exec-path (assoc-default 'exec-path-backup hsenv-active-environment))
+    (setenv "PACKAGE_DB_FOR_GHC")
+    (setenv "PACKAGE_DB_FOR_GHC_PKG")
+    (setenv "PACKAGE_DB_FOR_GHC_MOD")
+    (setenv "PACKAGE_DB_FOR_CABAL")
+    (setenv "HSENV")
+    (setenv "HSENV_NAME")
+    (setenv "HASKELL_PACKAGE_SANDBOX")
     ; Destroy the hsenv active environment
     (let ((old-dir (cdr (assoc 'dir hsenv-active-environment))))
       (setq hsenv-active-environment nil)

    (insert-file-contents (concat hsenv-dir file))
    (buffer-string)))

(defun hsenv-activate-environment (hsenv-dir)
  "Activate the Virtual Haskell Environment in directory HSENV-DIR"
  (when (and (hsenv-valid-dirp hsenv-dir)
             (hsenv-is-not-active))

             (env (assoc env-name environments)))
        (let* ((hsenv-dir-name (hsenv-env-dir env))
               (hsenv-dir (file-name-as-directory hsenv-dir-name)))
          (hsenv-activate-environment hsenv-dir dir env-name))))))

(defun hsenv-list-environments (dir)
  "Returns an assoc list of all environments avaliable in DIR.

The assoc list contains pairs of the form (NAME . DIRECTORY)."
  (let ((hsenv-dirs (append (file-expand-wildcards (concat dir ".hsenv"))
			    (file-expand-wildcards (concat dir ".hsenv*")))))
    (mapcar #'hsenv-make-env hsenv-dirs)))

(defun hsenv-activate (&optional select-dir)
