Skip to content

Manage virtual environments using modular nix shells.

Notifications You must be signed in to change notification settings

qaristote/venv-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

venv-manager is a set of nix modules that defines basic configurations for nix-shell, aiming to make it easier to declaratively manage virtual environments for different development frameworks.

NixOS indeed has, among others, two great advantages :

  • the ability to declaratively create virtual environments in shell.nix files that may then be activated with nix-shell ;
  • the ability to enable many services in a single statement thanks to a huge database of crowdsourced service configurations.

But creating a new virtual environment may end up being non trivial and cumbersome, because nix-shell doesn’t have a similar database of crowdsourced configurations. Consider the example of OCaml virtual environments. Simply using the shell.nix file given by

{ pkgs ? import <nixpkgs> {} }:
{ 
  buildInputs = with pkgs; [ ocaml ocamlPackages.lwt ]; 
} 

will not be enough as the ocaml binary needs to be made aware of the existence of the lwt library. After looking up how to do so, the user may then add the corresponding configuration to shell.nix (see modules/ocaml.nix for the solution). But creating another similar environment will require to either rewrite the same code or to find the previous file and copy it.

venv-manager aims to fill that gap by using the modularity of Nix to provide common configurations for virtual environments that may be enabled in a whim. Now creating the same OCaml environment only requires the following declaration.

{
  ocaml = {
    enable = true;
    packages = ocamlPackages: [ ocamlPackages.lwt ];
  };
}

Setup

To use venv-manager, clone this repository in ~/.config/venv-manager.

A new virtual environment configuration can then be created by copying the shell-template.nix (use an alias for that !) and filling in the settings attribute set. The available options can be found in the modules/ files.

A default configuration that will be used in all virtual environments may also be declared in config/default.nix. For example :

{ config, lib, pkgs, ... }:

{
  # enable support for direnv in all virtual environments
  # this value cannot be overriden locally
  direnv.enable = true;

  # enable support for Tuareg (OCaml's Emacs mode) in all virtual environments
  # where OCaml is enabled
  # this value can be overriden locally
  ocaml.tuareg.enable = lib.mkDefault true;

  # an example of something a little more complex
  # this value will be merged with other values declared locally
  buildInputs = lib.optional (config.ocaml.enable && 
                              config.python.enable) 
    pkgs.setupcfg2nix;
}

To do

venv-manager is still in its early development phase and there is still a lot of work to do. Among others :

  • adding support for all every existing programming languages ;
  • writing tests ;
  • creating a binary that automates the setup and creation of new virtual environment configurations, and lists the available options (think home-manager or nixos-option)

About

Manage virtual environments using modular nix shells.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages