1{ stdenv, fetchurl, zlib ? null, zlibSupport ? true, bzip2, includeModules ? false
2, sqlite, tcl, tk, xlibsWrapper, openssl, readline, db, ncurses, gdbm, self, callPackage
3, python26Packages }:
4
5assert zlibSupport -> zlib != null;
6
7with stdenv.lib;
8
9let
10 majorVersion = "2.6";
11 version = "${majorVersion}.9";
12
13 src = fetchurl {
14 url = "http://www.python.org/ftp/python/${version}/Python-${version}.tar.xz";
15 sha256 = "0hbfs2691b60c7arbysbzr0w9528d5pl8a4x7mq5psh6a2cvprya";
16 };
17
18 patches =
19 [ # Look in C_INCLUDE_PATH and LIBRARY_PATH for stuff.
20 ./search-path.patch
21
22 # Python recompiles a Python if the mtime stored *in* the
23 # pyc/pyo file differs from the mtime of the source file. This
24 # doesn't work in Nix because Nix changes the mtime of files in
25 # the Nix store to 1. So treat that as a special case.
26 ./nix-store-mtime.patch
27
28 # http://bugs.python.org/issue10013
29 ./python2.6-fix-parallel-make.patch
30 ];
31
32 preConfigure = ''
33 # Purity.
34 for i in /usr /sw /opt /pkg; do
35 substituteInPlace ./setup.py --replace $i /no-such-path
36 done
37 '' + optionalString (stdenv ? cc && stdenv.cc.libc != null) ''
38 for i in Lib/plat-*/regen; do
39 substituteInPlace $i --replace /usr/include/ ${stdenv.cc.libc}/include/
40 done
41 '' + optionalString stdenv.isCygwin ''
42 # On Cygwin, `make install' tries to read this Makefile.
43 mkdir -p $out/lib/python${majorVersion}/config
44 touch $out/lib/python${majorVersion}/config/Makefile
45 mkdir -p $out/include/python${majorVersion}
46 touch $out/include/python${majorVersion}/pyconfig.h
47 '';
48
49 configureFlags = "--enable-shared --with-threads --enable-unicode=ucs4";
50
51 buildInputs =
52 optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc ++
53 [ bzip2 openssl ]++ optionals includeModules [ db openssl ncurses gdbm readline xlibsWrapper tcl tk sqlite ]
54 ++ optional zlibSupport zlib;
55
56 mkPaths = paths: {
57 C_INCLUDE_PATH = makeSearchPathOutput "dev" "include" paths;
58 LIBRARY_PATH = makeLibraryPath paths;
59 };
60
61 # Build the basic Python interpreter without modules that have
62 # external dependencies.
63 python = stdenv.mkDerivation {
64 name = "python${if includeModules then "" else "-minimal"}-${version}";
65 pythonVersion = majorVersion;
66
67 inherit majorVersion version src patches buildInputs preConfigure
68 configureFlags;
69
70 inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
71
72 NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2";
73
74 setupHook = ./setup-hook.sh;
75
76 postInstall =
77 ''
78 # needed for some packages, especially packages that backport
79 # functionality to 2.x from 3.x
80 for item in $out/lib/python${majorVersion}/test/*; do
81 if [[ "$item" != */test_support.py* ]]; then
82 rm -rf "$item"
83 fi
84 done
85 touch $out/lib/python${majorVersion}/test/__init__.py
86 ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb
87 ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb${majorVersion}
88 mv $out/share/man/man1/{python.1,python2.6.1}
89 ln -s $out/share/man/man1/{python2.6.1,python.1}
90
91 paxmark E $out/bin/python${majorVersion}
92
93 ${ optionalString includeModules "$out/bin/python ./setup.py build_ext"}
94 '';
95
96 passthru = rec {
97 inherit zlibSupport;
98 isPy2 = true;
99 isPy26 = true;
100 buildEnv = callPackage ../../wrapper.nix { python = self; };
101 withPackages = import ../../with-packages.nix { inherit buildEnv; pythonPackages = python26Packages; };
102 libPrefix = "python${majorVersion}";
103 executable = libPrefix;
104 sitePackages = "lib/${libPrefix}/site-packages";
105 interpreter = "${self}/bin/${executable}";
106 };
107
108 enableParallelBuilding = true;
109
110 meta = {
111 homepage = "http://python.org";
112 description = "A high-level dynamically-typed programming language";
113 longDescription = ''
114 Python is a remarkably powerful dynamic programming language that
115 is used in a wide variety of application domains. Some of its key
116 distinguishing features include: clear, readable syntax; strong
117 introspection capabilities; intuitive object orientation; natural
118 expression of procedural code; full modularity, supporting
119 hierarchical packages; exception-based error handling; and very
120 high level dynamic data types.
121 '';
122 license = stdenv.lib.licenses.psfl;
123 platforms = stdenv.lib.platforms.all;
124 maintainers = with stdenv.lib.maintainers; [ chaoflow domenkozar ];
125 # If you want to use Python 2.6, remove "broken = true;" at your own
126 # risk. Python 2.6 has known security vulnerabilities is not receiving
127 # security updates as of October 2013.
128 broken = true;
129 };
130 };
131
132
133 # This function builds a Python module included in the main Python
134 # distribution in a separate derivation.
135 buildInternalPythonModule =
136 { moduleName
137 , internalName ? "_" + moduleName
138 , deps
139 }:
140 if includeModules then null else stdenv.mkDerivation rec {
141 name = "python-${moduleName}-${python.version}";
142
143 inherit src patches preConfigure configureFlags;
144
145 buildInputs = [ python ] ++ deps;
146
147 inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
148
149 buildPhase =
150 ''
151 substituteInPlace setup.py --replace 'self.extensions = extensions' \
152 'self.extensions = [ext for ext in self.extensions if ext.name in ["${internalName}"]]'
153
154 python ./setup.py build_ext
155 [ -z "$(find build -name '*_failed.so' -print)" ]
156 '';
157
158 installPhase =
159 ''
160 dest=$out/lib/${python.libPrefix}/site-packages
161 mkdir -p $dest
162 cp -p $(find . -name "*.${if stdenv.isCygwin then "dll" else "so"}") $dest/
163 '';
164 };
165
166
167 # The Python modules included in the main Python distribution, built
168 # as separate derivations.
169 modules = {
170
171 bsddb = buildInternalPythonModule {
172 moduleName = "bsddb";
173 deps = [ db ];
174 };
175
176 crypt = buildInternalPythonModule {
177 moduleName = "crypt";
178 internalName = "crypt";
179 deps = optional (stdenv ? glibc) stdenv.glibc;
180 };
181
182 curses = buildInternalPythonModule {
183 moduleName = "curses";
184 deps = [ ncurses ];
185 };
186
187 curses_panel = buildInternalPythonModule {
188 moduleName = "curses_panel";
189 deps = [ ncurses modules.curses ];
190 };
191
192 gdbm = buildInternalPythonModule {
193 moduleName = "gdbm";
194 internalName = "gdbm";
195 deps = [ gdbm ];
196 };
197
198 sqlite3 = buildInternalPythonModule {
199 moduleName = "sqlite3";
200 deps = [ sqlite ];
201 };
202
203 tkinter = buildInternalPythonModule {
204 moduleName = "tkinter";
205 deps = [ tcl tk xlibsWrapper ];
206 };
207
208 readline = buildInternalPythonModule {
209 moduleName = "readline";
210 internalName = "readline";
211 deps = [ readline ];
212 };
213
214 };
215
216in python // { inherit modules; }