1

As the manual page for nix-shell describes it:

Nix can be used to provides some kind of virtual environment through the nix-shell command.

Much like Python developers commonly create a virtual environment of python packages that they then activate, nix-shell can be used to create a virtual environment of any packages available in the Nix package manager; a tool which allows the user to download and activate a virtual shell environment with the packages needed to develop some piece of software without polluting the user or system environment.

With the background out of the way, my question is then: Is there an equivalent of nix-shell available for the Guix package manager?

2 Answers 2

3

I think you're looking for guix environment --ad-hoc. For example:

guix environment --ad-hoc python python-pandas

That creates a temporary Guix profile with Python and Pandas installed, but could equally be any other packages in Guix. Specifically with Python you need to include python so that it is aware of python-pandas. The above gives you a temporary profile that still has access to exsting environment variables and packages in the current user and system profiles.

For a more isolated (and hence reproducible) environment, you can use --pure to hide existing environment variables, user profile and system profile:

guix environment --pure --ad-hoc [packages]

For full containerized isolation, which alows you to restrict filesystem and network access:

guix environment --container --ad-hoc [packages]

The last two options will require you to explicitly specify a whole lot of the more fundamental packages, such as coreutils; more effort, but more reproducible.

See invoking guix environment for more.

I also use a program called direnv which automatically activates/deactivates these profiles and other environment variables for various projects. You create a .envrc file for your project something like this:

use guix --ad-hoc python python-matplotlib python-html5lib python-mypy python-flake8
source ~/.virtualenvs/base-django-py38/bin/activate
export DJANGO_SETTINGS_MODULE=project.settings.dev

The use guix is a custom feature of direnv, which is only briefly documented.

1

There is guix shell now.

$ guix shell hello

brings you fresh environment with hello package installed inside it. It is "drop-in" replacement for guix environment --ad-hoc.

If you rather want dependencies of hello (for example, to start development of it) then all you need is as simple as:

$ guix shell -D hello

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.