Ah. Thanks, Jonathan.
The rsession
definitely does NOT see the environmental variable:
> Sys.getenv("XDG_CONFIG_HOME")
[1] ""
What's interesting is that the official rstudio
container image doesn't have this problem. If I run it with
docker run -it --rm -p 8787:8787 -v "$PWD":/config -e XDG_CONFIG_HOME=/config rocker/rstudio
then the R session sees the environmental variable and the global options correctly appear in /config
.
I am trying to understand how rocker/rstudio
handles environmental variables, but there is an additional layer of complexity with the S6 server. I see that it copies the variables to ${R_HOME}/etc/Renviron.site
on startup:
$ docker run --rm rocker/rstudio cat /etc/cont-init.d/01_set_env
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
## Set our dynamic variables in Renviron.site to be reflected by RStudio Server or Shiny Server
exclude_vars="HOME PASSWORD RSTUDIO_VERSION BATCH_USER_CREATION"
for file in /var/run/s6/container_environment/*; do
sed -i "/^${file##*/}=/d" "${R_HOME}/etc/Renviron.site"
regex="(^| )${file##*/}($| )"
[[ ! $exclude_vars =~ $regex ]] && echo "${file##*/}=$(cat "${file}")" >>"${R_HOME}/etc/Renviron.site" || echo "skipping ${file}"
done
## only file-owner (root) should read container_environment files:
chmod 600 /var/run/s6/container_environment/*
If I do this manually in my container, the rsession sees those variables and writes dictionaries to /config
, but the remaining options still get written to ~/.config/
:
# On the host system
$ docker run -it --rm -p 8787:8787 -v "$PWD":/config -e XDG_CONFIG_HOME=/config rstudio:test
# Inside the container
gitpod ~ $ echo "XDG_CONFIG_HOME=$XDG_CONFIG_HOME" | sudo tee -a /etc/R/Renviron.site
gitpod ~ $ sudo /usr/lib/rstudio-server/bin/rserver
# Inside the rsession
> Sys.getenv("XDG_CONFIG_HOME")
[1] "/config"
# Changing appearance theme in Global Options...
# Back inside the container
gitpod ~ $ ls /config
R rstudio
gitpod ~ $ ls /config/rstudio
dictionaries
gitpod ~ $ ls ~/.config/rstudio/
rstudio-prefs.json
gitpod ~ $ cat ~/.config/rstudio/rstudio-prefs.json
{
"initial_working_directory": "~",
"editor_theme": "Solarized Dark",
"posix_terminal_shell": "bash"
}
Do dictionaries
and rstudio-prefs.json
use different env variables, maybe?