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