at 17.09-beta 8.3 kB view raw
1{ stdenv, hostPlatform, fetchurl 2, bzip2 3, gdbm 4, fetchpatch 5, ncurses 6, openssl 7, readline 8, sqlite 9, tcl ? null, tk ? null, tix ? null, xlibsWrapper ? null, libX11 ? null, x11Support ? false 10, zlib 11, callPackage 12, self 13, gettext 14, db 15, expat 16, libffi 17, CF, configd, coreutils 18, python-setup-hook 19# For the Python package set 20, pkgs, packageOverrides ? (self: super: {}) 21}: 22 23assert x11Support -> tcl != null 24 && tk != null 25 && xlibsWrapper != null 26 && libX11 != null; 27 28with stdenv.lib; 29 30let 31 majorVersion = "2.7"; 32 minorVersion = "13"; 33 minorVersionSuffix = ""; 34 pythonVersion = majorVersion; 35 version = "${majorVersion}.${minorVersion}${minorVersionSuffix}"; 36 libPrefix = "python${majorVersion}"; 37 sitePackages = "lib/${libPrefix}/site-packages"; 38 39 src = fetchurl { 40 url = "https://www.python.org/ftp/python/${majorVersion}.${minorVersion}/Python-${version}.tar.xz"; 41 sha256 = "0cgpk3zk0fgpji59pb4zy9nzljr70qzgv1vpz5hq5xw2d2c47m9m"; 42 }; 43 44 hasDistutilsCxxPatch = !(stdenv.cc.isGNU or false); 45 patches = 46 [ # Look in C_INCLUDE_PATH and LIBRARY_PATH for stuff. 47 ./search-path.patch 48 49 # Python recompiles a Python if the mtime stored *in* the 50 # pyc/pyo file differs from the mtime of the source file. This 51 # doesn't work in Nix because Nix changes the mtime of files in 52 # the Nix store to 1. So treat that as a special case. 53 ./nix-store-mtime.patch 54 55 # patch python to put zero timestamp into pyc 56 # if DETERMINISTIC_BUILD env var is set 57 ./deterministic-build.patch 58 59 ./properly-detect-curses.patch 60 61 ] ++ optionals stdenv.isLinux [ 62 63 # Disable the use of ldconfig in ctypes.util.find_library (since 64 # ldconfig doesn't work on NixOS), and don't use 65 # ctypes.util.find_library during the loading of the uuid module 66 # (since it will do a futile invocation of gcc (!) to find 67 # libuuid, slowing down program startup a lot). 68 ./no-ldconfig.patch 69 70 ./glibc-2.25-enosys.patch 71 72 ] ++ optionals hostPlatform.isCygwin [ 73 ./2.5.2-ctypes-util-find_library.patch 74 ./2.5.2-tkinter-x11.patch 75 ./2.6.2-ssl-threads.patch 76 ./2.6.5-export-PySignal_SetWakeupFd.patch 77 ./2.6.5-FD_SETSIZE.patch 78 ./2.6.5-ncurses-abi6.patch 79 ./2.7.3-dbm.patch 80 ./2.7.3-dylib.patch 81 ./2.7.3-getpath-exe-extension.patch 82 ./2.7.3-no-libm.patch 83 ] ++ optionals hasDistutilsCxxPatch [ 84 85 # Patch from http://bugs.python.org/issue1222585 adapted to work with 86 # `patch -p1' and with a last hunk removed 87 # Upstream distutils is calling C compiler to compile C++ code, which 88 # only works for GCC and Apple Clang. This makes distutils to call C++ 89 # compiler when needed. 90 ./python-2.7-distutils-C++.patch 91 92 ]; 93 94 preConfigure = '' 95 # Purity. 96 for i in /usr /sw /opt /pkg; do 97 substituteInPlace ./setup.py --replace $i /no-such-path 98 done 99 '' + optionalString (stdenv ? cc && stdenv.cc.libc != null) '' 100 for i in Lib/plat-*/regen; do 101 substituteInPlace $i --replace /usr/include/ ${stdenv.cc.libc}/include/ 102 done 103 '' + optionalString stdenv.isDarwin '' 104 substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"' 105 substituteInPlace Lib/multiprocessing/__init__.py \ 106 --replace 'os.popen(comm)' 'os.popen("${coreutils}/bin/nproc")' 107 ''; 108 109 configureFlags = [ 110 "--enable-shared" 111 "--with-threads" 112 "--enable-unicode=ucs4" 113 ] ++ optionals hostPlatform.isCygwin [ 114 "--with-system-ffi" 115 "--with-system-expat" 116 "ac_cv_func_bind_textdomain_codeset=yes" 117 ] ++ optionals stdenv.isDarwin [ 118 "--disable-toolbox-glue" 119 ]; 120 121 postConfigure = if hostPlatform.isCygwin then '' 122 sed -i Makefile -e 's,PYTHONPATH="$(srcdir),PYTHONPATH="$(abs_srcdir),' 123 '' else null; 124 125 buildInputs = 126 optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc ++ 127 [ bzip2 openssl zlib ] 128 ++ optionals hostPlatform.isCygwin [ expat libffi ] 129 ++ [ db gdbm ncurses sqlite readline ] 130 ++ optionals x11Support [ tcl tk xlibsWrapper libX11 ] 131 ++ optionals stdenv.isDarwin [ CF configd ]; 132 133 mkPaths = paths: { 134 C_INCLUDE_PATH = makeSearchPathOutput "dev" "include" paths; 135 LIBRARY_PATH = makeLibraryPath paths; 136 }; 137 138 # Build the basic Python interpreter without modules that have 139 # external dependencies. 140 141in stdenv.mkDerivation { 142 name = "python-${version}"; 143 pythonVersion = majorVersion; 144 145 inherit majorVersion version src patches buildInputs 146 preConfigure configureFlags; 147 148 LDFLAGS = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s"; 149 inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH; 150 151 NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2"; 152 DETERMINISTIC_BUILD = 1; 153 154 setupHook = python-setup-hook sitePackages; 155 156 postPatch = optionalString (x11Support && (tix != null)) '' 157 substituteInPlace "Lib/lib-tk/Tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'" 158 ''; 159 160 postInstall = 161 '' 162 # needed for some packages, especially packages that backport 163 # functionality to 2.x from 3.x 164 for item in $out/lib/python${majorVersion}/test/*; do 165 if [[ "$item" != */test_support.py* 166 && "$item" != */regrtest.py* ]]; then 167 rm -rf "$item" 168 else 169 echo $item 170 fi 171 done 172 touch $out/lib/python${majorVersion}/test/__init__.py 173 ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb 174 ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb${majorVersion} 175 ln -s $out/share/man/man1/{python2.7.1.gz,python.1.gz} 176 177 paxmark E $out/bin/python${majorVersion} 178 179 # Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484 180 echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py 181 182 rm "$out"/lib/python*/plat-*/regen # refers to glibc.dev 183 184 # Determinism: Windows installers were not deterministic. 185 # We're also not interested in building Windows installers. 186 find "$out" -name 'wininst*.exe' | xargs -r rm -f 187 188 # Determinism: rebuild all bytecode 189 # We exclude lib2to3 because that's Python 2 code which fails 190 # We rebuild three times, once for each optimization level 191 find $out -name "*.py" | $out/bin/python -m compileall -q -f -x "lib2to3" -i - 192 find $out -name "*.py" | $out/bin/python -O -m compileall -q -f -x "lib2to3" -i - 193 find $out -name "*.py" | $out/bin/python -OO -m compileall -q -f -x "lib2to3" -i - 194 '' + optionalString hostPlatform.isCygwin '' 195 cp libpython2.7.dll.a $out/lib 196 ''; 197 198 passthru = let 199 pythonPackages = callPackage ../../../../../top-level/python-packages.nix {python=self; overrides=packageOverrides;}; 200 in rec { 201 inherit libPrefix sitePackages x11Support hasDistutilsCxxPatch; 202 executable = libPrefix; 203 buildEnv = callPackage ../../wrapper.nix { python = self; }; 204 withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;}; 205 pkgs = pythonPackages; 206 isPy2 = true; 207 isPy27 = true; 208 interpreter = "${self}/bin/${executable}"; 209 }; 210 211 enableParallelBuilding = true; 212 213 meta = { 214 homepage = http://python.org; 215 description = "A high-level dynamically-typed programming language"; 216 longDescription = '' 217 Python is a remarkably powerful dynamic programming language that 218 is used in a wide variety of application domains. Some of its key 219 distinguishing features include: clear, readable syntax; strong 220 introspection capabilities; intuitive object orientation; natural 221 expression of procedural code; full modularity, supporting 222 hierarchical packages; exception-based error handling; and very 223 high level dynamic data types. 224 ''; 225 license = stdenv.lib.licenses.psfl; 226 platforms = stdenv.lib.platforms.all; 227 maintainers = with stdenv.lib.maintainers; [ chaoflow domenkozar ]; 228 # Higher priority than Python 3.x so that `/bin/python` points to `/bin/python2` 229 # in case both 2 and 3 are installed. 230 priority = -100; 231 }; 232 }