jupyterhub / the-littlest-jupyterhub

Simple JupyterHub distribution for 1-100 users on a single server
https://tljh.jupyter.org
BSD 3-Clause "New" or "Revised" License
1.04k stars 340 forks source link

Document how to set environment variables for hub and user environment #734

Open consideRatio opened 3 years ago

consideRatio commented 3 years ago

It could be needed for a environment variable to be set for the hub environment or the user environment. This may be done in various ways perhaps, but we should probably document this as this is quite distribution specific.

Related

minrk commented 3 years ago

The user environment is configured by setting Spawner.environment. Perhaps this shoudl be in tljh-config set user_environment.env.ENVVAR? It's unclear to me when an option should have a high-level tljh-config alias vs use the underlying traitlets config.

We should perhaps even have a tljh config area for setting the hub env, because manually editing the systemd unit is pretty advanced, and I suspect a problem for upgrades. In most cases, setting environment variables for the hub with Python code in jupyterhub_config.py with os.environ will work, which would be the easiest to implement, because nothing but jupyterhub itself has been imported or instantiated at this point. However, it does preclude setting things like $PATH or $PYTHONPATH or $PYTHONUNBUFFERED that should have an effect on the invocation of python or jupyterhub itself. To work everywhere, we would need to write config somewhere and have a custom entrypoint that loads the environment prior to invoking python -m jupyterhub ....

consideRatio commented 3 years ago

TLJH makes use of SystemdSpawner, which in turn has the extra_paths configuration.

https://github.com/jupyterhub/the-littlest-jupyterhub/blob/ece294f6ebd805f30921cd565abfca27b305d3fb/tljh/jupyterhub_config.py#L28-L29

A user can do append to that in a custom config file.