Joshua Sierles / Feb 09 2018

Using Guix Profiles in Nextjournal

If you use Guix in another environment, you can package up your dependencies in a tar file and use it to run code here.

1.
Packing up the Guix profile

In this example, we package up a Guix Python profile from my local Guix installation.

guix pack python python-wrapper python-scipy python-feather-format
Bash

Then, we upload the resulting tar file to then download it here.

curl --upload-file /gnu/store/jfbkpkadmlk5mh4c9xk50ridw77picbx-tarball-pack.tar.gz https://transfer.sh/jfbkpkadmlk5mh4c9xk50ridw77picbx-tarball-pack.tar.gz
Bash

2.
Converting the Guix profile to a Nextjournal environment

To make use of this software, we'll want to turn it into an environment to base our Python runtime on.

In a Bash runtime, we download the tarball, unpack it and link the Guix profile to /.profile. Nextjournal sources this file automatically before running code.

curl https://transfer.sh/O73In/jfbkpkadmlk5mh4c9xk50ridw77picbx-tarball-pack.tar.gz -o pack.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  464M  100  464M    0     0  72.6M      0  0:00:06  0:00:06 --:--:-- 83.0M
tar xzf pack.tar.gz
ln -nfs ./gnu/store/rmhd1gjcqpmrb6kdh7cqk7gkj3kp9006-profile/etc/profile /.profile

Finally, we mark this runtime to export an environment we can use within our Python runtime.

3.
Running code with the new Guix-based environment

Now let's use this environment in the following Python runtime. First, we'll check to make sure we're using the correct Python install, instead of the Nextjournal default.

which python
python -V
/gnu/store/rmhd1gjcqpmrb6kdh7cqk7gkj3kp9006-profile/bin/python
Python 3.5.3

We can see the active Python install is in the Guix store.

Now let's make sure the scipy package included in our Guix bundle is available.

import scipy

Yay!