The Nextjournal Bash Environment

The default environment for standalone Bash cells

The Minimal Bash environment is the default for a standalone Bash cell, and also serves as the base for most language images.

Showcase

The environment is based on the ubuntu:18.04 docker image.

grep "DISTRIB_" /etc/*release
0.7s
Bash Showcase (Bash)
Minimal Bash

These packages are installed in the default Minimal Bash environment.

dpkg -l | sed -e '1,3d' | sed -e '2d' | cut -b 5-65,79- | \
  sed 's/ \+/ /g; s/ /,/1; s/ /,"/1; s/$/"/' > /results/pkgs.csv
echo 'Name,Version,Description
bb,'"$(bb --version)"',"Command-line Clojure interpreter"
jet,'"$(jet --version)"',"CLI to transform between JSON, EDN and Transit"
jq,'"$(jq --version)"',"Command-line JSON processor"' \
  >> /results/added-pkgs.csv
0.2s
Bash Showcase (Bash)
Minimal Bash
0 items
0 items

System Packages and Basics

The packages installed include every major decompression tool, curl, wget, and netcat, gnupg and git, and fontconfig, as well as a small selection of fonts (including the fonts used in the Nextjournal UI).

Packages are installed with apt-get. The environment is saved without cached package lists (they would quickly outdate anyway), and so an update is required before installing any packages. It is recommended to set DEBIAN_FRONTEND=noninteractive for a smooth install.

apt-get -qq update
DEBIAN_FRONTEND=noninteractive \
  apt-get install cowsay fortune
/usr/games/fortune | /usr/games/cowsay
9.4s
Bash Showcase (Bash)
Minimal Bash

Displaying Files

Any file written or copied into the /results directory will, once the cell finishes execution, be stored in Nextjournal's immutable, versioned storage database. The editor will attempt to appropriately display files in recognized formats (text, images, CSV tables).

wget -qO /results/test.svg \
  https://nextjournal.com/images/nextjournal-logo.svg
0.4s
Bash Showcase (Bash)
Minimal Bash

These files can be accessed in subsequent cells in the same way as Uploaded files, using Ctrl-E or Cmd-E to insert a reference.

ls NJ__REF_
1.0s
Bash Showcase (Bash)
Minimal Bash

CSV files will show as paginated tables by default.

echo 'a,b,c
1,2,3' > /results/test.csv
0.2s
Bash Showcase (Bash)
Minimal Bash
0 items

Files displayed as text or tables can be changed to show as a downloadable file using the ··· menu to the upper left of the file's display area.

echo 'a b c
1 2 3' > /results/test.txt
0.1s
Bash Showcase (Bash)
Minimal Bash
test.txt

Setup

Build the Minimal Bash Environment

The default Bash environment is based off the Ubuntu 18.04 LTS Docker image.

Ubuntu Base
Download as Docker image from:
Copy
This image was imported from: ubuntu:18.04

We set the timezone and install some basic packages including gnupg and git. We've also set a number of environment variables in the runtime's settings—in particular, the value of NEXTJOURNAL_MOUNT_CUDA sets the default Nvidia CUDA and cuDNN versions for all descendant environments.

The basic packages installed include tools to aid in further package installation, such as decompression suites and git.

echo "UTC" > /etc/timezone
echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-yes
apt-get -qq update
DEBIAN_FRONTEND=noninteractive \
  apt-get install --no-install-recommends apt-utils net-tools \
  ca-certificates locales tzdata perl-doc sudo \
  zip unzip gzip bzip2 xz-utils unrar p7zip-full \
  curl wget netcat \
  gnupg git patch \
  fontconfig fonts-dejavu fonts-liberation2
apt-get clean
rm -r /var/lib/apt/lists/* # Clear package list so it isn't stale
35.7s
Minimal Bash (Bash)
Ubuntu Base

Generate the locale that we set in the environment variables.

locale-gen en_US.UTF-8
update-locale LANG=en_US.UTF-8 LANGUAGE=en_US.en LC_ALL=en_US.UTF-8
1.3s
Minimal Bash (Bash)
Ubuntu Base

And ensure the GPU libraries can be used.

echo "/usr/local/cuda/lib64" >> /etc/ld.so.conf.d/cuda.conf
echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf
ldconfig
0.5s
Minimal Bash (Bash)
Ubuntu Base

Install a small selection of open fonts available on Google Fonts and here. The Nextjournal UI uses Fira Sans, Fira Mono, and PT Serif.

nj_fonts.tar.xz
cd /usr/share/fonts/
sudo tar -Jxf NJ__REF_
shopt -s extglob
sudo chmod -R --reference=/usr/share/fonts/truetype/dejavu \
  /usr/share/fonts/!(dejavu)
fc-cache -f
fc-list
4.4s
Minimal Bash (Bash)
Ubuntu Base

Configure default fonts: Nextjournal UI fonts for the generic families, and similar alternatives for some specific common fonts.

echo '<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <alias>
    <family>serif</family>
    <prefer><family>PT Serif</family></prefer>
  </alias>
  <alias>
    <family>sans-serif</family>
    <prefer><family>Fira Sans</family></prefer>
  </alias>
  <alias>
    <family>sans</family>
    <prefer><family>Fira Sans</family></prefer>
  </alias>
  <alias>
    <family>monospace</family>
    <prefer><family>Fira Mono</family></prefer>
  </alias>
  <alias>
    <family>Arial</family>
    <prefer><family>Liberation Sans</family></prefer>
  </alias>
  <alias>
    <family>Helvetica</family>
    <prefer><family>Liberation Sans</family></prefer>
  </alias>
  <alias>
    <family>Verdana</family>
    <prefer><family>Andika</family></prefer>
  </alias>
  <alias>
    <family>Comic Sans</family>
    <prefer><family>Comic Neue</family></prefer>
  </alias>
</fontconfig>' > /etc/fonts/local.conf
0.1s
Minimal Bash (Bash)
Ubuntu Base

Download and install jq, babashka, and jet.

JQ_VERSION="1.6"
jq_file="jq-linux64"
jq_path="stedolan/jq/releases/download/jq-${JQ_VERSION}/${jq_file}"
jq_url="https://github.com/${jq_path}"
BB_VERSION="0.0.29"
bb_file="babashka-${BB_VERSION}-linux-amd64.zip"
bb_path="borkdude/babashka/releases/download/v${BB_VERSION}/${bb_file}"
bb_url="https://github.com/${bb_path}"
JET_VERSION="0.0.10"
jet_file="jet-${JET_VERSION}-linux-amd64.zip"
jet_path="borkdude/jet/releases/download/v${JET_VERSION}/${jet_file}"
jet_url="https://github.com/${jet_path}"
wget --progress=dot:giga $jq_url $bb_url $jet_url
mv $jq_file /usr/local/bin/jq
chmod +x /usr/local/bin/jq
unzip $bb_file
mv bb /usr/local/bin/
rm $bb_file
unzip $jet_file
mv jet /usr/local/bin/
rm $jet_file
5.3s
Minimal Bash (Bash)
Ubuntu Base
jq --version
bb --version
jet --version
0.7s
Minimal Bash (Bash)
Ubuntu Base

Build a Bash C/C++/Fortran Environment

An environment with GCC, G++, GFortran, and various support tools, for use as a base for compiled-language environments. Also provides an example of what to install in other cases.

apt-get -qq update
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends \
  build-essential gfortran cmake automake libtool libltdl-dev pkg-config
apt-get clean
rm -r /var/lib/apt/lists/* # Clear package list so it isn't stale
35.1s
Bash C (Bash)
Minimal Bash
Runtimes (3)