summary refs log tree commit diff
path: root/pkgs/development/interpreters/python/cpython
diff options
context:
space:
mode:
authorFrederik Rietdijk <fridh@fridh.nl>2016-07-07 14:05:05 +0200
committerFrederik Rietdijk <fridh@fridh.nl>2016-07-28 17:10:15 +0200
commit1da6775775e3695ff206bdcd3fca945bf5331101 (patch)
tree9da34dc021261438f4bd6603ea0980a9bbb75c9f /pkgs/development/interpreters/python/cpython
parent86393cfc205c4f8d474b928878b45b118f2c7b16 (diff)
downloadnixlib-1da6775775e3695ff206bdcd3fca945bf5331101.tar
nixlib-1da6775775e3695ff206bdcd3fca945bf5331101.tar.gz
nixlib-1da6775775e3695ff206bdcd3fca945bf5331101.tar.bz2
nixlib-1da6775775e3695ff206bdcd3fca945bf5331101.tar.lz
nixlib-1da6775775e3695ff206bdcd3fca945bf5331101.tar.xz
nixlib-1da6775775e3695ff206bdcd3fca945bf5331101.tar.zst
nixlib-1da6775775e3695ff206bdcd3fca945bf5331101.zip
Python: move interpreters
Move Python interpreters (CPython, PyPy) to same folder and share
layout.
Diffstat (limited to 'pkgs/development/interpreters/python/cpython')
-rw-r--r--pkgs/development/interpreters/python/cpython/2.6/default.nix218
-rw-r--r--pkgs/development/interpreters/python/cpython/2.6/nix-store-mtime.patch12
-rw-r--r--pkgs/development/interpreters/python/cpython/2.6/python2.6-fix-parallel-make.patch37
-rw-r--r--pkgs/development/interpreters/python/cpython/2.6/search-path.patch27
-rw-r--r--pkgs/development/interpreters/python/cpython/2.6/setup-hook.sh15
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/2.5.2-ctypes-util-find_library.patch34
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/2.5.2-tkinter-x11.patch27
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/2.6.2-ssl-threads.patch13
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/2.6.5-FD_SETSIZE.patch41
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/2.6.5-export-PySignal_SetWakeupFd.patch11
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/2.6.5-ncurses-abi6.patch16
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/2.7.3-dbm.patch27
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/2.7.3-dylib.patch10
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/2.7.3-getpath-exe-extension.patch31
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/2.7.3-no-libm.patch11
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/default.nix284
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/deterministic-build.patch36
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/nix-store-mtime.patch12
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/no-ldconfig.patch99
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/properly-detect-curses.patch116
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/search-path.patch27
-rw-r--r--pkgs/development/interpreters/python/cpython/2.7/setup-hook.sh15
-rw-r--r--pkgs/development/interpreters/python/cpython/3.3/default.nix118
-rw-r--r--pkgs/development/interpreters/python/cpython/3.3/setup-hook.sh15
-rw-r--r--pkgs/development/interpreters/python/cpython/3.4/default.nix141
-rw-r--r--pkgs/development/interpreters/python/cpython/3.4/setup-hook.sh15
-rw-r--r--pkgs/development/interpreters/python/cpython/3.5/default.nix141
-rw-r--r--pkgs/development/interpreters/python/cpython/3.5/setup-hook.sh15
-rw-r--r--pkgs/development/interpreters/python/cpython/3.6/default.nix145
-rw-r--r--pkgs/development/interpreters/python/cpython/3.6/setup-hook.sh15
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/2.6-html.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/2.6-pdf-a4.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/2.6-pdf-letter.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/2.6-text.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/2.7-html.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/2.7-pdf-a4.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/2.7-pdf-letter.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/2.7-text.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/3.3-html.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/3.3-pdf-a4.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/3.3-pdf-letter.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/3.3-text.nix18
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/default.nix53
-rwxr-xr-xpkgs/development/interpreters/python/cpython/docs/generate.sh59
-rw-r--r--pkgs/development/interpreters/python/cpython/docs/template.nix18
45 files changed, 2070 insertions, 0 deletions
diff --git a/pkgs/development/interpreters/python/cpython/2.6/default.nix b/pkgs/development/interpreters/python/cpython/2.6/default.nix
new file mode 100644
index 000000000000..e5c33cd7b2bd
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.6/default.nix
@@ -0,0 +1,218 @@
+{ stdenv, fetchurl, zlib ? null, zlibSupport ? true, bzip2, less, includeModules ? false
+, sqlite, tcl, tk, xlibsWrapper, openssl, readline, db, ncurses, gdbm, self, callPackage
+, python26Packages }:
+
+assert zlibSupport -> zlib != null;
+
+with stdenv.lib;
+
+let
+  majorVersion = "2.6";
+  version = "${majorVersion}.9";
+
+  src = fetchurl {
+    url = "http://www.python.org/ftp/python/${version}/Python-${version}.tar.xz";
+    sha256 = "0hbfs2691b60c7arbysbzr0w9528d5pl8a4x7mq5psh6a2cvprya";
+  };
+
+  patches =
+    [ # Look in C_INCLUDE_PATH and LIBRARY_PATH for stuff.
+      ./search-path.patch
+
+      # Python recompiles a Python if the mtime stored *in* the
+      # pyc/pyo file differs from the mtime of the source file.  This
+      # doesn't work in Nix because Nix changes the mtime of files in
+      # the Nix store to 1.  So treat that as a special case.
+      ./nix-store-mtime.patch
+
+      # http://bugs.python.org/issue10013
+      ./python2.6-fix-parallel-make.patch
+    ];
+    
+  preConfigure = ''
+      # Purity.
+      for i in /usr /sw /opt /pkg; do
+        substituteInPlace ./setup.py --replace $i /no-such-path
+      done
+    '' + optionalString (stdenv ? cc && stdenv.cc.libc != null) ''
+      for i in Lib/plat-*/regen; do
+        substituteInPlace $i --replace /usr/include/ ${stdenv.cc.libc}/include/
+      done
+    '' + optionalString stdenv.isCygwin ''
+      # On Cygwin, `make install' tries to read this Makefile.
+      mkdir -p $out/lib/python${majorVersion}/config
+      touch $out/lib/python${majorVersion}/config/Makefile
+      mkdir -p $out/include/python${majorVersion}
+      touch $out/include/python${majorVersion}/pyconfig.h
+    '';
+
+  configureFlags = "--enable-shared --with-threads --enable-unicode=ucs4";
+
+  buildInputs =
+    optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc ++
+    [ bzip2 openssl ]++ optionals includeModules [ db openssl ncurses gdbm readline xlibsWrapper tcl tk sqlite ]
+    ++ optional zlibSupport zlib;
+
+  propagatedBuildInputs = [ less ];
+
+  mkPaths = paths: {
+    C_INCLUDE_PATH = makeSearchPathOutput "dev" "include" paths;
+    LIBRARY_PATH = makeLibraryPath paths;
+  };
+
+  # Build the basic Python interpreter without modules that have
+  # external dependencies.
+  python = stdenv.mkDerivation {
+    name = "python${if includeModules then "" else "-minimal"}-${version}";
+    pythonVersion = majorVersion;
+
+    inherit majorVersion version src patches buildInputs propagatedBuildInputs
+            preConfigure configureFlags;
+
+    inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
+
+    NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2";
+
+    setupHook = ./setup-hook.sh;
+
+    postInstall =
+      ''
+        # needed for some packages, especially packages that backport
+        # functionality to 2.x from 3.x
+        for item in $out/lib/python${majorVersion}/test/*; do
+          if [[ "$item" != */test_support.py* ]]; then
+            rm -rf "$item"
+          fi
+        done
+        touch $out/lib/python${majorVersion}/test/__init__.py
+        ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb
+        ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb${majorVersion}
+        mv $out/share/man/man1/{python.1,python2.6.1}
+        ln -s $out/share/man/man1/{python2.6.1,python.1}
+
+        paxmark E $out/bin/python${majorVersion}
+
+        ${ optionalString includeModules "$out/bin/python ./setup.py build_ext"}
+      '';
+
+    passthru = rec {
+      inherit zlibSupport;
+      isPy2 = true;
+      isPy26 = true;
+      buildEnv = callPackage ../../wrapper.nix { python = self; };
+      withPackages = import ../../with-packages.nix { inherit buildEnv; pythonPackages = python26Packages; };
+      libPrefix = "python${majorVersion}";
+      executable = libPrefix;
+      sitePackages = "lib/${libPrefix}/site-packages";
+      interpreter = "${self}/bin/${executable}";
+    };
+
+    enableParallelBuilding = true;
+
+    meta = {
+      homepage = "http://python.org";
+      description = "A high-level dynamically-typed programming language";
+      longDescription = ''
+        Python is a remarkably powerful dynamic programming language that
+        is used in a wide variety of application domains. Some of its key
+        distinguishing features include: clear, readable syntax; strong
+        introspection capabilities; intuitive object orientation; natural
+        expression of procedural code; full modularity, supporting
+        hierarchical packages; exception-based error handling; and very
+        high level dynamic data types.
+      '';
+      license = stdenv.lib.licenses.psfl;
+      platforms = stdenv.lib.platforms.all;
+      maintainers = with stdenv.lib.maintainers; [ chaoflow domenkozar ];
+      # If you want to use Python 2.6, remove "broken = true;" at your own
+      # risk.  Python 2.6 has known security vulnerabilities is not receiving
+      # security updates as of October 2013.
+      broken = true;
+    };
+  };
+
+
+  # This function builds a Python module included in the main Python
+  # distribution in a separate derivation.
+  buildInternalPythonModule =
+    { moduleName
+    , internalName ? "_" + moduleName
+    , deps
+    }:
+    if includeModules then null else stdenv.mkDerivation rec {
+      name = "python-${moduleName}-${python.version}";
+
+      inherit src patches preConfigure configureFlags;
+
+      buildInputs = [ python ] ++ deps;
+
+      inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
+
+      buildPhase =
+        ''
+          substituteInPlace setup.py --replace 'self.extensions = extensions' \
+            'self.extensions = [ext for ext in self.extensions if ext.name in ["${internalName}"]]'
+
+          python ./setup.py build_ext
+          [ -z "$(find build -name '*_failed.so' -print)" ]
+        '';
+
+      installPhase =
+        ''
+          dest=$out/lib/${python.libPrefix}/site-packages
+          mkdir -p $dest
+          cp -p $(find . -name "*.${if stdenv.isCygwin then "dll" else "so"}") $dest/
+        '';
+    };
+
+
+  # The Python modules included in the main Python distribution, built
+  # as separate derivations.
+  modules = {
+
+    bsddb = buildInternalPythonModule {
+      moduleName = "bsddb";
+      deps = [ db ];
+    };
+
+    crypt = buildInternalPythonModule {
+      moduleName = "crypt";
+      internalName = "crypt";
+      deps = optional (stdenv ? glibc) stdenv.glibc;
+    };
+
+    curses = buildInternalPythonModule {
+      moduleName = "curses";
+      deps = [ ncurses ];
+    };
+
+    curses_panel = buildInternalPythonModule {
+      moduleName = "curses_panel";
+      deps = [ ncurses modules.curses ];
+    };
+
+    gdbm = buildInternalPythonModule {
+      moduleName = "gdbm";
+      internalName = "gdbm";
+      deps = [ gdbm ];
+    };
+
+    sqlite3 = buildInternalPythonModule {
+      moduleName = "sqlite3";
+      deps = [ sqlite ];
+    };
+
+    tkinter = buildInternalPythonModule {
+      moduleName = "tkinter";
+      deps = [ tcl tk xlibsWrapper ];
+    };
+
+    readline = buildInternalPythonModule {
+      moduleName = "readline";
+      internalName = "readline";
+      deps = [ readline ];
+    };
+
+  };
+
+in python // { inherit modules; }
diff --git a/pkgs/development/interpreters/python/cpython/2.6/nix-store-mtime.patch b/pkgs/development/interpreters/python/cpython/2.6/nix-store-mtime.patch
new file mode 100644
index 000000000000..83f3fea1931b
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.6/nix-store-mtime.patch
@@ -0,0 +1,12 @@
+diff -ru -x '*~' Python-2.7.1-orig/Python/import.c Python-2.7.1/Python/import.c
+--- Python-2.7.1-orig/Python/import.c	2010-05-20 20:37:55.000000000 +0200
++++ Python-2.7.1/Python/import.c	2011-01-04 15:55:11.000000000 +0100
+@@ -751,7 +751,7 @@
+         return NULL;
+     }
+     pyc_mtime = PyMarshal_ReadLongFromFile(fp);
+-    if (pyc_mtime != mtime) {
++    if (pyc_mtime != mtime && mtime != 1) {
+         if (Py_VerboseFlag)
+             PySys_WriteStderr("# %s has bad mtime\n", cpathname);
+         fclose(fp);
diff --git a/pkgs/development/interpreters/python/cpython/2.6/python2.6-fix-parallel-make.patch b/pkgs/development/interpreters/python/cpython/2.6/python2.6-fix-parallel-make.patch
new file mode 100644
index 000000000000..c43e141f9afb
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.6/python2.6-fix-parallel-make.patch
@@ -0,0 +1,37 @@
+diff -up Python-2.7/Makefile.pre.in.fix-parallel-make Python-2.7/Makefile.pre.in
+--- Python-2.7/Makefile.pre.in.fix-parallel-make	2010-07-22 15:01:39.567996932 -0400
++++ Python-2.7/Makefile.pre.in	2010-07-22 15:47:02.437998509 -0400
+@@ -207,6 +207,7 @@ SIGNAL_OBJS=	@SIGNAL_OBJS@
+ 
+ ##########################################################################
+ # Grammar
++GRAMMAR_STAMP=	$(srcdir)/grammar-stamp
+ GRAMMAR_H=	$(srcdir)/Include/graminit.h
+ GRAMMAR_C=	$(srcdir)/Python/graminit.c
+ GRAMMAR_INPUT=	$(srcdir)/Grammar/Grammar
+@@ -530,10 +531,24 @@ Modules/getpath.o: $(srcdir)/Modules/get
+ Modules/python.o: $(srcdir)/Modules/python.c
+ 	$(MAINCC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/python.c
+ 
++# GNU "make" interprets rules with two dependents as two copies of the rule.
++# 
++# In a parallel build this can lead to pgen being run twice, once for each of
++# GRAMMAR_H and GRAMMAR_C, leading to race conditions in which the compiler
++# reads a partially-overwritten copy of one of these files, leading to syntax
++# errors (or linker errors if the fragment happens to be syntactically valid C)
++#
++# See http://www.gnu.org/software/hello/manual/automake/Multiple-Outputs.html
++# for more information
++#
++# Introduce ".grammar-stamp" as a contrived single output from PGEN to avoid
++# this:
++$(GRAMMAR_H) $(GRAMMAR_C): $(GRAMMAR_STAMP)
+ 
+-$(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
++$(GRAMMAR_STAMP): $(PGEN) $(GRAMMAR_INPUT)
+ 		-@$(INSTALL) -d Include
+ 		-$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
++		touch $(GRAMMAR_STAMP)
+ 
+ $(PGEN):	$(PGENOBJS)
+ 		$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
diff --git a/pkgs/development/interpreters/python/cpython/2.6/search-path.patch b/pkgs/development/interpreters/python/cpython/2.6/search-path.patch
new file mode 100644
index 000000000000..2e7b7526c0ce
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.6/search-path.patch
@@ -0,0 +1,27 @@
+diff -rc Python-2.4.4-orig/setup.py Python-2.4.4/setup.py
+*** Python-2.4.4-orig/setup.py	2006-10-08 19:41:25.000000000 +0200
+--- Python-2.4.4/setup.py	2007-05-27 16:04:54.000000000 +0200
+***************
+*** 279,288 ****
+          # Check for AtheOS which has libraries in non-standard locations
+          if platform == 'atheos':
+              lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
+-             lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
+              inc_dirs += ['/system/include', '/atheos/autolnk/include']
+-             inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
+  
+          # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
+          if platform in ['osf1', 'unixware7', 'openunix8']:
+              lib_dirs += ['/usr/ccs/lib']
+--- 279,289 ----
+          # Check for AtheOS which has libraries in non-standard locations
+          if platform == 'atheos':
+              lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
+              inc_dirs += ['/system/include', '/atheos/autolnk/include']
+  
++         lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
++         inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
++         
+          # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
+          if platform in ['osf1', 'unixware7', 'openunix8']:
+              lib_dirs += ['/usr/ccs/lib']
diff --git a/pkgs/development/interpreters/python/cpython/2.6/setup-hook.sh b/pkgs/development/interpreters/python/cpython/2.6/setup-hook.sh
new file mode 100644
index 000000000000..4caff9c9d846
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.6/setup-hook.sh
@@ -0,0 +1,15 @@
+addPythonPath() {
+    addToSearchPathWithCustomDelimiter : PYTHONPATH $1/lib/python2.6/site-packages
+}
+
+toPythonPath() {
+    local paths="$1"
+    local result=
+    for i in $paths; do
+        p="$i/lib/python2.6/site-packages"
+        result="${result}${result:+:}$p"
+    done
+    echo $result
+}
+
+envHooks+=(addPythonPath)
diff --git a/pkgs/development/interpreters/python/cpython/2.7/2.5.2-ctypes-util-find_library.patch b/pkgs/development/interpreters/python/cpython/2.7/2.5.2-ctypes-util-find_library.patch
new file mode 100644
index 000000000000..22bc0f7ced0a
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/2.5.2-ctypes-util-find_library.patch
@@ -0,0 +1,34 @@
+--- origsrc/Lib/ctypes/util.py	2007-09-14 15:05:26.000000000 -0500
++++ src/Lib/ctypes/util.py	2008-11-25 17:54:47.319296200 -0600
+@@ -41,6 +41,20 @@
+                 continue
+         return None
+ 
++elif sys.platform == "cygwin":
++    def find_library(name):
++        for libdir in ['/usr/lib', '/usr/local/lib']:
++            for libext in ['lib%s.dll.a' % name, 'lib%s.a' % name]:
++                implib = os.path.join(libdir, libext)
++                if not os.path.exists(implib):
++                    continue
++                cmd = "dlltool -I " + implib + " 2>/dev/null"
++                res = os.popen(cmd).read().replace("\n","")
++                if not res:
++                    continue
++                return res
++        return None
++
+ elif os.name == "posix":
+     # Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
+     import re, tempfile, errno
+@@ -157,6 +173,10 @@
+             print cdll.LoadLibrary("libcrypto.dylib")
+             print cdll.LoadLibrary("libSystem.dylib")
+             print cdll.LoadLibrary("System.framework/System")
++        elif sys.platform == "cygwin":
++            print cdll.LoadLibrary("cygbz2-1.dll") 
++            print find_library("crypt")
++            print cdll.LoadLibrary("cygcrypt-0.dll") 
+         else:
+             print cdll.LoadLibrary("libm.so")
+             print cdll.LoadLibrary("libcrypt.so")
diff --git a/pkgs/development/interpreters/python/cpython/2.7/2.5.2-tkinter-x11.patch b/pkgs/development/interpreters/python/cpython/2.7/2.5.2-tkinter-x11.patch
new file mode 100644
index 000000000000..28b6dafc3f15
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/2.5.2-tkinter-x11.patch
@@ -0,0 +1,27 @@
+--- origsrc/setup.py	2008-02-04 17:41:02.000000000 -0600
++++ src/setup.py	2008-07-02 02:11:28.671875000 -0500
+@@ -1277,12 +1279,6 @@
+             include_dirs.append('/usr/X11/include')
+             added_lib_dirs.append('/usr/X11/lib')
+ 
+-        # If Cygwin, then verify that X is installed before proceeding
+-        if host_platform == 'cygwin':
+-            x11_inc = find_file('X11/Xlib.h', [], include_dirs)
+-            if x11_inc is None:
+-                return
+-
+         # Check for BLT extension
+         if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
+                                            'BLT8.0'):
+@@ -1300,9 +1296,8 @@
+         if host_platform in ['aix3', 'aix4']:
+             libs.append('ld')
+ 
+-        # Finally, link with the X11 libraries (not appropriate on cygwin)
+-        if host_platform != "cygwin":
+-            libs.append('X11')
++        # Finally, link with the X11 libraries
++        libs.append('X11')
+ 
+         ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
+                         define_macros=[('WITH_APPINIT', 1)] + defs,
diff --git a/pkgs/development/interpreters/python/cpython/2.7/2.6.2-ssl-threads.patch b/pkgs/development/interpreters/python/cpython/2.7/2.6.2-ssl-threads.patch
new file mode 100644
index 000000000000..bef137efda7b
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/2.6.2-ssl-threads.patch
@@ -0,0 +1,13 @@
+--- origsrc/Modules/_ssl.c	2009-01-26 10:55:41.000000000 -0600
++++ src/Modules/_ssl.c	2009-08-20 00:04:59.346816700 -0500
+@@ -15,6 +15,10 @@
+ 
+ #include "Python.h"
+ 
++#ifdef __CYGWIN__
++#undef WITH_THREAD
++#endif
++
+ #ifdef WITH_THREAD
+ #include "pythread.h"
+ #define PySSL_BEGIN_ALLOW_THREADS { \
diff --git a/pkgs/development/interpreters/python/cpython/2.7/2.6.5-FD_SETSIZE.patch b/pkgs/development/interpreters/python/cpython/2.7/2.6.5-FD_SETSIZE.patch
new file mode 100644
index 000000000000..d1dae8c47dc1
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/2.6.5-FD_SETSIZE.patch
@@ -0,0 +1,41 @@
+--- Python-2.6.5.orig/Modules/selectmodule.c	2012-02-02 22:35:21.835125000 -0500
++++ Python-2.6.5/Modules/selectmodule.c	2012-02-02 22:41:41.210125000 -0500
+@@ -6,6 +6,21 @@
+    >= 0.
+ */
+ 
++/* Windows #defines FD_SETSIZE to 64 if FD_SETSIZE isn't already defined.
++   64 is too small (too many people have bumped into that limit).
++   Here we boost it.
++
++   Cygwin also defines FD_SETSIZE to 64, so also increase the limit on
++   Cygwin.  We must do this before sys/types.h is included, which otherwise
++   sets FD_SETSIZE to the default.
++
++   Users who want even more than the boosted limit should #define
++   FD_SETSIZE higher before this; e.g., via compiler /D switch.
++*/
++#if (defined(MS_WINDOWS) || defined(__CYGWIN__)) && !defined(FD_SETSIZE)
++#define FD_SETSIZE 512
++#endif
++
+ #include "Python.h"
+ #include <structmember.h>
+ 
+@@ -16,16 +31,6 @@
+ #undef HAVE_BROKEN_POLL
+ #endif
+ 
+-/* Windows #defines FD_SETSIZE to 64 if FD_SETSIZE isn't already defined.
+-   64 is too small (too many people have bumped into that limit).
+-   Here we boost it.
+-   Users who want even more than the boosted limit should #define
+-   FD_SETSIZE higher before this; e.g., via compiler /D switch.
+-*/
+-#if defined(MS_WINDOWS) && !defined(FD_SETSIZE)
+-#define FD_SETSIZE 512
+-#endif
+-
+ #if defined(HAVE_POLL_H)
+ #include <poll.h>
+ #elif defined(HAVE_SYS_POLL_H)
diff --git a/pkgs/development/interpreters/python/cpython/2.7/2.6.5-export-PySignal_SetWakeupFd.patch b/pkgs/development/interpreters/python/cpython/2.7/2.6.5-export-PySignal_SetWakeupFd.patch
new file mode 100644
index 000000000000..ea696978236a
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/2.6.5-export-PySignal_SetWakeupFd.patch
@@ -0,0 +1,11 @@
+--- origsrc/Include/pyerrors.h	2008-06-08 23:58:54.000000000 -0500
++++ src/Include/pyerrors.h	2010-05-12 04:19:31.535297200 -0500
+@@ -232,7 +232,7 @@ PyAPI_FUNC(int) PyErr_CheckSignals(void)
+ PyAPI_FUNC(void) PyErr_SetInterrupt(void);
+ 
+ /* In signalmodule.c */
+-int PySignal_SetWakeupFd(int fd);
++PyAPI_FUNC(int) PySignal_SetWakeupFd(int fd);
+ 
+ /* Support for adding program text to SyntaxErrors */
+ PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
diff --git a/pkgs/development/interpreters/python/cpython/2.7/2.6.5-ncurses-abi6.patch b/pkgs/development/interpreters/python/cpython/2.7/2.6.5-ncurses-abi6.patch
new file mode 100644
index 000000000000..e1cf5ad4bbf9
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/2.6.5-ncurses-abi6.patch
@@ -0,0 +1,16 @@
+--- origsrc/Include/py_curses.h	2009-09-06 16:23:05.000000000 -0500
++++ src/Include/py_curses.h	2010-04-14 15:21:23.008971400 -0500
+@@ -17,6 +17,13 @@
+ #define NCURSES_OPAQUE 0
+ #endif /* __APPLE__ */
+ 
++#ifdef __CYGWIN__
++/* the following define is necessary for Cygwin; without it, the
++   Cygwin-supplied ncurses.h sets NCURSES_OPAQUE to 1, and then Python
++   can't get at the WINDOW flags field. */
++#define NCURSES_INTERNALS
++#endif /* __CYGWIN__ */
++
+ #ifdef __FreeBSD__
+ /*
+ ** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
diff --git a/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dbm.patch b/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dbm.patch
new file mode 100644
index 000000000000..bfaeb37c287d
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dbm.patch
@@ -0,0 +1,27 @@
+--- origsrc/setup.py.orig	2012-11-27 10:20:47.442395900 -0500
++++ src/setup.py	2012-11-27 10:53:15.583020900 -0500
+@@ -1141,7 +1141,7 @@
+ 
+         dbm_order = ['gdbm']
+         # The standard Unix dbm module:
+-        if host_platform not in ['cygwin']:
++        if host_platform not in ['win32']:
+             config_args = [arg.strip("'")
+                            for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
+             dbm_args = [arg for arg in config_args
+@@ -1192,6 +1192,15 @@
+                                     ],
+                                 libraries = gdbm_libs)
+                             break
++                        if find_file("ndbm.h", inc_dirs, []) is not None:
++                            print("building dbm using gdbm")
++                            dbmext = Extension(
++                                'dbm', ['dbmmodule.c'],
++                                define_macros=[
++                                    ('HAVE_NDBM_H', None),
++                                    ],
++                                libraries = gdbm_libs)
++                            break
+                 elif cand == "bdb":
+                     if db_incs is not None:
+                         print "building dbm using bdb"
diff --git a/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dylib.patch b/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dylib.patch
new file mode 100644
index 000000000000..6e1fc8b53e83
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dylib.patch
@@ -0,0 +1,10 @@
+--- origsrc/Lib/distutils/unixccompiler.py.orig	2012-11-27 07:44:15.409993500 -0500
++++ src/Lib/distutils/unixccompiler.py	2012-11-27 08:09:57.801770900 -0500
+@@ -141,6 +141,7 @@
+     static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
+     if sys.platform == "cygwin":
+         exe_extension = ".exe"
++        dylib_lib_extension = ".dll.a"
+ 
+     def preprocess(self, source,
+                    output_file=None, macros=None, include_dirs=None,
diff --git a/pkgs/development/interpreters/python/cpython/2.7/2.7.3-getpath-exe-extension.patch b/pkgs/development/interpreters/python/cpython/2.7/2.7.3-getpath-exe-extension.patch
new file mode 100644
index 000000000000..68f6921ba6aa
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/2.7.3-getpath-exe-extension.patch
@@ -0,0 +1,31 @@
+--- origsrc/Modules/getpath.c.orig	2012-11-27 12:07:56.098645900 -0500
++++ src/Modules/getpath.c	2012-11-27 12:10:11.254895900 -0500
+@@ -436,6 +436,28 @@
+                         if (isxfile(progpath))
+                                 break;
+ 
++#ifdef __CYGWIN__
++                        /*
++                         * Cygwin automatically removes the ".exe" extension from argv[0]
++                         * to make programs feel like they are in a more Unix-like
++                         * environment.  Unfortunately, this can make it problemmatic for
++                         * Cygwin to distinguish between a directory and an executable with
++                         * the same name excluding the ".exe" extension.  For example, the
++                         * Cygwin Python build directory has a "Python" directory and a
++                         * "python.exe" executable.  This causes isxfile() to erroneously
++                         * return false.  If isdir() returns true and there is enough space
++                         * to append the ".exe" extension, then we try again with the
++                         * extension appended.
++                         */
++#define EXE ".exe"
++                        if (isdir(progpath) && strlen(progpath) + strlen(EXE) <= MAXPATHLEN)
++                        {
++                            strcat(progpath, EXE);
++                            if (isxfile(progpath))
++                                break;
++                        }
++#endif /* __CYGWIN__ */
++
+                         if (!delim) {
+                                 progpath[0] = '\0';
+                                 break;
diff --git a/pkgs/development/interpreters/python/cpython/2.7/2.7.3-no-libm.patch b/pkgs/development/interpreters/python/cpython/2.7/2.7.3-no-libm.patch
new file mode 100644
index 000000000000..55281db6768f
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/2.7.3-no-libm.patch
@@ -0,0 +1,11 @@
+--- origsrc/setup.py.orig	2012-11-27 09:28:34.051770900 -0500
++++ src/setup.py	2012-11-27 09:28:47.239270900 -0500
+@@ -470,7 +470,7 @@
+ 
+         # Check for MacOS X, which doesn't need libm.a at all
+         math_libs = ['m']
+-        if host_platform in ['darwin', 'beos']:
++        if host_platform in ['darwin', 'beos', 'cygwin']:
+             math_libs = []
+ 
+         # XXX Omitted modules: gl, pure, dl, SGI-specific modules
diff --git a/pkgs/development/interpreters/python/cpython/2.7/default.nix b/pkgs/development/interpreters/python/cpython/2.7/default.nix
new file mode 100644
index 000000000000..96c098c82dca
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/default.nix
@@ -0,0 +1,284 @@
+{ stdenv, fetchurl, self, callPackage, python27Packages
+, bzip2, openssl, gettext
+, less
+
+, includeModules ? false
+
+, db, gdbm, ncurses, sqlite, readline
+
+, tcl ? null, tk ? null, xlibsWrapper ? null, libX11 ? null, x11Support ? !stdenv.isCygwin
+, zlib ? null, zlibSupport ? true
+, expat, libffi
+
+, CF, configd
+}:
+
+assert zlibSupport -> zlib != null;
+assert x11Support -> tcl != null
+                  && tk != null
+                  && xlibsWrapper != null
+                  && libX11 != null;
+
+with stdenv.lib;
+
+let
+  majorVersion = "2.7";
+  version = "${majorVersion}.12";
+
+  src = fetchurl {
+    url = "http://www.python.org/ftp/python/${version}/Python-${version}.tar.xz";
+    sha256 = "0y7rl603vmwlxm6ilkhc51rx2mfj14ckcz40xxgs0ljnvlhp30yp";
+  };
+
+  patches =
+    [ # Look in C_INCLUDE_PATH and LIBRARY_PATH for stuff.
+      ./search-path.patch
+
+      # Python recompiles a Python if the mtime stored *in* the
+      # pyc/pyo file differs from the mtime of the source file.  This
+      # doesn't work in Nix because Nix changes the mtime of files in
+      # the Nix store to 1.  So treat that as a special case.
+      ./nix-store-mtime.patch
+
+      # patch python to put zero timestamp into pyc
+      # if DETERMINISTIC_BUILD env var is set
+      ./deterministic-build.patch
+
+      ./properly-detect-curses.patch
+    ] ++ optionals stdenv.isLinux [
+
+      # Disable the use of ldconfig in ctypes.util.find_library (since
+      # ldconfig doesn't work on NixOS), and don't use
+      # ctypes.util.find_library during the loading of the uuid module
+      # (since it will do a futile invocation of gcc (!) to find
+      # libuuid, slowing down program startup a lot).
+      ./no-ldconfig.patch
+
+    ] ++ optionals stdenv.isCygwin [
+      ./2.5.2-ctypes-util-find_library.patch
+      ./2.5.2-tkinter-x11.patch
+      ./2.6.2-ssl-threads.patch
+      ./2.6.5-export-PySignal_SetWakeupFd.patch
+      ./2.6.5-FD_SETSIZE.patch
+      ./2.6.5-ncurses-abi6.patch
+      ./2.7.3-dbm.patch
+      ./2.7.3-dylib.patch
+      ./2.7.3-getpath-exe-extension.patch
+      ./2.7.3-no-libm.patch
+    ];
+
+  preConfigure = ''
+      # Purity.
+      for i in /usr /sw /opt /pkg; do
+        substituteInPlace ./setup.py --replace $i /no-such-path
+      done
+    '' + optionalString (stdenv ? cc && stdenv.cc.libc != null) ''
+      for i in Lib/plat-*/regen; do
+        substituteInPlace $i --replace /usr/include/ ${stdenv.cc.libc}/include/
+      done
+    '' + optionalString stdenv.isDarwin ''
+      substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
+      substituteInPlace Lib/multiprocessing/__init__.py \
+        --replace 'os.popen(comm)' 'os.popen("nproc")'
+    '';
+
+  configureFlags = [
+    "--enable-shared"
+    "--with-threads"
+    "--enable-unicode=ucs4"
+  ] ++ optionals stdenv.isCygwin [
+    "--with-system-ffi"
+    "--with-system-expat"
+    "ac_cv_func_bind_textdomain_codeset=yes"
+  ] ++ optionals stdenv.isDarwin [
+    "--disable-toolbox-glue"
+  ];
+
+  postConfigure = if stdenv.isCygwin then ''
+    sed -i Makefile -e 's,PYTHONPATH="$(srcdir),PYTHONPATH="$(abs_srcdir),'
+  '' else null;
+
+  buildInputs =
+    optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc ++
+    [ bzip2 openssl ]
+    ++ optionals stdenv.isCygwin [ expat libffi ]
+    ++ optionals includeModules (
+        [ db gdbm ncurses sqlite readline
+        ] ++ optionals x11Support [ tcl tk xlibsWrapper libX11 ]
+    )
+    ++ optional zlibSupport zlib
+    ++ optional stdenv.isDarwin CF;
+
+  propagatedBuildInputs = [ less ] ++ optional stdenv.isDarwin configd;
+
+  mkPaths = paths: {
+    C_INCLUDE_PATH = makeSearchPathOutput "dev" "include" paths;
+    LIBRARY_PATH = makeLibraryPath paths;
+  };
+
+  # Build the basic Python interpreter without modules that have
+  # external dependencies.
+  python = stdenv.mkDerivation {
+    name = "python-${version}";
+    pythonVersion = majorVersion;
+
+    inherit majorVersion version src patches buildInputs propagatedBuildInputs
+            preConfigure configureFlags;
+
+    LDFLAGS = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
+    inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
+
+    NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2";
+    DETERMINISTIC_BUILD = 1;
+
+    setupHook = ./setup-hook.sh;
+
+    postInstall =
+      ''
+        # needed for some packages, especially packages that backport
+        # functionality to 2.x from 3.x
+        for item in $out/lib/python${majorVersion}/test/*; do
+          if [[ "$item" != */test_support.py* ]]; then
+            rm -rf "$item"
+          else
+            echo $item
+          fi
+        done
+        touch $out/lib/python${majorVersion}/test/__init__.py
+        ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb
+        ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb${majorVersion}
+        ln -s $out/share/man/man1/{python2.7.1.gz,python.1.gz}
+
+        paxmark E $out/bin/python${majorVersion}
+
+        ${optionalString includeModules "$out/bin/python ./setup.py build_ext"}
+
+        rm "$out"/lib/python*/plat-*/regen # refers to glibc.dev
+      '';
+
+    passthru = rec {
+      inherit zlibSupport;
+      isPy2 = true;
+      isPy27 = true;
+      buildEnv = callPackage ../../wrapper.nix { python = self; };
+      withPackages = import ../../with-packages.nix { inherit buildEnv; pythonPackages = python27Packages; };
+      libPrefix = "python${majorVersion}";
+      executable = libPrefix;
+      sitePackages = "lib/${libPrefix}/site-packages";
+      interpreter = "${self}/bin/${executable}";
+    };
+
+    enableParallelBuilding = true;
+
+    meta = {
+      homepage = "http://python.org";
+      description = "A high-level dynamically-typed programming language";
+      longDescription = ''
+        Python is a remarkably powerful dynamic programming language that
+        is used in a wide variety of application domains. Some of its key
+        distinguishing features include: clear, readable syntax; strong
+        introspection capabilities; intuitive object orientation; natural
+        expression of procedural code; full modularity, supporting
+        hierarchical packages; exception-based error handling; and very
+        high level dynamic data types.
+      '';
+      license = stdenv.lib.licenses.psfl;
+      platforms = stdenv.lib.platforms.all;
+      maintainers = with stdenv.lib.maintainers; [ chaoflow domenkozar ];
+    };
+  };
+
+
+  # This function builds a Python module included in the main Python
+  # distribution in a separate derivation.
+  buildInternalPythonModule =
+    { moduleName
+    , internalName ? "_" + moduleName
+    , deps
+    }:
+    if includeModules then null else stdenv.mkDerivation rec {
+      name = "python-${moduleName}-${python.version}";
+
+      inherit src patches preConfigure postConfigure configureFlags;
+
+      buildInputs = [ python ] ++ deps;
+
+      # We need to set this for python.buildEnv
+      pythonPath = [];
+
+      inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
+
+      # non-python gdbm has a libintl dependency on i686-cygwin, not on x86_64-cygwin
+      buildPhase = (if (stdenv.system == "i686-cygwin" && moduleName == "gdbm") then ''
+          sed -i setup.py -e "s:libraries = \['gdbm'\]:libraries = ['gdbm', 'intl']:"
+      '' else '''') + ''
+          substituteInPlace setup.py --replace 'self.extensions = extensions' \
+            'self.extensions = [ext for ext in self.extensions if ext.name in ["${internalName}"]]'
+
+          python ./setup.py build_ext
+          [ -z "$(find build -name '*_failed.so' -print)" ]
+        '';
+
+      installPhase =
+        ''
+          dest=$out/lib/${python.libPrefix}/site-packages
+          mkdir -p $dest
+          cp -p $(find . -name "*.${if stdenv.isCygwin then "dll" else "so"}") $dest/
+        '';
+    };
+
+
+  # The Python modules included in the main Python distribution, built
+  # as separate derivations.
+  modules = {
+
+    bsddb = buildInternalPythonModule {
+      moduleName = "bsddb";
+      deps = [ db ];
+    };
+
+    curses = buildInternalPythonModule {
+      moduleName = "curses";
+      deps = [ ncurses ];
+    };
+
+    curses_panel = buildInternalPythonModule {
+      moduleName = "curses_panel";
+      deps = [ ncurses modules.curses ];
+    };
+
+    crypt = buildInternalPythonModule {
+      moduleName = "crypt";
+      internalName = "crypt";
+      deps = optional (stdenv ? glibc) stdenv.glibc;
+    };
+
+    gdbm = buildInternalPythonModule {
+      moduleName = "gdbm";
+      internalName = "gdbm";
+      deps = [ gdbm ] ++ stdenv.lib.optional stdenv.isCygwin gettext;
+    };
+
+    sqlite3 = buildInternalPythonModule {
+      moduleName = "sqlite3";
+      deps = [ sqlite ];
+    };
+
+  } // optionalAttrs x11Support {
+
+    tkinter = if stdenv.isCygwin then null else (buildInternalPythonModule {
+      moduleName = "tkinter";
+      deps = [ tcl tk xlibsWrapper libX11 ];
+    });
+
+  } // {
+
+    readline = buildInternalPythonModule {
+      moduleName = "readline";
+      internalName = "readline";
+      deps = [ readline ];
+    };
+
+  };
+
+in python // { inherit modules; }
diff --git a/pkgs/development/interpreters/python/cpython/2.7/deterministic-build.patch b/pkgs/development/interpreters/python/cpython/2.7/deterministic-build.patch
new file mode 100644
index 000000000000..98d9d339fa11
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/deterministic-build.patch
@@ -0,0 +1,36 @@
+diff -ur orig/Lib/py_compile.py new/Lib/py_compile.py
+--- orig/Lib/py_compile.py
++++ new/Lib/py_compile.py
+@@ -122,7 +122,10 @@
+         cfile = file + (__debug__ and 'c' or 'o')
+     with open(cfile, 'wb') as fc:
+         fc.write('\0\0\0\0')
+-        wr_long(fc, timestamp)
++        if "DETERMINISTIC_BUILD" in os.environ:
++            fc.write('\0\0\0\0')
++        else:
++            wr_long(fc, timestamp)
+         marshal.dump(codeobject, fc)
+         fc.flush()
+         fc.seek(0, 0)
+diff -ur orig/Python/import.c new/Python/import.c
+--- orig/Python/import.c
++++ new/Python/import.c
+@@ -939,10 +939,12 @@
+         return;
+     }
+     /* Now write the true mtime (as a 32-bit field) */
+-    fseek(fp, 4L, 0);
+-    assert(mtime <= 0xFFFFFFFF);
+-    PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
+-    fflush(fp);
++    if (Py_GETENV("DETERMINISTIC_BUILD") == NULL) {
++        fseek(fp, 4L, 0);
++        assert(mtime <= 0xFFFFFFFF);
++        PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
++        fflush(fp);
++    }
+     fclose(fp);
+     if (Py_VerboseFlag)
+         PySys_WriteStderr("# wrote %s\n", cpathname);
+
diff --git a/pkgs/development/interpreters/python/cpython/2.7/nix-store-mtime.patch b/pkgs/development/interpreters/python/cpython/2.7/nix-store-mtime.patch
new file mode 100644
index 000000000000..83f3fea1931b
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/nix-store-mtime.patch
@@ -0,0 +1,12 @@
+diff -ru -x '*~' Python-2.7.1-orig/Python/import.c Python-2.7.1/Python/import.c
+--- Python-2.7.1-orig/Python/import.c	2010-05-20 20:37:55.000000000 +0200
++++ Python-2.7.1/Python/import.c	2011-01-04 15:55:11.000000000 +0100
+@@ -751,7 +751,7 @@
+         return NULL;
+     }
+     pyc_mtime = PyMarshal_ReadLongFromFile(fp);
+-    if (pyc_mtime != mtime) {
++    if (pyc_mtime != mtime && mtime != 1) {
+         if (Py_VerboseFlag)
+             PySys_WriteStderr("# %s has bad mtime\n", cpathname);
+         fclose(fp);
diff --git a/pkgs/development/interpreters/python/cpython/2.7/no-ldconfig.patch b/pkgs/development/interpreters/python/cpython/2.7/no-ldconfig.patch
new file mode 100644
index 000000000000..44c38fb29534
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/no-ldconfig.patch
@@ -0,0 +1,99 @@
+diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
+index b2c514d..a6eca81 100644
+--- a/Lib/ctypes/util.py
++++ b/Lib/ctypes/util.py
+@@ -207,31 +207,7 @@ elif os.name == "posix":
+     else:
+ 
+         def _findSoname_ldconfig(name):
+-            import struct
+-            if struct.calcsize('l') == 4:
+-                machine = os.uname()[4] + '-32'
+-            else:
+-                machine = os.uname()[4] + '-64'
+-            mach_map = {
+-                'x86_64-64': 'libc6,x86-64',
+-                'ppc64-64': 'libc6,64bit',
+-                'sparc64-64': 'libc6,64bit',
+-                's390x-64': 'libc6,64bit',
+-                'ia64-64': 'libc6,IA-64',
+-                }
+-            abi_type = mach_map.get(machine, 'libc6')
+-
+-            # XXX assuming GLIBC's ldconfig (with option -p)
+-            expr = r'\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)
+-            f = os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null')
+-            try:
+-                data = f.read()
+-            finally:
+-                f.close()
+-            res = re.search(expr, data)
+-            if not res:
+-                return None
+-            return res.group(1)
++            return None
+ 
+         def find_library(name):
+             return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
+diff --git a/Lib/uuid.py b/Lib/uuid.py
+index 7432032..9829d18 100644
+--- a/Lib/uuid.py
++++ b/Lib/uuid.py
+@@ -437,57 +437,7 @@ def _netbios_getnode():
+         return ((bytes[0]<<40L) + (bytes[1]<<32L) + (bytes[2]<<24L) +
+                 (bytes[3]<<16L) + (bytes[4]<<8L) + bytes[5])
+ 
+-# Thanks to Thomas Heller for ctypes and for his help with its use here.
+-
+-# If ctypes is available, use it to find system routines for UUID generation.
+ _uuid_generate_time = _UuidCreate = None
+-try:
+-    import ctypes, ctypes.util
+-    import sys
+-
+-    # The uuid_generate_* routines are provided by libuuid on at least
+-    # Linux and FreeBSD, and provided by libc on Mac OS X.
+-    _libnames = ['uuid']
+-    if not sys.platform.startswith('win'):
+-        _libnames.append('c')
+-    for libname in _libnames:
+-        try:
+-            lib = ctypes.CDLL(ctypes.util.find_library(libname))
+-        except:
+-            continue
+-        if hasattr(lib, 'uuid_generate_time'):
+-            _uuid_generate_time = lib.uuid_generate_time
+-            break
+-    del _libnames
+-
+-    # The uuid_generate_* functions are broken on MacOS X 10.5, as noted
+-    # in issue #8621 the function generates the same sequence of values
+-    # in the parent process and all children created using fork (unless
+-    # those children use exec as well).
+-    #
+-    # Assume that the uuid_generate functions are broken from 10.5 onward,
+-    # the test can be adjusted when a later version is fixed.
+-    if sys.platform == 'darwin':
+-        import os
+-        if int(os.uname()[2].split('.')[0]) >= 9:
+-            _uuid_generate_time = None
+-
+-    # On Windows prior to 2000, UuidCreate gives a UUID containing the
+-    # hardware address.  On Windows 2000 and later, UuidCreate makes a
+-    # random UUID and UuidCreateSequential gives a UUID containing the
+-    # hardware address.  These routines are provided by the RPC runtime.
+-    # NOTE:  at least on Tim's WinXP Pro SP2 desktop box, while the last
+-    # 6 bytes returned by UuidCreateSequential are fixed, they don't appear
+-    # to bear any relationship to the MAC address of any network device
+-    # on the box.
+-    try:
+-        lib = ctypes.windll.rpcrt4
+-    except:
+-        lib = None
+-    _UuidCreate = getattr(lib, 'UuidCreateSequential',
+-                          getattr(lib, 'UuidCreate', None))
+-except:
+-    pass
+ 
+ def _unixdll_getnode():
+     """Get the hardware address on Unix using ctypes."""
diff --git a/pkgs/development/interpreters/python/cpython/2.7/properly-detect-curses.patch b/pkgs/development/interpreters/python/cpython/2.7/properly-detect-curses.patch
new file mode 100644
index 000000000000..e2640bab0e9a
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/properly-detect-curses.patch
@@ -0,0 +1,116 @@
+From 6dc83db69b5e29d25ba6d73646ea2e9a1097848a Mon Sep 17 00:00:00 2001
+From: Roumen Petrov <local@example.net>
+Date: Sun, 19 Feb 2012 16:13:24 +0200
+Subject: [PATCH] CROSS-properly detect WINDOW _flags for different ncurses versions
+
+---
+ Include/py_curses.h |    5 +++++
+ configure.ac        |   40 ++++++++++++++++++++++++++++++++++++++--
+ pyconfig.h.in       |    6 ++++++
+ 3 files changed, 49 insertions(+), 2 deletions(-)
+
+diff --git a/Include/py_curses.h b/Include/py_curses.h
+index f2c08f6..a9b5260 100644
+--- a/Include/py_curses.h
++++ b/Include/py_curses.h
+@@ -14,7 +14,9 @@
+ /* the following define is necessary for OS X 10.6; without it, the
+    Apple-supplied ncurses.h sets NCURSES_OPAQUE to 1, and then Python
+    can't get at the WINDOW flags field. */
++/* NOTE configure check if ncurses require such definition
+ #define NCURSES_OPAQUE 0
++*/
+ #endif /* __APPLE__ */
+ 
+ #ifdef __FreeBSD__
+@@ -57,9 +59,12 @@
+ #ifdef HAVE_NCURSES_H
+ /* configure was checking <curses.h>, but we will
+    use <ncurses.h>, which has all these features. */
++/* NOTE configure check for existence of flags
++ * Also flags are visible only if WINDOW structure is not opaque
+ #ifndef WINDOW_HAS_FLAGS
+ #define WINDOW_HAS_FLAGS 1
+ #endif
++*/
+ #ifndef MVWDELCH_IS_EXPRESSION
+ #define MVWDELCH_IS_EXPRESSION 1
+ #endif
+diff --git a/configure.ac b/configure.ac
+index 0a3a186..75f5142 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -4150,15 +4150,51 @@ then
+ fi
+ 
+ AC_MSG_CHECKING(whether WINDOW has _flags)
+-AC_CACHE_VAL(ac_cv_window_has_flags,
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[
+   WINDOW *w;
+   w->_flags = 0;
+ ]])],
+ [ac_cv_window_has_flags=yes],
+-[ac_cv_window_has_flags=no]))
++[ac_cv_window_has_flags=no])
+ AC_MSG_RESULT($ac_cv_window_has_flags)
+ 
++py_curses_window_is_opaque=no
++if test no = $ac_cv_window_has_flags; then
++  AC_MSG_CHECKING([whether WINDOW has _flags in non-opaque structure])
++  AC_COMPILE_IFELSE([
++  AC_LANG_PROGRAM([[
++    #define NCURSES_OPAQUE 0
++    #include <curses.h>
++  ]],[[
++    WINDOW *w;
++    w->_flags = 0;
++  ]])],
++  [py_curses_window_is_opaque=yes])
++  AC_MSG_RESULT([$py_curses_window_is_opaque])
++fi
++if test yes = $py_curses_window_is_opaque; then
++  ac_cv_window_has_flags=yes
++  AC_DEFINE([NCURSES_OPAQUE], [0], [Define to 0 if you have WINDOW _flags in non-opaque structure.])
++fi
++
++py_curses_window_is_internal=no
++if test no = $ac_cv_window_has_flags; then
++  AC_MSG_CHECKING([whether WINDOW has _flags as internal structure])
++  AC_COMPILE_IFELSE([
++  AC_LANG_PROGRAM([[
++    #define NCURSES_INTERNALS 1
++    #include <curses.h>
++  ]],[[
++    WINDOW *w;
++    w->_flags = 0;
++  ]])],
++  [py_curses_window_is_internal=yes])
++  AC_MSG_RESULT([$py_curses_window_is_internal])
++fi
++if test yes = $py_curses_window_is_internal; then
++  ac_cv_window_has_flags=yes
++  AC_DEFINE([NCURSES_INTERNALS], [1], [Define to 1 if you have WINDOW _flags as internal structure.])
++fi
+ 
+ if test "$ac_cv_window_has_flags" = yes
+ then
+diff --git a/pyconfig.h.in b/pyconfig.h.in
+index 3ca3a4f..484c817 100644
+--- a/pyconfig.h.in
++++ b/pyconfig.h.in
+@@ -1130,6 +1130,12 @@
+ /* Define if mvwdelch in curses.h is an expression. */
+ #undef MVWDELCH_IS_EXPRESSION
+ 
++/* Define to 1 if you have WINDOW _flags as internal structure. */
++#undef NCURSES_INTERNALS
++
++/* Define to 0 if you have WINDOW _flags in non-opaque structure. */
++#undef NCURSES_OPAQUE
++
+ /* Define to the address where bug reports for this package should be sent. */
+ #undef PACKAGE_BUGREPORT
+ 
+-- 
+1.6.4
+
diff --git a/pkgs/development/interpreters/python/cpython/2.7/search-path.patch b/pkgs/development/interpreters/python/cpython/2.7/search-path.patch
new file mode 100644
index 000000000000..2e7b7526c0ce
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/search-path.patch
@@ -0,0 +1,27 @@
+diff -rc Python-2.4.4-orig/setup.py Python-2.4.4/setup.py
+*** Python-2.4.4-orig/setup.py	2006-10-08 19:41:25.000000000 +0200
+--- Python-2.4.4/setup.py	2007-05-27 16:04:54.000000000 +0200
+***************
+*** 279,288 ****
+          # Check for AtheOS which has libraries in non-standard locations
+          if platform == 'atheos':
+              lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
+-             lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
+              inc_dirs += ['/system/include', '/atheos/autolnk/include']
+-             inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
+  
+          # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
+          if platform in ['osf1', 'unixware7', 'openunix8']:
+              lib_dirs += ['/usr/ccs/lib']
+--- 279,289 ----
+          # Check for AtheOS which has libraries in non-standard locations
+          if platform == 'atheos':
+              lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
+              inc_dirs += ['/system/include', '/atheos/autolnk/include']
+  
++         lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
++         inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
++         
+          # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
+          if platform in ['osf1', 'unixware7', 'openunix8']:
+              lib_dirs += ['/usr/ccs/lib']
diff --git a/pkgs/development/interpreters/python/cpython/2.7/setup-hook.sh b/pkgs/development/interpreters/python/cpython/2.7/setup-hook.sh
new file mode 100644
index 000000000000..4770eea886f6
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/2.7/setup-hook.sh
@@ -0,0 +1,15 @@
+addPythonPath() {
+    addToSearchPathWithCustomDelimiter : PYTHONPATH $1/lib/python2.7/site-packages
+}
+
+toPythonPath() {
+    local paths="$1"
+    local result=
+    for i in $paths; do
+        p="$i/lib/python2.7/site-packages"
+        result="${result}${result:+:}$p"
+    done
+    echo $result
+}
+
+envHooks+=(addPythonPath)
diff --git a/pkgs/development/interpreters/python/cpython/3.3/default.nix b/pkgs/development/interpreters/python/cpython/3.3/default.nix
new file mode 100644
index 000000000000..1d2312fdc151
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/3.3/default.nix
@@ -0,0 +1,118 @@
+{ stdenv, fetchurl
+, bzip2
+, db
+, gdbm
+, less
+, libX11, xproto
+, lzma
+, ncurses
+, openssl
+, readline
+, sqlite
+, tcl, tk
+, zlib
+, callPackage
+, self
+, python33Packages
+}:
+
+assert readline != null -> ncurses != null;
+
+with stdenv.lib;
+
+let
+  majorVersion = "3.3";
+  pythonVersion = majorVersion;
+  version = "${majorVersion}.6";
+
+  buildInputs = filter (p: p != null) [
+    zlib bzip2 lzma gdbm sqlite db readline ncurses openssl tcl tk libX11 xproto
+  ];
+
+  propagatedBuildInputs = [
+    less
+  ];
+
+in
+stdenv.mkDerivation {
+  name = "python3-${version}";
+  pythonVersion = majorVersion;
+  inherit majorVersion version;
+
+  inherit buildInputs;
+  inherit propagatedBuildInputs;
+
+  src = fetchurl {
+    url = "http://www.python.org/ftp/python/${version}/Python-${version}.tar.xz";
+    sha256 = "0gsxpgd5p4mwd01gw501vsyahncyw3h9836ypkr3y32kgazy89jj";
+  };
+
+  NIX_LDFLAGS = stdenv.lib.optionalString stdenv.isLinux "-lgcc_s";
+
+  preConfigure = ''
+    for i in /usr /sw /opt /pkg; do	# improve purity
+      substituteInPlace ./setup.py --replace $i /no-such-path
+    done
+    ${optionalString stdenv.isDarwin ''export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -msse2"''}
+
+    configureFlagsArray=( --enable-shared --with-threads
+                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${getDev p}/include") buildInputs)}"
+                          LDFLAGS="${concatStringsSep " " (map (p: "-L${getLib p}/lib") buildInputs)}"
+                          LIBS="${optionalString (!stdenv.isDarwin) "-lcrypt"} ${optionalString (ncurses != null) "-lncurses"}"
+                        )
+  '';
+
+  setupHook = ./setup-hook.sh;
+
+  postInstall = ''
+    # needed for some packages, especially packages that backport functionality
+    # to 2.x from 3.x
+    for item in $out/lib/python${majorVersion}/test/*; do
+      if [[ "$item" != */test_support.py* ]]; then
+        rm -rf "$item"
+      else
+        echo $item
+      fi
+    done
+    touch $out/lib/python${majorVersion}/test/__init__.py
+    ln -s "$out/include/python${majorVersion}m" "$out/include/python${majorVersion}"
+    paxmark E $out/bin/python${majorVersion}
+  '';
+
+  passthru = rec {
+    zlibSupport = zlib != null;
+    sqliteSupport = sqlite != null;
+    dbSupport = db != null;
+    readlineSupport = readline != null;
+    opensslSupport = openssl != null;
+    tkSupport = (tk != null) && (tcl != null) && (libX11 != null) && (xproto != null);
+    libPrefix = "python${majorVersion}";
+    executable = "python3.3m";
+    buildEnv = callPackage ../../wrapper.nix { python = self; };
+    withPackages = import ../../with-packages.nix { inherit buildEnv; pythonPackages = python33Packages; };
+    isPy3 = true;
+    isPy33 = true;
+    is_py3k = true;  # deprecated
+    sitePackages = "lib/${libPrefix}/site-packages";
+    interpreter = "${self}/bin/${executable}";
+  };
+
+  enableParallelBuilding = true;
+
+  meta = {
+    homepage = http://python.org;
+    description = "A high-level dynamically-typed programming language";
+    longDescription = ''
+      Python is a remarkably powerful dynamic programming language that
+      is used in a wide variety of application domains. Some of its key
+      distinguishing features include: clear, readable syntax; strong
+      introspection capabilities; intuitive object orientation; natural
+      expression of procedural code; full modularity, supporting
+      hierarchical packages; exception-based error handling; and very
+      high level dynamic data types.
+    '';
+    license = stdenv.lib.licenses.psfl;
+    platforms = with stdenv.lib.platforms; linux ++ darwin;
+    maintainers = with stdenv.lib.maintainers; [ chaoflow cstrahan ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/3.3/setup-hook.sh b/pkgs/development/interpreters/python/cpython/3.3/setup-hook.sh
new file mode 100644
index 000000000000..82a8c0abd32f
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/3.3/setup-hook.sh
@@ -0,0 +1,15 @@
+addPythonPath() {
+    addToSearchPathWithCustomDelimiter : PYTHONPATH $1/lib/python3.3/site-packages
+}
+
+toPythonPath() {
+    local paths="$1"
+    local result=
+    for i in $paths; do
+        p="$i/lib/python3.3/site-packages"
+        result="${result}${result:+:}$p"
+    done
+    echo $result
+}
+
+envHooks+=(addPythonPath)
diff --git a/pkgs/development/interpreters/python/cpython/3.4/default.nix b/pkgs/development/interpreters/python/cpython/3.4/default.nix
new file mode 100644
index 000000000000..64c61e504b7e
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/3.4/default.nix
@@ -0,0 +1,141 @@
+{ stdenv, fetchurl
+, bzip2
+, db
+, gdbm
+, less
+, libX11, xproto
+, lzma
+, ncurses
+, openssl
+, readline
+, sqlite
+, tcl, tk
+, zlib
+, callPackage
+, self
+, python34Packages
+
+, CF, configd
+}:
+
+assert readline != null -> ncurses != null;
+
+with stdenv.lib;
+
+let
+  majorVersion = "3.4";
+  pythonVersion = majorVersion;
+  version = "${majorVersion}.5";
+  fullVersion = "${version}";
+
+  buildInputs = filter (p: p != null) [
+    zlib
+    bzip2
+    lzma
+    gdbm
+    sqlite
+    db
+    readline
+    ncurses
+    openssl
+    tcl
+    tk
+    libX11
+    xproto
+  ] ++ optionals stdenv.isDarwin [ CF configd ];
+
+  propagatedBuildInputs = [
+    less
+  ];
+
+in
+stdenv.mkDerivation {
+  name = "python3-${fullVersion}";
+  pythonVersion = majorVersion;
+  inherit majorVersion version;
+
+  inherit buildInputs;
+  inherit propagatedBuildInputs;
+
+  src = fetchurl {
+    url = "http://www.python.org/ftp/python/${version}/Python-${fullVersion}.tar.xz";
+    sha256 = "12l9klp778wklxmckhghniy5hklss8r26995pyd00qbllk4b2r7f";
+  };
+
+  NIX_LDFLAGS = optionalString stdenv.isLinux "-lgcc_s";
+
+  prePatch = optionalString stdenv.isDarwin ''
+    substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
+  '';
+
+  preConfigure = ''
+    for i in /usr /sw /opt /pkg; do	# improve purity
+      substituteInPlace ./setup.py --replace $i /no-such-path
+    done
+    ${optionalString stdenv.isDarwin ''
+       export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -msse2"
+       export MACOSX_DEPLOYMENT_TARGET=10.6
+     ''}
+
+    configureFlagsArray=( --enable-shared --with-threads
+                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${getDev p}/include") buildInputs)}"
+                          LDFLAGS="${concatStringsSep " " (map (p: "-L${getLib p}/lib") buildInputs)}"
+                          LIBS="${optionalString (!stdenv.isDarwin) "-lcrypt"} ${optionalString (ncurses != null) "-lncurses"}"
+                        )
+  '';
+
+  setupHook = ./setup-hook.sh;
+
+  postInstall = ''
+    # needed for some packages, especially packages that backport functionality
+    # to 2.x from 3.x
+    for item in $out/lib/python${majorVersion}/test/*; do
+      if [[ "$item" != */test_support.py* ]]; then
+        rm -rf "$item"
+      else
+        echo $item
+      fi
+    done
+    touch $out/lib/python${majorVersion}/test/__init__.py
+
+    ln -s "$out/include/python${majorVersion}m" "$out/include/python${majorVersion}"
+    paxmark E $out/bin/python${majorVersion}
+  '';
+
+  passthru = rec {
+    zlibSupport = zlib != null;
+    sqliteSupport = sqlite != null;
+    dbSupport = db != null;
+    readlineSupport = readline != null;
+    opensslSupport = openssl != null;
+    tkSupport = (tk != null) && (tcl != null) && (libX11 != null) && (xproto != null);
+    libPrefix = "python${majorVersion}";
+    executable = "python3.4m";
+    buildEnv = callPackage ../../wrapper.nix { python = self; };
+    withPackages = import ../../with-packages.nix { inherit buildEnv; pythonPackages = python34Packages; };
+    isPy3 = true;
+    isPy34 = true;
+    is_py3k = true;  # deprecated
+    sitePackages = "lib/${libPrefix}/site-packages";
+    interpreter = "${self}/bin/${executable}";
+  };
+
+  enableParallelBuilding = true;
+
+  meta = {
+    homepage = http://python.org;
+    description = "A high-level dynamically-typed programming language";
+    longDescription = ''
+      Python is a remarkably powerful dynamic programming language that
+      is used in a wide variety of application domains. Some of its key
+      distinguishing features include: clear, readable syntax; strong
+      introspection capabilities; intuitive object orientation; natural
+      expression of procedural code; full modularity, supporting
+      hierarchical packages; exception-based error handling; and very
+      high level dynamic data types.
+    '';
+    license = licenses.psfl;
+    platforms = with platforms; linux ++ darwin;
+    maintainers = with maintainers; [ chaoflow domenkozar cstrahan ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/3.4/setup-hook.sh b/pkgs/development/interpreters/python/cpython/3.4/setup-hook.sh
new file mode 100644
index 000000000000..fddcc0b73fe8
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/3.4/setup-hook.sh
@@ -0,0 +1,15 @@
+addPythonPath() {
+    addToSearchPathWithCustomDelimiter : PYTHONPATH $1/lib/python3.4/site-packages
+}
+
+toPythonPath() {
+    local paths="$1"
+    local result=
+    for i in $paths; do
+        p="$i/lib/python3.4/site-packages"
+        result="${result}${result:+:}$p"
+    done
+    echo $result
+}
+
+envHooks+=(addPythonPath)
diff --git a/pkgs/development/interpreters/python/cpython/3.5/default.nix b/pkgs/development/interpreters/python/cpython/3.5/default.nix
new file mode 100644
index 000000000000..c36d7c2a6eb9
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/3.5/default.nix
@@ -0,0 +1,141 @@
+{ stdenv, fetchurl
+, bzip2
+, db
+, gdbm
+, less
+, libX11, xproto
+, lzma
+, ncurses
+, openssl
+, readline
+, sqlite
+, tcl, tk
+, zlib
+, callPackage
+, self
+, python35Packages
+
+, CF, configd
+}:
+
+assert readline != null -> ncurses != null;
+
+with stdenv.lib;
+
+let
+  majorVersion = "3.5";
+  pythonVersion = majorVersion;
+  version = "${majorVersion}.2";
+  fullVersion = "${version}";
+
+  buildInputs = filter (p: p != null) [
+    zlib
+    bzip2
+    lzma
+    gdbm
+    sqlite
+    db
+    readline
+    ncurses
+    openssl
+    tcl
+    tk
+    libX11
+    xproto
+  ] ++ optionals stdenv.isDarwin [ CF configd ];
+
+  propagatedBuildInputs = [
+    less
+  ];
+
+in
+stdenv.mkDerivation {
+  name = "python3-${fullVersion}";
+  pythonVersion = majorVersion;
+  inherit majorVersion version;
+
+  inherit buildInputs;
+  inherit propagatedBuildInputs;
+
+  src = fetchurl {
+    url = "http://www.python.org/ftp/python/${version}/Python-${fullVersion}.tar.xz";
+    sha256 = "0h6a5fr7ram2s483lh0pnmc4ncijb8llnpfdxdcl5dxr01hza400";
+  };
+
+  NIX_LDFLAGS = optionalString stdenv.isLinux "-lgcc_s";
+
+  prePatch = optionalString stdenv.isDarwin ''
+    substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
+  '';
+
+  preConfigure = ''
+    for i in /usr /sw /opt /pkg; do	# improve purity
+      substituteInPlace ./setup.py --replace $i /no-such-path
+    done
+    ${optionalString stdenv.isDarwin ''
+       export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -msse2"
+       export MACOSX_DEPLOYMENT_TARGET=10.6
+     ''}
+
+    configureFlagsArray=( --enable-shared --with-threads
+                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${getDev p}/include") buildInputs)}"
+                          LDFLAGS="${concatStringsSep " " (map (p: "-L${getLib p}/lib") buildInputs)}"
+                          LIBS="${optionalString (!stdenv.isDarwin) "-lcrypt"} ${optionalString (ncurses != null) "-lncurses"}"
+                        )
+  '';
+
+  setupHook = ./setup-hook.sh;
+
+  postInstall = ''
+    # needed for some packages, especially packages that backport functionality
+    # to 2.x from 3.x
+    for item in $out/lib/python${majorVersion}/test/*; do
+      if [[ "$item" != */test_support.py* ]]; then
+        rm -rf "$item"
+      else
+        echo $item
+      fi
+    done
+    touch $out/lib/python${majorVersion}/test/__init__.py
+
+    ln -s "$out/include/python${majorVersion}m" "$out/include/python${majorVersion}"
+    paxmark E $out/bin/python${majorVersion}
+  '';
+
+  passthru = rec {
+    zlibSupport = zlib != null;
+    sqliteSupport = sqlite != null;
+    dbSupport = db != null;
+    readlineSupport = readline != null;
+    opensslSupport = openssl != null;
+    tkSupport = (tk != null) && (tcl != null) && (libX11 != null) && (xproto != null);
+    libPrefix = "python${majorVersion}";
+    executable = "python${majorVersion}m";
+    buildEnv = callPackage ../../wrapper.nix { python = self; };
+    withPackages = import ../../with-packages.nix { inherit buildEnv; pythonPackages = python35Packages; };
+    isPy3 = true;
+    isPy35 = true;
+    is_py3k = true;  # deprecated
+    sitePackages = "lib/${libPrefix}/site-packages";
+    interpreter = "${self}/bin/${executable}";
+  };
+
+  enableParallelBuilding = true;
+
+  meta = {
+    homepage = http://python.org;
+    description = "A high-level dynamically-typed programming language";
+    longDescription = ''
+      Python is a remarkably powerful dynamic programming language that
+      is used in a wide variety of application domains. Some of its key
+      distinguishing features include: clear, readable syntax; strong
+      introspection capabilities; intuitive object orientation; natural
+      expression of procedural code; full modularity, supporting
+      hierarchical packages; exception-based error handling; and very
+      high level dynamic data types.
+    '';
+    license = licenses.psfl;
+    platforms = with platforms; linux ++ darwin;
+    maintainers = with maintainers; [ chaoflow domenkozar cstrahan ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/3.5/setup-hook.sh b/pkgs/development/interpreters/python/cpython/3.5/setup-hook.sh
new file mode 100644
index 000000000000..2836ad7e8f56
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/3.5/setup-hook.sh
@@ -0,0 +1,15 @@
+addPythonPath() {
+    addToSearchPathWithCustomDelimiter : PYTHONPATH $1/lib/python3.5/site-packages
+}
+
+toPythonPath() {
+    local paths="$1"
+    local result=
+    for i in $paths; do
+        p="$i/lib/python3.5/site-packages"
+        result="${result}${result:+:}$p"
+    done
+    echo $result
+}
+
+envHooks+=(addPythonPath)
diff --git a/pkgs/development/interpreters/python/cpython/3.6/default.nix b/pkgs/development/interpreters/python/cpython/3.6/default.nix
new file mode 100644
index 000000000000..a337b28859b7
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/3.6/default.nix
@@ -0,0 +1,145 @@
+{ stdenv, fetchurl
+, glibc
+, bzip2
+, db
+, gdbm
+, less
+, libX11, xproto
+, lzma
+, ncurses
+, openssl
+, readline
+, sqlite
+, tcl, tk
+, zlib
+, callPackage
+, self
+, python36Packages
+
+, CF, configd
+}:
+
+assert readline != null -> ncurses != null;
+
+with stdenv.lib;
+
+let
+  majorVersion = "3.6";
+  pythonVersion = majorVersion;
+  version = "${majorVersion}.0a3";
+  fullVersion = "${version}";
+
+  buildInputs = filter (p: p != null) [
+    glibc
+    zlib
+    bzip2
+    lzma
+    gdbm
+    sqlite
+    db
+    readline
+    ncurses
+    openssl
+    tcl
+    tk
+    libX11
+    xproto
+  ] ++ optionals stdenv.isDarwin [ CF configd ];
+
+  propagatedBuildInputs = [
+    less
+  ];
+
+in
+stdenv.mkDerivation {
+  name = "python3-${fullVersion}";
+  pythonVersion = majorVersion;
+  inherit majorVersion version;
+
+  inherit buildInputs;
+  inherit propagatedBuildInputs;
+
+  src = fetchurl {
+    url = "https://www.python.org/ftp/python/${majorVersion}.0/Python-${fullVersion}.tar.xz";
+    sha256 = "08c3598bwihibwca9lwxq923sjq9shvgv3wxv4vkga2n6hf63l1c";
+  };
+
+  NIX_LDFLAGS = optionalString stdenv.isLinux "-lgcc_s";
+
+  prePatch = optionalString stdenv.isDarwin ''
+    substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
+  '';
+
+  preConfigure = ''
+    for i in /usr /sw /opt /pkg; do	# improve purity
+      substituteInPlace ./setup.py --replace $i /no-such-path
+    done
+    ${optionalString stdenv.isDarwin ''
+       export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -msse2"
+       export MACOSX_DEPLOYMENT_TARGET=10.6
+     ''}
+
+    substituteInPlace ./Lib/plat-generic/regen --replace "/usr/include" ${glibc}/include
+
+    configureFlagsArray=( --enable-shared --with-threads
+                          CPPFLAGS="${concatStringsSep " " (map (p: "-I${getDev p}/include") buildInputs)}"
+                          LDFLAGS="${concatStringsSep " " (map (p: "-L${getLib p}/lib") buildInputs)}"
+                          LIBS="${optionalString (!stdenv.isDarwin) "-lcrypt"} ${optionalString (ncurses != null) "-lncurses"}"
+                        )
+  '';
+
+  setupHook = ./setup-hook.sh;
+
+  postInstall = ''
+    # needed for some packages, especially packages that backport functionality
+    # to 2.x from 3.x
+    for item in $out/lib/python${majorVersion}/test/*; do
+      if [[ "$item" != */test_support.py* ]]; then
+        rm -rf "$item"
+      else
+        echo $item
+      fi
+    done
+    touch $out/lib/python${majorVersion}/test/__init__.py
+
+    ln -s "$out/include/python${majorVersion}m" "$out/include/python${majorVersion}"
+    paxmark E $out/bin/python${majorVersion}
+  '';
+
+  passthru = rec {
+    zlibSupport = zlib != null;
+    sqliteSupport = sqlite != null;
+    dbSupport = db != null;
+    readlineSupport = readline != null;
+    opensslSupport = openssl != null;
+    tkSupport = (tk != null) && (tcl != null) && (libX11 != null) && (xproto != null);
+    libPrefix = "python${majorVersion}";
+    executable = "python${majorVersion}m";
+    buildEnv = callPackage ../../wrapper.nix { python = self; };
+    withPackages = import ../../with-packages.nix { inherit buildEnv; pythonPackages = python36Packages; };
+    isPy3 = true;
+    isPy35 = true;
+    is_py3k = true;  # deprecated
+    sitePackages = "lib/${libPrefix}/site-packages";
+    interpreter = "${self}/bin/${executable}";
+  };
+
+  enableParallelBuilding = true;
+
+  meta = {
+    homepage = http://python.org;
+    description = "A high-level dynamically-typed programming language";
+    longDescription = ''
+      Python is a remarkably powerful dynamic programming language that
+      is used in a wide variety of application domains. Some of its key
+      distinguishing features include: clear, readable syntax; strong
+      introspection capabilities; intuitive object orientation; natural
+      expression of procedural code; full modularity, supporting
+      hierarchical packages; exception-based error handling; and very
+      high level dynamic data types.
+    '';
+    license = licenses.psfl;
+    platforms = with platforms; linux ++ darwin;
+    maintainers = with maintainers; [ chaoflow domenkozar cstrahan kragniz ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/3.6/setup-hook.sh b/pkgs/development/interpreters/python/cpython/3.6/setup-hook.sh
new file mode 100644
index 000000000000..26a0d57bc87c
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/3.6/setup-hook.sh
@@ -0,0 +1,15 @@
+addPythonPath() {
+    addToSearchPathWithCustomDelimiter : PYTHONPATH $1/lib/python3.6/site-packages
+}
+
+toPythonPath() {
+    local paths="$1"
+    local result=
+    for i in $paths; do
+        p="$i/lib/python3.6/site-packages"
+        result="${result}${result:+:}$p"
+    done
+    echo $result
+}
+
+envHooks+=(addPythonPath)
diff --git a/pkgs/development/interpreters/python/cpython/docs/2.6-html.nix b/pkgs/development/interpreters/python/cpython/docs/2.6-html.nix
new file mode 100644
index 000000000000..2b41f122fa9b
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/2.6-html.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python26-docs-html-2.6.8";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/2.6.8/python-2.6.8-docs-html.tar.bz2;
+    sha256 = "09kznik9ahmnrqw9gkr7mjv3b3zr258f2fm27n12hrrwwsaszkni";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python26
+    cp -R ./ $out/share/doc/python26/html
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/2.6-pdf-a4.nix b/pkgs/development/interpreters/python/cpython/docs/2.6-pdf-a4.nix
new file mode 100644
index 000000000000..ec031821a03f
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/2.6-pdf-a4.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python26-docs-pdf-a4-2.6.8";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/2.6.8/python-2.6.8-docs-pdf-a4.tar.bz2;
+    sha256 = "07k8n9zhd59s1yn8ahsizkaqnv969p0f2c2acxgxrxhhyy842pp8";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python26
+    cp -R ./ $out/share/doc/python26/pdf-a4
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/2.6-pdf-letter.nix b/pkgs/development/interpreters/python/cpython/docs/2.6-pdf-letter.nix
new file mode 100644
index 000000000000..7cacf7778348
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/2.6-pdf-letter.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python26-docs-pdf-letter-2.6.8";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/2.6.8/python-2.6.8-docs-pdf-letter.tar.bz2;
+    sha256 = "01r87m8hb7f9ql4j9zcjcrr9150nsk23sj8cy02vygr83sc1ldmq";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python26
+    cp -R ./ $out/share/doc/python26/pdf-letter
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/2.6-text.nix b/pkgs/development/interpreters/python/cpython/docs/2.6-text.nix
new file mode 100644
index 000000000000..eb394a3f3e2d
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/2.6-text.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python26-docs-text-2.6.8";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/2.6.8/python-2.6.8-docs-text.tar.bz2;
+    sha256 = "05wsdh6ilgkclgak09fq7fsx5kflkmqq8dyxi2rpydx289cw3a8c";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python26
+    cp -R ./ $out/share/doc/python26/text
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/2.7-html.nix b/pkgs/development/interpreters/python/cpython/docs/2.7-html.nix
new file mode 100644
index 000000000000..3885b43960f5
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/2.7-html.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python27-docs-html-2.7.3";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/2.7.3/python-2.7.3-docs-html.tar.bz2;
+    sha256 = "1hg92n0mzl9w6j33b2h0bf2vy6fsxnpxfdc3qw760vcm0y00155j";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python27
+    cp -R ./ $out/share/doc/python27/html
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-a4.nix b/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-a4.nix
new file mode 100644
index 000000000000..d8dde17ac66a
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-a4.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python27-docs-pdf-a4-2.7.3";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/2.7.3/python-2.7.3-docs-pdf-a4.tar.bz2;
+    sha256 = "13da88panq5b6qfhf8k4dgqgxkg4ydcac5cx69a3f35s1w90xdjr";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python27
+    cp -R ./ $out/share/doc/python27/pdf-a4
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-letter.nix b/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-letter.nix
new file mode 100644
index 000000000000..32581cd229a9
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-letter.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python27-docs-pdf-letter-2.7.3";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/2.7.3/python-2.7.3-docs-pdf-letter.tar.bz2;
+    sha256 = "0x41phsdrpivhzkchswsliyx3a10n7gzc9irkrw6rz22j81bfydg";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python27
+    cp -R ./ $out/share/doc/python27/pdf-letter
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/2.7-text.nix b/pkgs/development/interpreters/python/cpython/docs/2.7-text.nix
new file mode 100644
index 000000000000..590192383016
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/2.7-text.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python27-docs-text-2.7.3";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/2.7.3/python-2.7.3-docs-text.tar.bz2;
+    sha256 = "1rxlb3jhh3892y65i45nk1y2lx981fr22a5hmfkp9gvjvdykjnzp";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python27
+    cp -R ./ $out/share/doc/python27/text
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/3.3-html.nix b/pkgs/development/interpreters/python/cpython/docs/3.3-html.nix
new file mode 100644
index 000000000000..055224dd740b
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/3.3-html.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python33-docs-html-3.3.0";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/3.3.0/python-3.3.0-docs-html.tar.bz2;
+    sha256 = "0vv24b9qi7gznv687ik0pa2w1rq9grqivy44znvj2ysjfg7mc2c1";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python33
+    cp -R ./ $out/share/doc/python33/html
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/3.3-pdf-a4.nix b/pkgs/development/interpreters/python/cpython/docs/3.3-pdf-a4.nix
new file mode 100644
index 000000000000..8c6b842d0b94
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/3.3-pdf-a4.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python33-docs-pdf-a4-3.3.0";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/3.3.0/python-3.3.0-docs-pdf-a4.tar.bz2;
+    sha256 = "1y6n13bxlw8a11khy3ynfbz8z0kpf2lvh32dvy8scyw3hrk6wdxp";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python33
+    cp -R ./ $out/share/doc/python33/pdf-a4
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/3.3-pdf-letter.nix b/pkgs/development/interpreters/python/cpython/docs/3.3-pdf-letter.nix
new file mode 100644
index 000000000000..046abe8f83d7
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/3.3-pdf-letter.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python33-docs-pdf-letter-3.3.0";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/3.3.0/python-3.3.0-docs-pdf-letter.tar.bz2;
+    sha256 = "0mcj1i47nx81fc9zk1cic4c4p139qjcqlzf4hnnkzvb3jcgy5z6k";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python33
+    cp -R ./ $out/share/doc/python33/pdf-letter
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/3.3-text.nix b/pkgs/development/interpreters/python/cpython/docs/3.3-text.nix
new file mode 100644
index 000000000000..4d99c25bf598
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/3.3-text.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "python33-docs-text-3.3.0";
+  src = fetchurl {
+    url = http://docs.python.org/ftp/python/doc/3.3.0/python-3.3.0-docs-text.tar.bz2;
+    sha256 = "10vk2fixg1aglqmsf89kn98rlirrbhnrk1285vzfbynf2iavxw0n";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/python33
+    cp -R ./ $out/share/doc/python33/text
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}
diff --git a/pkgs/development/interpreters/python/cpython/docs/default.nix b/pkgs/development/interpreters/python/cpython/docs/default.nix
new file mode 100644
index 000000000000..8f5fc810fb71
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/default.nix
@@ -0,0 +1,53 @@
+{ stdenv, fetchurl, lib }:
+
+let
+pythonDocs = {
+  html = {
+    recurseForDerivations = true;
+    python33 = import ./3.3-html.nix {
+      inherit stdenv fetchurl lib;
+    };
+    python27 = import ./2.7-html.nix {
+      inherit stdenv fetchurl lib;
+    };
+    python26 = import ./2.6-html.nix {
+      inherit stdenv fetchurl lib;
+    };
+  };
+  pdf_a4 = {
+    recurseForDerivations = true;
+    python33 = import ./3.3-pdf-a4.nix {
+      inherit stdenv fetchurl lib;
+    };
+    python27 = import ./2.7-pdf-a4.nix {
+      inherit stdenv fetchurl lib;
+    };
+    python26 = import ./2.6-pdf-a4.nix {
+      inherit stdenv fetchurl lib;
+    };
+  };
+  pdf_letter = {
+    recurseForDerivations = true;
+    python33 = import ./3.3-pdf-letter.nix {
+      inherit stdenv fetchurl lib;
+    };
+    python27 = import ./2.7-pdf-letter.nix {
+      inherit stdenv fetchurl lib;
+    };
+    python26 = import ./2.6-pdf-letter.nix {
+      inherit stdenv fetchurl lib;
+    };
+  };
+  text = {
+    recurseForDerivations = true;
+    python33 = import ./3.3-text.nix {
+      inherit stdenv fetchurl lib;
+    };
+    python27 = import ./2.7-text.nix {
+      inherit stdenv fetchurl lib;
+    };
+    python26 = import ./2.6-text.nix {
+      inherit stdenv fetchurl lib;
+    };
+  };
+}; in pythonDocs
diff --git a/pkgs/development/interpreters/python/cpython/docs/generate.sh b/pkgs/development/interpreters/python/cpython/docs/generate.sh
new file mode 100755
index 000000000000..bebefc10ccd0
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/generate.sh
@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+
+TYPES="html pdf-a4 pdf-letter text"
+URL=http://docs.python.org/ftp/python/doc/VERSION/python-VERSION-docs-TYPE.tar.bz2
+VERSIONS=$(curl http://www.python.org/download/releases/ 2>/dev/null | grep "releases/[123456789]"| cut -d/ -f4 |grep -v "^[12].[012345]" |grep -v "^1.6.1")
+echo "Generating expressions for:
+${VERSIONS}
+"
+
+
+cat >default.nix <<EOF
+{ stdenv, fetchurl, lib }:
+
+let
+pythonDocs = {
+EOF
+
+for type in $TYPES; do
+    cat >>default.nix <<EOF
+  ${type/-/_} = {
+    recurseForDerivations = true;
+EOF
+
+    for version in $VERSIONS; do
+        major=$(echo -n ${version}| cut -d. -f1)
+        minor=$(echo -n ${version}| cut -d. -f2)
+        outfile=${major}.${minor}-${type}.nix
+        hash=
+        if [ -e ${outfile} ]; then
+            currentversion=$(grep "url =" ${outfile} |cut -d/ -f7)
+            if [ ${version} = ${currentversion} ]; then
+                hash=$(grep sha256 ${outfile} | cut -d'"' -f2)
+            fi
+        fi
+        echo "Generating ${outfile}"
+        url=$(echo -n $URL |sed -e "s,VERSION,${version},g" -e "s,TYPE,${type},")
+        sha=$(nix-prefetch-url ${url} ${hash})
+
+        sed -e "s,VERSION,${version}," \
+            -e "s,MAJOR,${major}," \
+            -e "s,MINOR,${minor}," \
+            -e "s,TYPE,${type}," \
+            -e "s,URL,${url}," \
+            -e "s,SHA,${sha}," < template.nix > ${outfile}
+
+        attrname=python${major}${minor}
+        cat >>default.nix <<EOF
+    ${attrname} = import ./${major}.${minor}-${type}.nix {
+      inherit stdenv fetchurl lib;
+    };
+EOF
+
+        echo "done."
+        echo
+    done
+    echo "  };" >> default.nix
+done
+
+echo "}; in pythonDocs" >> default.nix
diff --git a/pkgs/development/interpreters/python/cpython/docs/template.nix b/pkgs/development/interpreters/python/cpython/docs/template.nix
new file mode 100644
index 000000000000..cc92f71bc1ea
--- /dev/null
+++ b/pkgs/development/interpreters/python/cpython/docs/template.nix
@@ -0,0 +1,18 @@
+# This file was generated and will be overwritten by ./generate.sh
+
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "pythonMAJORMINOR-docs-TYPE-VERSION";
+  src = fetchurl {
+    url = URL;
+    sha256 = "SHA";
+  };
+  installPhase = ''
+    mkdir -p $out/share/doc/pythonMAJORMINOR
+    cp -R ./ $out/share/doc/pythonMAJORMINOR/TYPE
+  '';
+  meta = {
+    maintainers = [ lib.maintainers.chaoflow ];
+  };
+}