Joshua Sierles / Feb 14 2018

Using Guix with R in Nextjournal

Let's try getting a Guix-based R installation in place for use in Nextjournal articles.

First, let's get a copy of the Guix binary installation and store it permanently in this article. This means we never have to download it again.

curl ftp://alpha.gnu.org/gnu/guix/guix-binary-0.14.0.x86_64-linux.tar.xz -o /results/guix-binary-0.14.0.x86_64-linux.tar.xz




guix-binary-0.14.0.x86_64-linux.tar.xz
Download

Now let's do the same with our custom R modules. We need this to install the required r-feather package that's not available yet in Guix upstream.

curl https://gist.githubusercontent.com/jsierles/633ef7050c929ac45957544c1adc44fd/raw/8f97fab26c0680afe35acda896a547dadc4cbb12/r.scm -o /results/r.scm




Now we're ready to install Guix itself. We'll untar the binary installation and install our custom modules somewhere.

cd /tmp
tar --warning=no-timestamp -xf 
old-snow.guix-binary-0.14.0.x86_64-linux.tar.xz
rm -rf /var/guix /gnu mv var/guix /var/ && mv gnu / mkdir -p /modules/nextjournal/packages cp
spring-scene.r.scm
/modules/nextjournal/packages/r.scm

Now let's get guix and guix-daemon in our path so we can install packages later, and run some setup to ensure the Guix daemon will run and can download binaries from a trusted Guix mirror.

We also need to link our root user Guix profile to /.profile. Nextjournal will automatically source that when present in the environment filesystem.

ln -nfs /var/guix/profiles/per-user/root/guix-profile/bin/guix /usr/local/bin/guix
ln -nfs /var/guix/profiles/per-user/root/guix-profile/bin/guix /usr/local/bin/guix-daemon
ln -nfs /var/guix/profiles/per-user/root/guix-profile/etc/profile /.profile

if ! id -u guixbuilder0 > /dev/null 2>&1; then
  groupadd --system guixbuild
  useradd -g guixbuild -G guixbuild           \
          -d /var/empty -s `which nologin`    \
          -c "Guix build user" --system       \
          guixbuilder0;
fi

guix archive --authorize < /var/guix/profiles/per-user/root/guix-profile/share/guix/hydra.gnu.org.pub

This next cell uses the resulting environment from the previous steps.

To install packages, we need the Guix daemon running. Since we can't run permanent processes here, we'll just run it in the background for the duration of this particular installation.

Let's install R, plus Nextjournal required packages, and finally, the lubridate package to test our installation.

guix-daemon --build-users-group guixbuild --disable-chroot &
GUIX_PACKAGE_PATH=/modules USER=root guix package -i r r-feather r-jsonlite r-magrittr r-plotly r-base64enc r-lubridate

Now let's built on that environment in a new runtime. We can see we're using the correct Guix-based R installation.

which R


Now let's make sure lubridate is installed and usable.

require(lubridate)
dmy("30/30/2015")