Makers Blog Archive

Install the GNU Guix package manager

Bjoern PLCnext Team 16 May 2019 min. read
257 views 0 comments

This article describes how to install the GNU Guix package manager on the AXC F 2152. GNU Guix is a functional package manager that offers transactional, reproducible, per-user package management. GNU Guix can be installed on top of an existing Linux system where it complements the available tools without interference. Guix could be used to install packages to provide for example a gcc toolchain or python 2 on a per-user level. There is an excellent explanation in the manual on how to install Guix on the GNU homepage. This article will guide you trough the process of installing GNU Guix.

There is also an adapted shell installer script based on the GNU Guix installer script. The script automates the download, installation, and initial configuration steps described below. It should be run as the root user. You can download the script from the GitHub Gist.

Install dependencies

To extract the Guix archive we need to install the xz-utils debian package. Open a ssh connection and log into the system with the admin user. Execute the following commands.

curl -OL
sudo dpkg -i --force-depends --force-architecture xz-utils_5.2.2-1.2+b1_armhf.deb

Install Guix package manager

These steps follow the install procedure of the Binary-Installation chapter in the Guix manual. Open a shell session, login as root user and run the following commands:

  1. Download the Guix prebuilt binary package.
    cd ~root curl -OL
  2. Extract the Guix prebuilt binary package. We extract it directly to the upper directory of the overlay filesystem, otherwise we could get some kind of the following error message:
    tar: ./gnu/store/bjdpc29ilwjix0snnprim9g6xrgw257h-profile/bin: Directory renamed before its status could be extracted tar: Exiting with failure status due to previous errors
    Run the following commands:
    tar --warning=no-timestamp -xf guix-binary-1.0.0.armhf-linux.tar.xz -C /media/rfs/rw/upperdir/home/root/ mv var/guix /var/ && mv gnu / rm guix-binary-1.0.0.armhf-linux.tar.xz rm -R var
  3. Make the Guix profile available.
    mkdir -p ~root/.config/guix ln -sf /var/guix/profiles/per-user/root/current-guix ~root/.config/guix/current GUIX_PROFILE="`echo ~root`/.config/guix/current" ; source $GUIX_PROFILE/etc/profile
  4. Create the group and user account for build users as explained in the Guix manual, chapter Build Environment Setup.
    groupadd --system guixbuild for i in `seq -w 1 10`; do useradd -g guixbuild -G guixbuild \ -d /var/empty -s `which nologin` \ -c "Guix build user $i" --system \ guixbuilder$i; done
  5. Open another ssh session, login as root user and run the Guix daemon.
    ~root/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild
  6. Return to the first shell session and make the Guix command available to other users.
    mkdir -p /usr/local/bin cd /usr/local/bin ln -s /var/guix/profiles/per-user/root/current-guix/bin/guix
  7. Setup the Substitute Servers.
    guix archive --authorize < ~root/.config/guix/current/share/guix/ guix archive --authorize < ~root/.config/guix/current/share/guix/
  8. Setup guix glibc locales.See the Guix manual chapter Application Setup. This is needed because packages installed via Guix will not use the local data of the host system.
    guix install glibc-utf8-locales export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale

The Guix package manager can now be used to install packages on the device. Try to install the hello package to check if everything is working.

guix install hello

Setup the environment profile

Create a profile script so that the environment variables of the shell are setup to include the needed settings for the Guix profile. This profile script will be loaded if you login to a shell.

Start a shell session and log in as root user. Execute the following commands.

mkdir -p /etc/profile.d
touch /etc/profile.d/
chmod 755 /etc/profile.d/

Copy the following code to the file /etc/profile.d/

if [ -e "$HOME/.config/guix/current" ]; then
    export PATH="$HOME/.config/guix/current/bin:$PATH"
    export INFOPATH="$HOME/.config/guix/current/share/info:$INFOPATH"
if [ -e "$HOME/.guix-profile" ]; then
    export GUIX_PROFILE="$HOME/.guix-profile"
    . "$GUIX_PROFILE/etc/profile"
    export GUIX_LOCPATH="$GUIX_PROFILE/lib/locale"

This code will now be executed if you open a new shell.

Start Guix daemon on boot

Add a startup script to the /etc/init.d directory to automatically start the Guix daemon on boot.

  1. Create the startup script. Start a shell session and login with the root user.
    touch /etc/init.d/guix-daemon chmod 755 /etc/init.d/guix-daemon
  2. Copy the script below to the created file.
    #! /bin/sh ### BEGIN INIT INFO # Provides: guix-daemon # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 6 # Short-Description: Build daemon for GNU Guix ### END INIT INFO USER=root PATH=/var/guix/profiles/per-user/root/current-guix/bin:/usr/sbin:/sbin:/usr/bin:/bin NAME=guix-daemon DAEMON=/var/guix/profiles/per-user/root/current-guix/bin/guix-daemon GUIX_LOCPATH=/var/guix/profiles/per-user/root/guix-profile/lib/locale OPTIONS="--build-users-group=guixbuild --cores=2 --max-jobs=2" LOG=/var/log/guix-daemon.log PIDFILE=/var/run/ # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present [ -r /etc/default/$NAME ] && . /etc/default/$NAME . /etc/init.d/functions start_daemon () { start-stop-daemon --start --background --no-close \ --chuid $USER --name $NAME \ $START_STOP_OPTIONS \ --make-pidfile --pidfile $PIDFILE \ --exec "$DAEMON" -- $OPTIONS > $LOG 2>&1 echo "Logging to "$LOG } stop_daemon () { start-stop-daemon --stop \ --user $USER \ --remove-pidfile --pidfile $PIDFILE \ --retry 30 --oknodo } case "$1" in start) echo "Starting daemon" "$NAME" start_daemon ;; stop) echo "Stopping daemon" "$NAME" stop_daemon ;; restart) $0 stop sleep 5 $0 start ;; status) status "$DAEMON" "$NAME" exit $? ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac exit 0
  3. Update the symbolic links of init system.
    update-rc.d guix-daemon defaults 99
  4. Restart the PLC and check if the Guix daemon has started.
    ps | grep guix

Install packages

Packages can be install with the guix install command. This will install the package and all its dependencies into the current profile. This will consume a lot of disc space. So keep in mind to provide enough free space.

Install tools for a gcc build environment. The following command will install gcc-7, make and python in version 2.

guix install gcc-toolchain@7 make python2

After installing the packages you may have to update your environment variables to be able to use the install packages. Simply log out and start a new shell session. The needed environment variables will be pulled in from the profile script in /etc/profile.d/

If you have also installed Node.js from the PLCnext App Store you are now be able to install Node.js native modules from npm which will fallback to build from source.

npm install -g bcrypt

Uninstall GNU Guix

GNU Guix does not install packages in the host system. Therefore it is easy to remove GNU Guix and all installed packages from the system. Just remove the /gnu and /var/guix folders.

Also clean up the symlinks to the profile in the user home directories. Remove the file ~/.guix-profile and if present the directory ~/.config/guix.


The Makers Blog shows applications and user stories of community members that are not tested or reviewed by Phoenix Contact. Use them at your own risk.


Please login/register to comment
Never miss a new article
Sign up for the newsletter
Never miss news about PLCnext Technology
Get interesting content via newsletter four times a year
Receive exclusive information before all other users