User-defined environment variables in z2jh

Is there a good way to propagate user-defined environment variables to kernels in a z2jh-based deployment? Users can set their own variables (such as personal API keys) in a .bashrc file, which makes them available in terminals, but these are not inherited by kernels.

I could imagine a new entry point Spawner.cmd that tries to source a .bashrc after mounting the user volume, but before launching the notebook server, but this seems a little brittle to me.

In case anyone runs across this in the future, I had a similar usecase where I wanted our users to be able to set their own personal API keys for internal tools in a .bashrc file or the like. With inspiration from this answer I created a file at /usr/local/bin/start-notebook.d/source_bashrc.sh that contained:

#!/usr/bin/env bash

if [ -f "/home/jovyan/.bashrc" ]; then
  source /home/jovyan/.bashrc
fi

I added this to our custom docker image. I also had to change the command being run in the pod to start the Jupyter Notebook instance from the default of /opt/conda/bin/jupyterhub-singleuser to use /usr/local/bin/start-singleuser.sh. That will call /usr/local/bin/start.sh which will run things palced in /usr/local/bin/start-notebook.d/. I did that by making my custom images in profileList look like:

  profileList:
    - display_name: "Python 3.9"
      description: "Python 3.9 with Poetry installed"
      kubespawner_override:
        image: "customeImageName"
        cmd: "start-singleuser.sh"

In my case I did the same but instead of .bashrc I used .profile