@@ -4,11 +4,17 @@
4, enableGhostscript ? false, ghostscript ? null, gtk3
4, enableGhostscript ? false, ghostscript ? null, gtk3
5, enableGtk2 ? false, pygtk ? null, gobjectIntrospection
5, enableGtk2 ? false, pygtk ? null, gobjectIntrospection
6, enableGtk3 ? false, cairo
6, enableGtk3 ? false, cairo
7+, enableTk ? false, tcl ? null, tk ? null, tkinter ? null, libX11 ? null
7, Cocoa, Foundation, CoreData, cf-private, libobjc, libcxx
8, Cocoa, Foundation, CoreData, cf-private, libobjc, libcxx
10assert enableGhostscript -> ghostscript != null;
11assert enableGhostscript -> ghostscript != null;
11assert enableGtk2 -> pygtk != null;
12assert enableGtk2 -> pygtk != null;
13+assert enableTk -> (tcl != null)
13buildPythonPackage rec {
19buildPythonPackage rec {
14 name = "matplotlib-${version}";
20 name = "matplotlib-${version}";
@@ -33,12 +39,27 @@ buildPythonPackage rec {
33 libpng pkgconfig mock pytz
39 libpng pkgconfig mock pytz
35 ++ stdenv.lib.optional enableGtk2 pygtk
41 ++ stdenv.lib.optional enableGtk2 pygtk
36− ++ stdenv.lib.optionals enableGtk3 [ cairo pycairo gtk3 gobjectIntrospection pygobject3 ];
42+ ++ stdenv.lib.optionals enableGtk3 [ cairo pycairo gtk3 gobjectIntrospection pygobject3 ]
43+ ++ stdenv.lib.optionals enableTk [ tcl tk tkinter libX11 ];
39 [ ./basedirlist.patch ] ++
46 [ ./basedirlist.patch ] ++
40 stdenv.lib.optionals stdenv.isDarwin [ ./darwin-stdenv.patch ];
47 stdenv.lib.optionals stdenv.isDarwin [ ./darwin-stdenv.patch ];
49+ # Matplotlib tries to find Tcl/Tk by opening a Tk window and asking the
50+ # corresponding interpreter object for its library paths. This fails if
51+ # `$DISPLAY` is not set. The fallback option assumes that Tcl/Tk are both
52+ # installed under the same path which is not true in Nix.
53+ # With the following patch we just hard-code these paths into the install
57+ inherit (stdenv.lib.strings) substring;
58+ tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${substring 0 3 tk.version}"'';
60+ stdenv.lib.optionalString enableTk
61+ "sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py";
42 checkPhase = ''
63 checkPhase = ''
43 ${python.interpreter} tests.py
64 ${python.interpreter} tests.py