Joshua Sierles / Apr 11 2018

Bootstrapping a Guix store for Nextjournal

The Guix binary installation comes with a default profile designed for running Guix itself. Guix profiles lack any concept of a 'distribution'; nothing is installed by default in a profile. Not even bash or ls.

So, a Guix profile suitable for use in Nextjournal must at least have python and bash installed.

Running the following in a guix-ready environment, like the guix-daemon container on build servers in production staging, will generate a new profile suitable for use. We'll add some useful commands too.

guix package -i coreutils nss-certs zlib unzip bzip2 which tar gawk grep gzip sed wget curl vim bash gcc-toolchain make gdb findutils openssl python conda python-pandas python-numpy python-wrapper python-matplotlib
Bash

This command links ~/.guix-profile to the new profile. Let's inspect the link to find out which profile was generated.

/ # ls -lsa /var/guix/profiles/per-user/root
total 8
4 drwxr-xr-x 2 root root 4096 Apr 11 14:08 .
4 drwxrwxrwt 3 root root 4096 Jan  1  1970 ..
0 lrwxrwxrwx 1 root root   52 Apr 11 14:08 guix-profile -> /var/guix/profiles/per-user/root/guix-profile-2-link
0 lrwxrwxrwx 1 root root   51 Apr 11 14:03 guix-profile-1-link -> /gnu/store/6sx2275xz66qzk3cbwa807fvb7ad9z35-profile
0 lrwxrwxrwx 1 root root   51 Apr 11 14:08 guix-profile-2-link -> /gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile
text

We can see the new profile lives at /gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile. Finally, to find out all the environment variables we need to use this profile, we examine the profile's bash profile at /gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile/etc/profile.

# Source this file to define all the relevant environment variables in Bash
# for this profile.  You may want to define the 'GUIX_PROFILE' environment
# variable to point to the "visible" name of the profile, like this:
#
#  GUIX_PROFILE=/path/to/profile ; \
#  source /path/to/profile/etc/profile
#
# When GUIX_PROFILE is undefined, the various environment variables refer
# to this specific profile generation.

export PATH="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/bin:${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/sbin${PATH:+:}$PATH"
export BASH_LOADABLES_PATH="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/lib/bash${BASH_LOADABLES_PATH:+:}$BASH_LOADABLES_PATH"
export C_INCLUDE_PATH="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/include${C_INCLUDE_PATH:+:}$C_INCLUDE_PATH"
export CPLUS_INCLUDE_PATH="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/include${CPLUS_INCLUDE_PATH:+:}$CPLUS_INCLUDE_PATH"
export LIBRARY_PATH="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/lib${LIBRARY_PATH:+:}$LIBRARY_PATH"
export SSL_CERT_DIR="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/etc/ssl/certs${SSL_CERT_DIR:+:}$SSL_CERT_DIR"
export PYTHONPATH="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/lib/python3.5/site-packages${PYTHONPATH:+:}$PYTHONPATH"
export GI_TYPELIB_PATH="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/lib/girepository-1.0${GI_TYPELIB_PATH:+:}$GI_TYPELIB_PATH"
export GUIX_GTK3_PATH="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/lib/gtk-3.0${GUIX_GTK3_PATH:+:}$GUIX_GTK3_PATH"
export XDG_DATA_DIRS="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/share${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"
export GIO_EXTRA_MODULES="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/lib/gio/modules${GIO_EXTRA_MODULES:+:}$GIO_EXTRA_MODULES"
export GUIX_LOCPATH="${GUIX_PROFILE:-/gnu/store/b2vqvh4bbs7dp84k8f89msp2m6kzsfps-profile}/lib/locale${GUIX_LOCPATH:+:}$GUIX_LOCPATH"
Bash

Once we can extract these values directly from this file and apply them to a runtime, using guix from within language containers should be even easier than using it on a standard Unix system.

Now let's examine the fruits of our labor. The following runtime has its environment set manually from the above template.

scratch
Download as Docker image from:
This image was imported from: tianon/true
which ls
which python
guix --version


print("python works")

guix package -i extends the current profile by creating a new profile including the current packages we installed. Let's install R and see that we still have python.

guix package -i r-minimal 2>&1
source ~/.guix-profile/etc/profile
which R
which python