Skip to content

Guix and Virtualenv used together for a reproducible python development environment

Notifications You must be signed in to change notification settings

TimotheeMathieu/guix-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Guix & poetry environments for reproducible python development

This package give a cli tool to construct and enter environments constructed through guix (for the system-level packages) and optionally a poetry environment (for python packages). My main use-case are: having deployable environment that can run on server, archiving projects that I want to reliably run in several years and having clean environment to test stuff without the bloat of my main system.

Usage

Guix must be installed on the system, see the guix manual to do this.

pip install git+https://github.com/TimotheeMathieu/guix-env 
guix-env create my_env_name

This should create a directory in ~/.guix-env containing files needed for the environment to run. Note that every file generated by guix-env will be saved into ~/.guix-env and removing the environment is as simple as removing this directory (also doable through the guix-env rm command). Then to spawn a shell in the environment, do

guix-env shell my_env_name

The first run may be a bit slow because of guix downloading a bunch of packages but the second run should be faster as guix cache the packages it uses in /gnu/store (remark: don't forget to use guix gc to clear the store periodically).

Then, you are good to go and do anything you wish in your environment. You are in a python virtual environment that is managed with poetry for reproducibility purpose, to install new python package from inside the environment, use gep add package_name, gep stands for guix-env-poetry and is just an alias of poetry that install at the right place. To add new guix package, use guix-env add-guix my_env_name my_package_name from outside the environment.

Some remarks:

  • I included some guix and python packages that are convenient for basic shell commands and basic graphical display.
  • I use zsh shell in the guix-env environments.
  • Every environment has its own .local and .zshrc. They can be accessed in $HOME/.guix_env/env_name
  • I do not share the home directory, by default the only directory shared are the current directory and its children (default from guix shell).
  • I use the Filesystem Hierarchy Standard (FHS) emulator of guix shell to populate /bin and /lib apropriately for some python compatibility.
  • I use a poetry cache specific to guix-env environments. It is shared among the guix envs but not with the host system.
  • I added a channel file with the guix channel in which I made the last working test so if there is something wronggoing on, try to use this channel file, it should work then.

TODO

  • Better documentation -- include explanations of how it works: poetry, what do we share (what we do not share, e.g. .local), how to tinker with it, what changes are made...
  • Comment more
  • Make tests
  • Have an alias that install guix_env in a guix shell environment so that we can install & use guix-env in a reproducible maneer and without needing to install anything.
  • Feature: rollback, at first this could be through git repo that auto-commit.
  • Handle GPU ?
  • Feature: use tmux inside the env and share tmp to make a sort of daemon. https://stackoverflow.com/questions/16398850/create-new-tmux-session-from-inside-a-tmux-session

About

Guix and Virtualenv used together for a reproducible python development environment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published