Skip to content

Software Environment

Guix

GNU Guix is a functional package manager and an advanced distribution system for the GNU system and beyond. It is designed to provide reproducible, user-controlled, and transparent package management.

If you don't know what Guix is, and why it is useful, we had a nice seminar about it at CPPM by Konrad Hinsen. You can watch the video here. And there is a practical introduction to Guix on the gitlab here.

The following sections provide basic guide lines to get started with Guix. For more detailed information, refer to the Guix documentation.

Guix vs. Conda

While Conda is popular for managing packages and environments in data science and computational science, Guix offers some distinctive advantages:

  • Reproducibility: Guix supports truly reproducible environments, ensuring that installations are identical every time, down to the binary level. This is achieved by precise tracking of dependencies and build environments.

  • User Empowerment: Users can install software without administrative privileges, modify packages, and contribute to the package database. Guix uses a declarative approach that allows users to customize or override packages easily.

  • Transparency: Guix is completely open-source, and every build process is transparent and modifiable. It also supports bootstrapping from source code, enhancing trust and security.

  • Environment Management: Guix environments are isolated and can be manipulated easily without affecting global or user-specific settings unless explicitly intended.

Installing Packages with Guix

To install a package using Guix, use the guix install command. For example, to install htop, you would run:

guix install htop

This command downloads and builds htop, along with all its dependencies, in an isolated environment ensuring that it does not interfere with other installed software.

Searching for Packages with Guix

To search for packages in the Guix package database, use the guix package command with the --search option. For example, to search for packages related to Python, you would run:

guix package --search=python

List all the version available for a package:

guix package -A python

Install a specific version of a package:

guix install python@3.8

Managing environment with Guix

Guix can create isolated environments similar to Conda but with more granularity in terms of package management.

To create an environment with specific packages, use the guix shell command. For example, to create an environment with Python and Jupyter, run:

guix shell python jupyter

This command temporarily activates an environment with Python and Jupyter. Bu default, the environment inherits packages from the host system.

You can use the option --pure to clean the environment from environment variables and paths from the host system:

guix shell --pure python jupyter

To go further, you can use the --container option to create a fully isolated environment:

guix shell --container python jupyter

This will create a containerized environment that is isolated from the host system, ensuring that the environment is reproducible and self-contained.

You can export the environment to a file using the --export-manifest option:

guix shell --pure openjdk --export-manifest > manifest.scm

This will create a file manifest.scm that contains the list of packages in the environment.

To be able to reproduce the environment on another system, you can use the --manifest option:

guix shell --manifest=manifest.scm

This will create an environment with the same packages as the one exported to manifest.scm. Take that the environment will be created with the versions of the packages available for the guix version you are using. May not be the same as the one you used to create the manifest.

To ensure full reproducibility, you also need to specify the guix version and the channel used to install the packages.

guix describe -f channels > channels.scm 

And with 2 files manifest.scm and channels.scm, you can travel back in time:

guix time-machine --channels=channels.scm -- shell --manifest=manifest.scm

Creating a Singularity Container from a Guix Environment

Guix can export environments to various container formats, including Singularity, making it easy to share or deploy applications:

guix pack -f singularity python jupyter

This command creates a Singularity container image that contains Python and Jupyter, which can be executed on any system with Singularity installed, without needing Guix.

This is very useful for sharing computational environments with collaborators or deploying applications in othe clusters or to be used in CI/CD pipelines.

Make guix and pip coexist

Guix python packages may not be as up-to-date as the ones available on PyPI. To use both Guix and pip packages in the same environment, you can create a Guix environment with the necessary packages and then install additional packages using pip.

For example, to create a Guix environment with Python and Jupyter, and then install additional packages using pip, you would run:

guix shell python python-pip

Then, activate the environment and install additional packages using pip:

pip install pytorch

This way, you can combine the benefits of Guix and pip packages in the same environment. Take care that the pip packages will not be managed by Guix, they may not be as reproducible as the Guix packages.

Make guix and rustup coexist

Guix rust packages may not be as up-to-date as the ones available on crates.io. To use both Guix and rustup packages in the same environment, you can create a Guix environment with the necessary packages and then install additional packages using rustup.

For example, to create a Guix environment with Rust and Cargo, and then install additional packages using rustup, you would run:

guix shell rust

Then, activate the environment and install additional packages using rustup:

rustup install nightly

As in the case of python/pip, the rustup packages will not be managed by Guix, they may not be as reproducible as the Guix packages.

Go further

Guix can be used to manage a wide range of software packages and environments. For more information, refer to the Guix documentation.