1{ stdenv, fetchurl, zlib ? null, zlibSupport ? true, bzip2, less, 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 propagatedBuildInputs = [ less ];
57
58 mkPaths = paths: {
59 C_INCLUDE_PATH = makeSearchPathOutput "dev" "include" paths;
60 LIBRARY_PATH = makeLibraryPath paths;
61 };
62
63 # Build the basic Python interpreter without modules that have
64 # external dependencies.
65 python = stdenv.mkDerivation {
66 name = "python${if includeModules then "" else "-minimal"}-${version}";
67 pythonVersion = majorVersion;
68
69 inherit majorVersion version src patches buildInputs propagatedBuildInputs
70 preConfigure configureFlags;
71
72 inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
73
74 NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2";
75
76 setupHook = ./setup-hook.sh;
77
78 postInstall =
79 ''
80 # needed for some packages, especially packages that backport
81 # functionality to 2.x from 3.x
82 for item in $out/lib/python${majorVersion}/test/*; do
83 if [[ "$item" != */test_support.py* ]]; then
84 rm -rf "$item"
85 fi
86 done
87 touch $out/lib/python${majorVersion}/test/__init__.py
88 ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb
89 ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb${majorVersion}
90 mv $out/share/man/man1/{python.1,python2.6.1}
91 ln -s $out/share/man/man1/{python2.6.1,python.1}
92
93 paxmark E $out/bin/python${majorVersion}
94
95 ${ optionalString includeModules "$out/bin/python ./setup.py build_ext"}
96 '';
97
98 passthru = rec {
99 inherit zlibSupport;
100 isPy2 = true;
101 isPy26 = true;
102 buildEnv = callPackage ../../wrapper.nix { python = self; };
103 withPackages = import ../../with-packages.nix { inherit buildEnv; pythonPackages = python26Packages; };
104 libPrefix = "python${majorVersion}";
105 executable = libPrefix;
106 sitePackages = "lib/${libPrefix}/site-packages";
107 interpreter = "${self}/bin/${executable}";
108 };
109
110 enableParallelBuilding = true;
111
112 meta = {
113 homepage = "http://python.org";
114 description = "A high-level dynamically-typed programming language";
115 longDescription = ''
116 Python is a remarkably powerful dynamic programming language that
117 is used in a wide variety of application domains. Some of its key
118 distinguishing features include: clear, readable syntax; strong
119 introspection capabilities; intuitive object orientation; natural
120 expression of procedural code; full modularity, supporting
121 hierarchical packages; exception-based error handling; and very
122 high level dynamic data types.
123 '';
124 license = stdenv.lib.licenses.psfl;
125 platforms = stdenv.lib.platforms.all;
126 maintainers = with stdenv.lib.maintainers; [ chaoflow domenkozar ];
127 # If you want to use Python 2.6, remove "broken = true;" at your own
128 # risk. Python 2.6 has known security vulnerabilities is not receiving
129 # security updates as of October 2013.
130 broken = true;
131 };
132 };
133
134
135 # This function builds a Python module included in the main Python
136 # distribution in a separate derivation.
137 buildInternalPythonModule =
138 { moduleName
139 , internalName ? "_" + moduleName
140 , deps
141 }:
142 if includeModules then null else stdenv.mkDerivation rec {
143 name = "python-${moduleName}-${python.version}";
144
145 inherit src patches preConfigure configureFlags;
146
147 buildInputs = [ python ] ++ deps;
148
149 inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
150
151 buildPhase =
152 ''
153 substituteInPlace setup.py --replace 'self.extensions = extensions' \
154 'self.extensions = [ext for ext in self.extensions if ext.name in ["${internalName}"]]'
155
156 python ./setup.py build_ext
157 [ -z "$(find build -name '*_failed.so' -print)" ]
158 '';
159
160 installPhase =
161 ''
162 dest=$out/lib/${python.libPrefix}/site-packages
163 mkdir -p $dest
164 cp -p $(find . -name "*.${if stdenv.isCygwin then "dll" else "so"}") $dest/
165 '';
166 };
167
168
169 # The Python modules included in the main Python distribution, built
170 # as separate derivations.
171 modules = {
172
173 bsddb = buildInternalPythonModule {
174 moduleName = "bsddb";
175 deps = [ db ];
176 };
177
178 crypt = buildInternalPythonModule {
179 moduleName = "crypt";
180 internalName = "crypt";
181 deps = optional (stdenv ? glibc) stdenv.glibc;
182 };
183
184 curses = buildInternalPythonModule {
185 moduleName = "curses";
186 deps = [ ncurses ];
187 };
188
189 curses_panel = buildInternalPythonModule {
190 moduleName = "curses_panel";
191 deps = [ ncurses modules.curses ];
192 };
193
194 gdbm = buildInternalPythonModule {
195 moduleName = "gdbm";
196 internalName = "gdbm";
197 deps = [ gdbm ];
198 };
199
200 sqlite3 = buildInternalPythonModule {
201 moduleName = "sqlite3";
202 deps = [ sqlite ];
203 };
204
205 tkinter = buildInternalPythonModule {
206 moduleName = "tkinter";
207 deps = [ tcl tk xlibsWrapper ];
208 };
209
210 readline = buildInternalPythonModule {
211 moduleName = "readline";
212 internalName = "readline";
213 deps = [ readline ];
214 };
215
216 };
217
218in python // { inherit modules; }