blob: cf5065441ea777f7f8b08387a8214c1df07d0693 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
* 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.
[[https://nixos.org/][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
#+BEGIN_SRC nix
{ pkgs ? import <nixpkgs> {} }:
{
buildInputs = with pkgs; [ ocaml ocamlPackages.lwt ];
}
#+END_SRC
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 [[file: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.
#+BEGIN_SRC nix
{
ocaml = {
enable = true;
packages = ocamlPackages: [ ocamlPackages.lwt ];
};
}
#+END_SRC
* 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 [[file:modules/]] files.
A default configuration that will be used in all virtual environments may also
be declared in ~config/default.nix~. For example :
#+BEGIN_SRC nix
{ 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;
}
#+END_SRC
* 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~)
|