about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/interpreters
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/interpreters')
-rw-r--r--nixpkgs/pkgs/development/interpreters/angelscript/default.nix4
-rw-r--r--nixpkgs/pkgs/development/interpreters/clisp/default.nix6
-rw-r--r--nixpkgs/pkgs/development/interpreters/clisp/hg.nix6
-rw-r--r--nixpkgs/pkgs/development/interpreters/clojure/default.nix4
-rw-r--r--nixpkgs/pkgs/development/interpreters/duktape/default.nix4
-rw-r--r--nixpkgs/pkgs/development/interpreters/elixir/1.3.nix7
-rw-r--r--nixpkgs/pkgs/development/interpreters/elixir/1.8.nix7
-rw-r--r--nixpkgs/pkgs/development/interpreters/elixir/generic-builder.nix3
-rw-r--r--nixpkgs/pkgs/development/interpreters/erlang/R21.nix4
-rw-r--r--nixpkgs/pkgs/development/interpreters/erlang/generic-builder.nix3
-rw-r--r--nixpkgs/pkgs/development/interpreters/groovy/default.nix4
-rw-r--r--nixpkgs/pkgs/development/interpreters/gtk-server/default.nix4
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/5.1.nix22
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/5.2.nix26
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/5.3.nix24
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/build-lua-package.nix182
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/build-rocks.nix0
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/build-rockspec.nix0
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.nix15
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.sh47
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/with-packages.nix4
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/wrap-lua.nix19
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/wrap.sh99
-rw-r--r--nixpkgs/pkgs/development/interpreters/lua-5/wrapper.nix73
-rw-r--r--nixpkgs/pkgs/development/interpreters/luajit/2.0.nix10
-rw-r--r--nixpkgs/pkgs/development/interpreters/luajit/2.1.nix7
-rw-r--r--nixpkgs/pkgs/development/interpreters/luajit/default.nix121
-rw-r--r--nixpkgs/pkgs/development/interpreters/lush/default.nix4
-rw-r--r--nixpkgs/pkgs/development/interpreters/metamath/default.nix6
-rw-r--r--nixpkgs/pkgs/development/interpreters/mujs/default.nix16
-rw-r--r--nixpkgs/pkgs/development/interpreters/perl/default.nix22
-rw-r--r--nixpkgs/pkgs/development/interpreters/perl/no-sys-dirs-5.29.patch251
-rw-r--r--nixpkgs/pkgs/development/interpreters/php/default.nix20
-rw-r--r--nixpkgs/pkgs/development/interpreters/php/fix-bug-71041.patch25
-rw-r--r--nixpkgs/pkgs/development/interpreters/picolisp/default.nix40
-rw-r--r--nixpkgs/pkgs/development/interpreters/pixie/default.nix2
-rw-r--r--nixpkgs/pkgs/development/interpreters/pure/default.nix1
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/build-python-package-common.nix5
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/build-python-package-setuptools.nix11
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/build-python-package.nix5
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/boot.nix2
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix74
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/3.5/default.nix213
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/3.7/default.nix196
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/default.nix (renamed from nixpkgs/pkgs/development/interpreters/python/cpython/3.6/default.nix)183
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/default.nix156
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix7
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/pypy/2.7/default.nix136
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/pypy/3/default.nix138
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/pypy/3/tk_tcl_paths.patch17
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/pypy/default.nix148
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix123
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/pypy/tk_tcl_paths.patch (renamed from nixpkgs/pkgs/development/interpreters/python/pypy/2.7/tk_tcl_paths.patch)0
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/wrap-python.nix5
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/wrap.sh20
-rw-r--r--nixpkgs/pkgs/development/interpreters/racket/default.nix21
-rw-r--r--nixpkgs/pkgs/development/interpreters/racket/minimal.nix3
-rw-r--r--nixpkgs/pkgs/development/interpreters/ruby/default.nix17
-rw-r--r--nixpkgs/pkgs/development/interpreters/ruby/patchsets.nix2
-rw-r--r--nixpkgs/pkgs/development/interpreters/spidermonkey/1.8.5.nix5
-rw-r--r--nixpkgs/pkgs/development/interpreters/tcl/generic.nix18
-rw-r--r--nixpkgs/pkgs/development/interpreters/tinyscheme/default.nix33
62 files changed, 1587 insertions, 1043 deletions
diff --git a/nixpkgs/pkgs/development/interpreters/angelscript/default.nix b/nixpkgs/pkgs/development/interpreters/angelscript/default.nix
index 01348c753484..adbfbaf48a43 100644
--- a/nixpkgs/pkgs/development/interpreters/angelscript/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/angelscript/default.nix
@@ -3,10 +3,10 @@ let
   s = # Generated upstream information
   rec {
     baseName="angelscript";
-    version = "2.32.0";
+    version = "2.33.0";
     name="${baseName}-${version}";
     url="http://www.angelcode.com/angelscript/sdk/files/angelscript_${version}.zip";
-    sha256 = "0675hza06v3grxyqfy70gzm57idmbbm7qvi6bg5vf8m6mpw757dl";
+    sha256 = "18qywbi1k53xgnlr9v6ycin669j5v5qspq7lli4jhf6l4c5hk49n";
   };
   buildInputs = [
     unzip
diff --git a/nixpkgs/pkgs/development/interpreters/clisp/default.nix b/nixpkgs/pkgs/development/interpreters/clisp/default.nix
index e6112c5a3343..f850a9f57b80 100644
--- a/nixpkgs/pkgs/development/interpreters/clisp/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/clisp/default.nix
@@ -4,7 +4,7 @@
 #   by default
 # - full: contains base plus modules in withModules
 { stdenv, fetchurl, libsigsegv, gettext, ncurses, readline, libX11
-, libXau, libXt, pcre, zlib, libXpm, xproto, libXext, xextproto
+, libXau, libXt, pcre, zlib, libXpm, xorgproto, libXext
 , libffi
 , libffcall
 , coreutils
@@ -21,7 +21,7 @@
 }:
 
 assert x11Support -> (libX11 != null && libXau != null && libXt != null
-  && libXpm != null && xproto != null && libXext != null && xextproto != null);
+  && libXpm != null && xorgproto != null && libXext != null);
 
 stdenv.mkDerivation rec {
   v = "2.49";
@@ -45,7 +45,7 @@ stdenv.mkDerivation rec {
   ++ stdenv.lib.optional (ffcallAvailable && (libffi != null)) libffi
   ++ stdenv.lib.optional ffcallAvailable libffcall
   ++ stdenv.lib.optionals x11Support [
-    libX11 libXau libXt libXpm xproto libXext xextproto
+    libX11 libXau libXt libXpm xorgproto libXext
   ];
 
   patches = [
diff --git a/nixpkgs/pkgs/development/interpreters/clisp/hg.nix b/nixpkgs/pkgs/development/interpreters/clisp/hg.nix
index 47dbf8a225cf..550535f30aee 100644
--- a/nixpkgs/pkgs/development/interpreters/clisp/hg.nix
+++ b/nixpkgs/pkgs/development/interpreters/clisp/hg.nix
@@ -4,7 +4,7 @@
 #   by default
 # - full: contains base plus modules in withModules
 { stdenv, fetchhg, libsigsegv, gettext, ncurses, readline, libX11
-, libXau, libXt, pcre, zlib, libXpm, xproto, libXext, xextproto
+, libXau, libXt, pcre, zlib, libXpm, xorgproto, libXext
 , libffi, libffcall, automake
 , coreutils
 # build options
@@ -20,7 +20,7 @@
 }:
 
 assert x11Support -> (libX11 != null && libXau != null && libXt != null
-  && libXpm != null && xproto != null && libXext != null && xextproto != null);
+  && libXpm != null && xorgproto != null && libXext != null);
 
 stdenv.mkDerivation rec {
   v = "2.50pre20171114";
@@ -46,7 +46,7 @@ stdenv.mkDerivation rec {
   ++ stdenv.lib.optional (ffcallAvailable && (libffi != null)) libffi
   ++ stdenv.lib.optional ffcallAvailable libffcall
   ++ stdenv.lib.optionals x11Support [
-    libX11 libXau libXt libXpm xproto libXext xextproto
+    libX11 libXau libXt libXpm xorgproto libXext
   ];
 
   # First, replace port 9090 (rather low, can be used)
diff --git a/nixpkgs/pkgs/development/interpreters/clojure/default.nix b/nixpkgs/pkgs/development/interpreters/clojure/default.nix
index 001f7c9abee0..6018d92bbcab 100644
--- a/nixpkgs/pkgs/development/interpreters/clojure/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/clojure/default.nix
@@ -2,11 +2,11 @@
 
 stdenv.mkDerivation rec {
   name = "clojure-${version}";
-  version = "1.10.0.403";
+  version = "1.10.0.411";
 
   src = fetchurl {
     url = "https://download.clojure.org/install/clojure-tools-${version}.tar.gz";
-    sha256 = "0jsyd0vr1qfqs0dz560hyfya553jhr4m4msf5x0n610yzvbqym4c";
+    sha256 = "00bhn6w9iwhgmyx89lk97q19phpm9vh45m3m1pi7d31gldb6v0zh";
   };
 
   buildInputs = [ makeWrapper ];
diff --git a/nixpkgs/pkgs/development/interpreters/duktape/default.nix b/nixpkgs/pkgs/development/interpreters/duktape/default.nix
index 2178f859007f..f3b253bfd220 100644
--- a/nixpkgs/pkgs/development/interpreters/duktape/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/duktape/default.nix
@@ -23,8 +23,8 @@ stdenv.mkDerivation rec {
 
   meta = with stdenv.lib; {
     description = "An embeddable Javascript engine, with a focus on portability and compact footprint";
-    homepage = "http://duktape.org/";
-    downloadPage = "http://duktape.org/download.html";
+    homepage = https://duktape.org/;
+    downloadPage = https://duktape.org/download.html;
     license = licenses.mit;
     maintainers = [ maintainers.fgaz ];
     platforms = platforms.linux;
diff --git a/nixpkgs/pkgs/development/interpreters/elixir/1.3.nix b/nixpkgs/pkgs/development/interpreters/elixir/1.3.nix
deleted file mode 100644
index 43d48e2cf7cd..000000000000
--- a/nixpkgs/pkgs/development/interpreters/elixir/1.3.nix
+++ /dev/null
@@ -1,7 +0,0 @@
-{ mkDerivation }:
-
-mkDerivation rec {
-  version = "1.3.4";
-  sha256 = "01qqv1ghvfadcwcr5p88w8j217cgaf094pmpqllij3l0q1yg104l";
-  minimumOTPVersion = "18";
-}
diff --git a/nixpkgs/pkgs/development/interpreters/elixir/1.8.nix b/nixpkgs/pkgs/development/interpreters/elixir/1.8.nix
new file mode 100644
index 000000000000..40136fd22de8
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/elixir/1.8.nix
@@ -0,0 +1,7 @@
+{ mkDerivation }:
+
+mkDerivation rec {
+  version = "1.8.1";
+  sha256 = "1npnrkn21kqqfqrsn06mr78jxs6n5l8c935jpxvnmj7iysp50pf9";
+  minimumOTPVersion = "20";
+}
diff --git a/nixpkgs/pkgs/development/interpreters/elixir/generic-builder.nix b/nixpkgs/pkgs/development/interpreters/elixir/generic-builder.nix
index b4e1cacfe267..844d6eeb4fb9 100644
--- a/nixpkgs/pkgs/development/interpreters/elixir/generic-builder.nix
+++ b/nixpkgs/pkgs/development/interpreters/elixir/generic-builder.nix
@@ -7,7 +7,7 @@
 , sha256 ? null
 , rev ? "v${version}"
 , src ? fetchFromGitHub { inherit rev sha256; owner = "elixir-lang"; repo = "elixir"; }
-}:
+} @ args:
 
 let
   inherit (stdenv.lib) getVersion versionAtLeast;
@@ -62,6 +62,7 @@ in
             --replace "/usr/bin/env elixir" "${coreutils}/bin/env elixir"
     '';
 
+    pos = builtins.unsafeGetAttrPos "sha256" args;
     meta = with stdenv.lib; {
       homepage = https://elixir-lang.org/;
       description = "A functional, meta-programming aware language built on top of the Erlang VM";
diff --git a/nixpkgs/pkgs/development/interpreters/erlang/R21.nix b/nixpkgs/pkgs/development/interpreters/erlang/R21.nix
index b787f3f44f54..28166dfc0b0a 100644
--- a/nixpkgs/pkgs/development/interpreters/erlang/R21.nix
+++ b/nixpkgs/pkgs/development/interpreters/erlang/R21.nix
@@ -1,8 +1,8 @@
 { mkDerivation }:
 
 mkDerivation rec {
-  version = "21.2";
-  sha256 = "0v9smdp2vxkpsz65a6ypwzl12fqdfrsi7k29f5i7af0v27r308cm";
+  version = "21.2.3";
+  sha256 = "1v47c7bddbp31y6f8yzdjyvgcx9sskxql33k7cs0p5fmr05hhxws";
 
   prePatch = ''
     substituteInPlace configure.in --replace '`sw_vers -productVersion`' '10.10'
diff --git a/nixpkgs/pkgs/development/interpreters/erlang/generic-builder.nix b/nixpkgs/pkgs/development/interpreters/erlang/generic-builder.nix
index 0529c9f1e28c..bc0b728ecce4 100644
--- a/nixpkgs/pkgs/development/interpreters/erlang/generic-builder.nix
+++ b/nixpkgs/pkgs/development/interpreters/erlang/generic-builder.nix
@@ -59,7 +59,8 @@ in stdenv.mkDerivation ({
 
   debugInfo = enableDebugInfo;
 
-  enableParallelBuilding = true;
+  # On some machines, parallel build reliably crashes on `GEN    asn1ct_eval_ext.erl` step
+  enableParallelBuilding = false;
 
   # Clang 4 (rightfully) thinks signed comparisons of pointers with NULL are nonsense
   prePatch = ''
diff --git a/nixpkgs/pkgs/development/interpreters/groovy/default.nix b/nixpkgs/pkgs/development/interpreters/groovy/default.nix
index dccba8ebb0e4..6b55f006cd2a 100644
--- a/nixpkgs/pkgs/development/interpreters/groovy/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/groovy/default.nix
@@ -4,11 +4,11 @@
 
 stdenv.mkDerivation rec {
   name = "groovy-${version}";
-  version = "2.5.4";
+  version = "2.5.5";
 
   src = fetchurl {
     url = "http://dl.bintray.com/groovy/maven/apache-groovy-binary-${version}.zip";
-    sha256 = "1s661d5kwiafv5i1pq2b7k8b2fd7m2zp3xwcrf4iv1iik033djdj";
+    sha256 = "16hj2v6r89s3qrgbnkinwwzv16mphb6jjw8ijgmmd9y2063nchc2";
   };
 
   buildInputs = [ unzip makeWrapper ];
diff --git a/nixpkgs/pkgs/development/interpreters/gtk-server/default.nix b/nixpkgs/pkgs/development/interpreters/gtk-server/default.nix
index ab295dab4443..6f5a5ec0f198 100644
--- a/nixpkgs/pkgs/development/interpreters/gtk-server/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/gtk-server/default.nix
@@ -14,6 +14,10 @@ stdenv.mkDerivation rec {
 
   configureOptions = [ "--with-gtk2" ];
 
+  NIX_LDFLAGS = [
+    "-ldl"
+  ];
+
   meta = {
     description = "gtk-server for interpreted GUI programming";
     homepage = http://www.gtk-server.org/;
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/5.1.nix b/nixpkgs/pkgs/development/interpreters/lua-5/5.1.nix
index 09af492490cf..b2948b392d5e 100644
--- a/nixpkgs/pkgs/development/interpreters/lua-5/5.1.nix
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/5.1.nix
@@ -1,4 +1,8 @@
-{ stdenv, fetchurl, readline }:
+{ stdenv, fetchurl, readline
+, self
+, callPackage
+, packageOverrides ? (self: super: {})
+}:
 
 let
   dsoPatch = fetchurl {
@@ -6,6 +10,7 @@ let
     sha256 = "11fcyb4q55p4p7kdb8yp85xlw8imy14kzamp2khvcyxss4vw8ipw";
     name = "lua-arch.patch";
   };
+  luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};
 in
 stdenv.mkDerivation rec {
   name = "lua-${version}";
@@ -17,6 +22,10 @@ stdenv.mkDerivation rec {
     sha256 = "2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333";
   };
 
+  LuaPathSearchPaths    = luaPackages.getLuaPathList luaversion;
+  LuaCPathSearchPaths   = luaPackages.getLuaCPathList luaversion;
+  setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;
+
   buildInputs = [ readline ];
 
   patches = (if stdenv.isDarwin then [ ./5.1.darwin.patch ] else [ dsoPatch ])
@@ -39,6 +48,16 @@ stdenv.mkDerivation rec {
     rmdir $out/{share,lib}/lua/5.1 $out/{share,lib}/lua
   '';
 
+  passthru = rec {
+    buildEnv = callPackage ./wrapper.nix {
+      lua=self;
+      inherit (luaPackages) requiredLuaModules;
+    };
+    withPackages = import ./with-packages.nix { inherit buildEnv luaPackages;};
+    pkgs = luaPackages;
+    interpreter = "${self}/bin/lua";
+  };
+
   meta = {
     homepage = http://www.lua.org;
     description = "Powerful, fast, lightweight, embeddable scripting language";
@@ -51,6 +70,7 @@ stdenv.mkDerivation rec {
       for configuration, scripting, and rapid prototyping.
     '';
     license = stdenv.lib.licenses.mit;
+    platforms = with stdenv.lib.platforms; linux ++ darwin;
     hydraPlatforms = stdenv.lib.platforms.linux;
   };
 }
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/5.2.nix b/nixpkgs/pkgs/development/interpreters/lua-5/5.2.nix
index a8badf647c0c..e89a2cbece6d 100644
--- a/nixpkgs/pkgs/development/interpreters/lua-5/5.2.nix
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/5.2.nix
@@ -1,4 +1,10 @@
-{ stdenv, fetchurl, readline, compat ? false }:
+{ stdenv, fetchurl, readline
+# compiles compatibility layer with lua5.1
+, compat ? false
+, callPackage
+, self
+, packageOverrides ? (self: super: {})
+}:
 
 let
   dsoPatch = fetchurl {
@@ -6,12 +12,17 @@ let
     sha256 = "1by1dy4ql61f5c6njq9ibf9kaqm3y633g2q8j54iyjr4cxvqwqz9";
     name = "lua-arch.patch";
   };
+  luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};
 in
 stdenv.mkDerivation rec {
   name = "lua-${version}";
   luaversion = "5.2";
   version = "${luaversion}.4";
 
+  LuaPathSearchPaths    = luaPackages.getLuaPathList luaversion;
+  LuaCPathSearchPaths   = luaPackages.getLuaCPathList luaversion;
+  setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;
+
   src = fetchurl {
     url = "https://www.lua.org/ftp/${name}.tar.gz";
     sha256 = "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr";
@@ -21,6 +32,19 @@ stdenv.mkDerivation rec {
 
   patches = if stdenv.isDarwin then [ ./5.2.darwin.patch ] else [ dsoPatch ];
 
+
+  passthru = rec {
+    buildEnv = callPackage ./wrapper.nix {
+      lua = self;
+      inherit (luaPackages) requiredLuaModules;
+    };
+    withPackages = import ./with-packages.nix { inherit buildEnv luaPackages;};
+    pkgs = luaPackages;
+    interpreter = "${self}/bin/lua";
+  };
+
+  enableParallelBuilding = true;
+
   configurePhase =
     if stdenv.isDarwin
     then ''
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/5.3.nix b/nixpkgs/pkgs/development/interpreters/lua-5/5.3.nix
index eb34391e1993..c1fdc0fd9904 100644
--- a/nixpkgs/pkgs/development/interpreters/lua-5/5.3.nix
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/5.3.nix
@@ -1,5 +1,11 @@
-{ stdenv, fetchurl, readline, compat ? false }:
-
+{ stdenv, fetchurl, readline, compat ? false
+, callPackage
+, self
+, packageOverrides ? (self: super: {})
+}:
+let
+  luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};
+in
 stdenv.mkDerivation rec {
   name = "lua-${version}";
   luaversion = "5.3";
@@ -10,6 +16,10 @@ stdenv.mkDerivation rec {
     sha256 = "0c2eed3f960446e1a3e4b9a1ca2f3ff893b6ce41942cf54d5dd59ab4b3b058ac";
   };
 
+  LuaPathSearchPaths    = luaPackages.getLuaPathList luaversion;
+  LuaCPathSearchPaths   = luaPackages.getLuaCPathList luaversion;
+  setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;
+
   buildInputs = [ readline ];
 
   patches = if stdenv.isDarwin then [ ./5.2.darwin.patch ] else [];
@@ -54,6 +64,16 @@ stdenv.mkDerivation rec {
     ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua${luaversion}.pc"
   '';
 
+  passthru = rec {
+    buildEnv = callPackage ./wrapper.nix {
+      lua = self;
+      inherit (luaPackages) requiredLuaModules;
+    };
+    withPackages = import ./with-packages.nix { inherit buildEnv luaPackages;};
+    pkgs = luaPackages;
+    interpreter = "${self}/bin/lua";
+  };
+
   meta = {
     homepage = http://www.lua.org;
     description = "Powerful, fast, lightweight, embeddable scripting language";
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/build-lua-package.nix b/nixpkgs/pkgs/development/interpreters/lua-5/build-lua-package.nix
new file mode 100644
index 000000000000..0bed5efe4f79
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/build-lua-package.nix
@@ -0,0 +1,182 @@
+# Generic builder for lua packages
+{ lib
+, lua
+, stdenv
+, wrapLua
+, unzip
+, writeText
+# Whether the derivation provides a lua module or not.
+, toLuaModule
+}:
+
+{
+name ? "${attrs.pname}-${attrs.version}"
+
+, version
+
+# by default prefix `name` e.g. "lua5.2-${name}"
+, namePrefix ? "lua" + lua.luaversion + "-"
+
+# Dependencies for building the package
+, buildInputs ? []
+
+# Dependencies needed for running the checkPhase.
+# These are added to buildInputs when doCheck = true.
+, checkInputs ? []
+
+# propagate build dependencies so in case we have A -> B -> C,
+# C can import package A propagated by B
+, propagatedBuildInputs ? []
+, propagatedNativeBuildInputs ? []
+
+# used to disable derivation, useful for specific lua versions
+, disabled ? false
+
+# Additional arguments to pass to the makeWrapper function, which wraps
+# generated binaries.
+, makeWrapperArgs ? []
+, external_deps ? propagatedBuildInputs ++ buildInputs
+
+# Skip wrapping of lua programs altogether
+, dontWrapLuaPrograms ? false
+
+, meta ? {}
+
+, passthru ? {}
+, doCheck ? false
+
+# appended to the luarocks generated config
+# in peculiar variables like { EVENT_INCDIR } can be useful to work around
+# luarocks limitations, ie, luarocks consider include/lib folders to be subfolders of the same package in external_deps_dirs
+# as explained in https://github.com/luarocks/luarocks/issues/766
+, extraConfig ? ""
+
+# relative to srcRoot, path to the rockspec to use when using rocks
+, rockspecFilename ?  "../*.rockspec"
+
+# must be set for packages that don't have a rock
+, knownRockspec ? null
+
+, ... } @ attrs:
+
+
+# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
+if disabled
+then throw "${name} not supported for interpreter ${lua}"
+else
+
+let
+
+  deps_dirs= lib.concatStringsSep ", " (
+    map (x: "\"${builtins.toString x}\"") external_deps
+  );
+
+  # TODO
+  # - add rocktrees (look at torch-distro.nix/https://github.com/luarocks/luarocks/wiki/Config-file-format)
+  # - silence warnings
+  luarocks_config = "luarocksConfig";
+  luarocks_content = ''
+    local_cache = ""
+    -- array of strings
+    external_deps_dirs = {
+    ${deps_dirs}
+    }
+    rocks_trees = {
+    }
+    ${extraConfig}
+  '';
+in
+toLuaModule ( lua.stdenv.mkDerivation (
+builtins.removeAttrs attrs ["disabled" "checkInputs"] // {
+
+  name = namePrefix + name;
+
+  buildInputs = [ wrapLua lua.pkgs.luarocks ]
+    ++ buildInputs
+    ++ lib.optionals doCheck checkInputs
+    ;
+
+  # propagate lua to active setup-hook in nix-shell
+  propagatedBuildInputs = propagatedBuildInputs ++ [ lua ];
+  doCheck = false;
+
+  # enabled only for src.rock
+  setSourceRoot= let
+    name_only=(builtins.parseDrvName name).name;
+  in
+    lib.optionalString (knownRockspec == null) ''
+    # format is rockspec_basename/source_basename
+    # rockspec can set it via spec.source.dir
+    folder=$(find . -mindepth 2 -maxdepth 2 -type d -path '*${name_only}*/*'|head -n1)
+    sourceRoot="$folder"
+  '';
+
+  configurePhase = ''
+    runHook preConfigure
+
+    cat > ${luarocks_config} <<EOF
+    ${luarocks_content}
+    EOF
+    export LUAROCKS_CONFIG=$PWD/${luarocks_config};
+  ''
+  + lib.optionalString (knownRockspec != null) ''
+
+    # prevents the following type of error:
+    # Inconsistency between rockspec filename (42fm1b3d7iv6fcbhgm9674as3jh6y2sh-luv-1.22.0-1.rockspec) and its contents (luv-1.22.0-1.rockspec)
+    rockspecFilename="$TMP/$(stripHash ''${knownRockspec})"
+    cp ''${knownRockspec} $rockspecFilename
+    runHook postConfigure
+  '';
+
+  buildPhase = ''
+    runHook preBuild
+
+    nix_debug "Using LUAROCKS_CONFIG=$LUAROCKS_CONFIG"
+
+    LUAROCKS=luarocks
+    if (( ''${NIX_DEBUG:-0} >= 1 )); then
+        LUAROCKS="$LUAROCKS --verbose"
+    fi
+
+    patchShebangs .
+
+    runHook postBuild
+  '';
+
+  postFixup = lib.optionalString (!dontWrapLuaPrograms) ''
+    wrapLuaPrograms
+  '' + attrs.postFixup or '''';
+
+  installPhase = attrs.installPhase or ''
+    runHook preInstall
+
+    # luarocks make assumes sources are available in cwd
+    # After the build is complete, it also installs the rock.
+    # If no argument is given, it looks for a rockspec in the current directory
+    # but some packages have several rockspecs in their source directory so
+    # we force the use of the upper level since it is
+    # the sole rockspec in that folder
+    # maybe we could reestablish dependency checking via passing --rock-trees
+
+    nix_debug "ROCKSPEC $rockspecFilename"
+    nix_debug "cwd: $PWD"
+    $LUAROCKS make --deps-mode=none --tree $out ''${rockspecFilename}
+
+    # to prevent collisions when creating environments
+    # also added -f as it doesn't always exist
+    # don't remove the whole directory as
+    rm -rf $out/lib/luarocks/rocks/manifest
+
+    runHook postInstall
+  '';
+
+  passthru = {
+    inherit lua; # The lua interpreter
+  } // passthru;
+
+  meta = with lib.maintainers; {
+    platforms = lua.meta.platforms;
+    # add extra maintainer(s) to every package
+    maintainers = (meta.maintainers or []) ++ [ ];
+  } // meta;
+}))
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/build-rocks.nix b/nixpkgs/pkgs/development/interpreters/lua-5/build-rocks.nix
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/build-rocks.nix
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/build-rockspec.nix b/nixpkgs/pkgs/development/interpreters/lua-5/build-rockspec.nix
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/build-rockspec.nix
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.nix b/nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.nix
new file mode 100644
index 000000000000..62caffd8d8a0
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.nix
@@ -0,0 +1,15 @@
+{ runCommand, lib, }:
+
+LuaPathSearchPaths: LuaCPathSearchPaths:
+
+let
+  hook = ./setup-hook.sh;
+in runCommand "lua-setup-hook.sh" {
+  # hum doesn't seem to like caps !! BUG ?
+  luapathsearchpaths=lib.escapeShellArgs LuaPathSearchPaths;
+  luacpathsearchpaths=lib.escapeShellArgs LuaCPathSearchPaths;
+} ''
+  cp ${hook} hook.sh
+  substituteAllInPlace hook.sh
+  mv hook.sh $out
+''
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.sh b/nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.sh
new file mode 100644
index 000000000000..3989bedffdb1
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/setup-hook.sh
@@ -0,0 +1,47 @@
+# set -e
+
+nix_print() {
+    if [ ${NIX_DEBUG:-0} -ge $1 ]; then
+        echo "$2"
+    fi
+}
+
+nix_debug() {
+    nix_print 3 "$1"
+}
+
+addToLuaSearchPathWithCustomDelimiter() {
+    local varName="$1"
+    local absPattern="$2"
+    # delete longest match starting from the lua placeholder '?'
+    local topDir="${absPattern%%\?*}"
+
+    # export only if the folder exists else LUA_PATH grows too big
+    if  [ ! -d "$topDir" ]; then return; fi
+
+    export "${varName}=${!varName:+${!varName};}${absPattern}"
+}
+
+addToLuaPath() {
+    local dir="$1"
+
+    if [[ ! -d "$dir" ]]; then
+        nix_debug "$dir not a directory abort"
+        return 0
+    fi
+    cd "$dir"
+    for pattern in @luapathsearchpaths@;
+    do
+        addToLuaSearchPathWithCustomDelimiter NIX_LUA_PATH "$PWD/$pattern"
+    done
+
+    # LUA_CPATH
+    for pattern in @luacpathsearchpaths@;
+    do
+        addToLuaSearchPathWithCustomDelimiter NIX_LUA_CPATH "$PWD/$pattern"
+    done
+    cd - >/dev/null
+}
+
+addEnvHooks "$hostOffset" addToLuaPath
+
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/with-packages.nix b/nixpkgs/pkgs/development/interpreters/lua-5/with-packages.nix
new file mode 100644
index 000000000000..0e0fbd397358
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/with-packages.nix
@@ -0,0 +1,4 @@
+{ buildEnv, luaPackages }:
+
+# this is a function that returns a function that returns an environment
+f: let packages = f luaPackages; in buildEnv.override { extraLibs = packages; }
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/wrap-lua.nix b/nixpkgs/pkgs/development/interpreters/lua-5/wrap-lua.nix
new file mode 100644
index 000000000000..f00e0d5ac336
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/wrap-lua.nix
@@ -0,0 +1,19 @@
+{ lib
+, lua
+, makeSetupHook
+, makeWrapper
+}:
+
+with lib;
+
+# defined in trivial-builders.nix
+# imported as wrapLua in lua-packages.nix and passed to build-lua-derivation to be used as buildInput
+makeSetupHook {
+      deps = makeWrapper;
+      substitutions.executable = lua.interpreter;
+      substitutions.lua = lua;
+      substitutions.LuaPathSearchPaths = lib.escapeShellArgs lua.LuaPathSearchPaths;
+      substitutions.LuaCPathSearchPaths = lib.escapeShellArgs lua.LuaPathSearchPaths;
+
+} ./wrap.sh
+
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/wrap.sh b/nixpkgs/pkgs/development/interpreters/lua-5/wrap.sh
new file mode 100644
index 000000000000..545a0ae271c4
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/wrap.sh
@@ -0,0 +1,99 @@
+# Inspired by python/wrapper.nix
+# Wrapper around wrapLuaProgramsIn, below. The $luaPath
+# variable is passed in from the buildLuarocksPackage function.
+set -e
+
+wrapLuaPrograms() {
+    wrapLuaProgramsIn "$out/bin" "$out $luaPath"
+}
+
+# Builds environment variables like LUA_PATH and PATH walking through closure
+# of dependencies.
+buildLuaPath() {
+    local luaPath="$1"
+    local path
+
+    # Create an empty table of paths (see doc on loadFromPropagatedInputs
+    # for how this is used). Build up the program_PATH and program_LUA_PATH
+    # variables.
+    declare -A luaPathsSeen=()
+    program_PATH=
+    luaPathsSeen["@lua@"]=1
+    addToSearchPath program_PATH @lua@/bin
+    for path in $luaPath; do
+        addToLuaPath "$path"
+    done
+}
+
+
+# with an executable shell script which will set some environment variables
+# and then call into the original binary (which has been given a .wrapped suffix).
+# luaPath is a list of directories
+wrapLuaProgramsIn() {
+    local dir="$1"
+    local luaPath="$2"
+    local f
+
+    buildLuaPath "$luaPath"
+
+    if [ ! -d "$dir" ]; then
+        nix_debug "$dir not a directory"
+        return
+    fi
+
+    nix_debug "wrapping programs in [$dir]"
+
+    # Find all regular files in the output directory that are executable.
+    find "$dir" -type f -perm -0100 -print0 | while read -d "" f; do
+        # Rewrite "#! .../env lua" to "#! /nix/store/.../lua".
+        # Strip suffix, like "3" or "2.7m" -- we don't have any choice on which
+        # Lua to use besides one with this hook anyway.
+        if head -n1 "$f" | grep -q '#!.*/env.*\(lua\)'; then
+            sed -i "$f" -e "1 s^.*/env[ ]*\(lua\)[^ ]*^#! @executable@^"
+        fi
+
+        # wrapProgram creates the executable shell script described
+        # above. The script will set LUA_(C)PATH and PATH variables!
+        # (see pkgs/build-support/setup-hooks/make-wrapper.sh)
+        local -a wrap_args=("$f"
+            --prefix PATH ':' "$program_PATH"
+            --prefix LUA_PATH ';' "$NIX_LUA_PATH"
+            --prefix LUA_CPATH ';' "$NIX_LUA_CPATH"
+        )
+
+        # Add any additional arguments provided by makeWrapperArgs
+        # argument to buildLuaPackage.
+        # makeWrapperArgs
+        local -a user_args="($makeWrapperArgs)"
+        local -a wrapProgramArgs=("${wrap_args[@]}" "${user_args[@]}")
+
+        # see setup-hooks/make-wrapper.sh
+        wrapProgram "${wrapProgramArgs[@]}"
+
+    done
+}
+
+# Adds the lib and bin directories to the LUA_PATH and PATH variables,
+# respectively. Recurses on any paths declared in
+# `propagated-native-build-inputs`, while avoiding duplicating paths by
+# flagging the directories it has visited in `luaPathsSeen`.
+loadFromPropagatedInputs() {
+    local dir="$1"
+    # Stop if we've already visited here.
+    if [ -n "${luaPathsSeen[$dir]}" ]; then
+        return;
+    fi
+    luaPathsSeen[$dir]=1
+
+    addToLuaPath "$dir"
+    addToSearchPath program_PATH $dir/bin
+
+    # Inspect the propagated inputs (if they exist) and recur on them.
+    local prop="$dir/nix-support/propagated-native-build-inputs"
+    if [ -e "$prop" ]; then
+        local new_path
+        for new_path in $(cat $prop); do
+            loadFromPropagatedInputs "$new_path"
+        done
+    fi
+}
diff --git a/nixpkgs/pkgs/development/interpreters/lua-5/wrapper.nix b/nixpkgs/pkgs/development/interpreters/lua-5/wrapper.nix
new file mode 100644
index 000000000000..7f584c0f0aff
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/lua-5/wrapper.nix
@@ -0,0 +1,73 @@
+{ stdenv, lua, buildEnv, makeWrapper
+, extraLibs ? []
+, extraOutputsToInstall ? []
+, postBuild ? ""
+, ignoreCollisions ? false
+, lib
+, requiredLuaModules
+, makeWrapperArgs ? []
+}:
+
+# Create a lua executable that knows about additional packages.
+let
+  env = let
+    paths =  requiredLuaModules (extraLibs ++ [ lua ] );
+  in buildEnv {
+    name = "${lua.name}-env";
+
+    inherit paths;
+    inherit ignoreCollisions;
+    extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
+
+    # we create wrapper for the binaries in the different packages
+    postBuild = ''
+
+      . "${makeWrapper}/nix-support/setup-hook"
+
+      # get access to lua functions
+      . ${lua}/nix-support/setup-hook
+
+      if [ -L "$out/bin" ]; then
+          unlink "$out/bin"
+      fi
+      mkdir -p "$out/bin"
+
+      addToLuaPath "$out"
+
+      # take every binary from lua packages and put them into the env
+      for path in ${stdenv.lib.concatStringsSep " " paths}; do
+        nix_debug "looking for binaries in path = $path"
+        if [ -d "$path/bin" ]; then
+          cd "$path/bin"
+          for prg in *; do
+            if [ -f "$prg" ]; then
+              rm -f "$out/bin/$prg"
+              if [ -x "$prg" ]; then
+                nix_debug "Making wrapper $prg"
+                makeWrapper "$path/bin/$prg" "$out/bin/$prg" --suffix LUA_PATH ';' "$NIX_LUA_PATH"   --suffix LUA_CPATH ';' "$NIX_LUA_CPATH" ${stdenv.lib.concatStringsSep " " makeWrapperArgs}
+              fi
+            fi
+          done
+        fi
+      done
+    '' + postBuild;
+
+    inherit (lua) meta;
+
+    passthru = lua.passthru // {
+      interpreter = "${env}/bin/lua";
+      inherit lua;
+      env = stdenv.mkDerivation {
+        name = "interactive-${lua.name}-environment";
+        nativeBuildInputs = [ env ];
+
+        buildCommand = ''
+          echo >&2 ""
+          echo >&2 "*** lua 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
+          echo >&2 ""
+          exit 1
+        '';
+    };
+    };
+  };
+in env
diff --git a/nixpkgs/pkgs/development/interpreters/luajit/2.0.nix b/nixpkgs/pkgs/development/interpreters/luajit/2.0.nix
new file mode 100644
index 000000000000..0889b7fefe68
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/luajit/2.0.nix
@@ -0,0 +1,10 @@
+{ self, callPackage, lib }:
+callPackage ./default.nix {
+  inherit self;
+  version = "2.0.5";
+  isStable = true;
+  sha256 = "0yg9q4q6v028bgh85317ykc9whgxgysp76qzaqgq55y6jy11yjw7";
+  extraMeta = {
+    platforms = lib.filter (p: p != "aarch64-linux") lib.meta.platforms;
+  };
+}
diff --git a/nixpkgs/pkgs/development/interpreters/luajit/2.1.nix b/nixpkgs/pkgs/development/interpreters/luajit/2.1.nix
new file mode 100644
index 000000000000..0f223963132e
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/luajit/2.1.nix
@@ -0,0 +1,7 @@
+{ self, callPackage, lib }:
+callPackage ./default.nix {
+  inherit self;
+  version = "2.1.0-beta3";
+  isStable = false;
+  sha256 = "1hyrhpkwjqsv54hnnx4cl8vk44h9d6c9w0fz1jfjz00w255y7lhs";
+}
diff --git a/nixpkgs/pkgs/development/interpreters/luajit/default.nix b/nixpkgs/pkgs/development/interpreters/luajit/default.nix
index 9ee628f498ee..c95b9e8b8e37 100644
--- a/nixpkgs/pkgs/development/interpreters/luajit/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/luajit/default.nix
@@ -1,71 +1,74 @@
-{ stdenv, lib, fetchurl }:
-rec {
+{ stdenv, lib, fetchurl
+, name ? "luajit-${version}"
+, isStable
+, sha256
+, version
+, extraMeta ? {}
+, callPackage
+, self
+, packageOverrides ? (self: super: {})
+}:
+let
+  luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};
+in
+stdenv.mkDerivation rec {
+  inherit name version;
+  src = fetchurl {
+    url = "http://luajit.org/download/LuaJIT-${version}.tar.gz";
+    inherit sha256;
+  };
 
-  luajit = luajit_2_1;
+  luaversion = "5.1";
 
-  luajit_2_0 = generic {
-    version = "2.0.5";
-    isStable = true;
-    sha256 = "0yg9q4q6v028bgh85317ykc9whgxgysp76qzaqgq55y6jy11yjw7";
-    meta = genericMeta // {
-      platforms = lib.filter (p: p != "aarch64-linux") genericMeta.platforms;
-    };
-  };
+  patchPhase = ''
+    substituteInPlace Makefile \
+      --replace /usr/local "$out"
+
+    substituteInPlace src/Makefile --replace gcc cc
+  '' + stdenv.lib.optionalString (stdenv.cc.libc != null)
+  ''
+    substituteInPlace Makefile \
+      --replace ldconfig ${stdenv.cc.libc.bin or stdenv.cc.libc}/bin/ldconfig
+  '';
+
+  configurePhase = false;
 
-  luajit_2_1 = generic {
-    version = "2.1.0-beta3";
-    isStable = false;
-    sha256 = "1hyrhpkwjqsv54hnnx4cl8vk44h9d6c9w0fz1jfjz00w255y7lhs";
+  buildFlags = [ "amalg" ]; # Build highly optimized version
+  enableParallelBuilding = true;
+
+  installPhase   = ''
+      make install PREFIX="$out"
+      ( cd "$out/include"; ln -s luajit-*/* . )
+      ln -s "$out"/bin/luajit-* "$out"/bin/lua
+    ''
+    + stdenv.lib.optionalString (!isStable) ''
+      ln -s "$out"/bin/luajit-* "$out"/bin/luajit
+    '';
+
+  LuaPathSearchPaths = [
+    "lib/lua/${luaversion}/?.lua" "share/lua/${luaversion}/?.lua"
+    "share/lua/${luaversion}/?/init.lua" "lib/lua/${luaversion}/?/init.lua"
+    "share/${name}/?.lua"
+  ];
+  LuaCPathSearchPaths = [ "lib/lua/${luaversion}/?.so" "share/lua/${luaversion}/?.so" ];
+  setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;
+
+  passthru = rec {
+    buildEnv = callPackage ../lua-5/wrapper.nix {
+      lua = self;
+      inherit (luaPackages) requiredLuaModules;
+    };
+    withPackages = import ../lua-5/with-packages.nix { inherit buildEnv luaPackages;};
+    pkgs = luaPackages;
+    interpreter = "${self}/bin/lua";
   };
 
-  genericMeta = with stdenv.lib; {
+  meta = with stdenv.lib; extraMeta // {
     description = "High-performance JIT compiler for Lua 5.1";
     homepage    = http://luajit.org;
     license     = licenses.mit;
     platforms   = platforms.linux ++ platforms.darwin;
     maintainers = with maintainers; [ thoughtpolice smironov vcunat andir ];
   };
-
-  generic =
-    { version, sha256 ? null, isStable
-    , name ? "luajit-${version}"
-    , src ?
-      (fetchurl {
-        url = "http://luajit.org/download/LuaJIT-${version}.tar.gz";
-        inherit sha256;
-      })
-    , meta ? genericMeta
-    }:
-
-    stdenv.mkDerivation rec {
-      inherit name version src meta;
-
-      luaversion = "5.1";
-
-      patchPhase = ''
-        substituteInPlace Makefile \
-          --replace /usr/local "$out"
-
-        substituteInPlace src/Makefile --replace gcc cc
-      '' + stdenv.lib.optionalString (stdenv.cc.libc != null)
-      ''
-        substituteInPlace Makefile \
-          --replace ldconfig ${stdenv.cc.libc.bin or stdenv.cc.libc}/bin/ldconfig
-      '';
-
-      configurePhase = false;
-
-      buildFlags = [ "amalg" ]; # Build highly optimized version
-      enableParallelBuilding = true;
-
-      installPhase   = ''
-        make install PREFIX="$out"
-        ( cd "$out/include"; ln -s luajit-*/* . )
-        ln -s "$out"/bin/luajit-* "$out"/bin/lua
-      ''
-        + stdenv.lib.optionalString (!isStable)
-          ''
-            ln -s "$out"/bin/luajit-* "$out"/bin/luajit
-          '';
-    };
 }
+
diff --git a/nixpkgs/pkgs/development/interpreters/lush/default.nix b/nixpkgs/pkgs/development/interpreters/lush/default.nix
index 9575409f9868..5a241fbf83ee 100644
--- a/nixpkgs/pkgs/development/interpreters/lush/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/lush/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl, libX11, xproto, indent, readline, gsl, freeglut, libGLU_combined, SDL
+{stdenv, fetchurl, libX11, xorgproto, indent, readline, gsl, freeglut, libGLU_combined, SDL
 , blas, libbfd, intltool, gettext, zlib, libSM}:
 
 stdenv.mkDerivation rec {
@@ -12,7 +12,7 @@ stdenv.mkDerivation rec {
   };
 
   buildInputs = [
-    libX11 libSM xproto indent readline gsl freeglut libGLU_combined SDL blas libbfd
+    libX11 libSM xorgproto indent readline gsl freeglut libGLU_combined SDL blas libbfd
     intltool gettext zlib
   ];
 
diff --git a/nixpkgs/pkgs/development/interpreters/metamath/default.nix b/nixpkgs/pkgs/development/interpreters/metamath/default.nix
index 2fb1ccb24bc4..e8e23cee830a 100644
--- a/nixpkgs/pkgs/development/interpreters/metamath/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/metamath/default.nix
@@ -2,7 +2,7 @@
 
 stdenv.mkDerivation rec {
   name = "metamath-${version}";
-  version = "0.168";
+  version = "0.172";
 
   buildInputs = [ autoreconfHook ];
 
@@ -13,8 +13,8 @@ stdenv.mkDerivation rec {
   src = fetchFromGitHub {
     owner = "Taneb";
     repo = "metamath";
-    rev = "542bfd5e53d8ce026ce5d29da9e7069ec807f5e0";
-    sha256 = "07ssgqh9ipiw1bf60snmjaxngln1an1h9q0vgszadc94wzw06zi4";
+    rev = "43141cd17638f8efb409dc5d46e7de6a6c39ec42";
+    sha256 = "07c7df0zl0wsb0pvdgkwikpr8kz7fi3mshxzk61vkamyp68djjb5";
   };
 
   meta = with stdenv.lib; {
diff --git a/nixpkgs/pkgs/development/interpreters/mujs/default.nix b/nixpkgs/pkgs/development/interpreters/mujs/default.nix
index c7663a116763..918b2c2515e2 100644
--- a/nixpkgs/pkgs/development/interpreters/mujs/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/mujs/default.nix
@@ -1,22 +1,22 @@
-{ stdenv, fetchgit, clang }:
+{ stdenv, fetchurl, readline }:
 
 stdenv.mkDerivation rec {
-  name = "mujs-2017-01-24";
+  name = "mujs-${version}";
+  version = "1.0.5";
 
-  src = fetchgit {
-    url = git://git.ghostscript.com/mujs.git;
-    rev  = "4006739a28367c708dea19aeb19b8a1a9326ce08";
-    sha256 = "0wvjl8lkh0ga6fkmxgjqq77yagncbv1bdy6hpnxq31x3mkwn1s51";
+  src = fetchurl {
+    url = "https://mujs.com/downloads/mujs-${version}.tar.xz";
+    sha256 = "02cqrfnww2s3ylcvqin1951f2c5nzpby8gxb207p2hbrivbg8f0l";
   };
 
-  buildInputs = [ clang ];
+  buildInputs = [ readline ];
 
   makeFlags = [ "prefix=$(out)" ];
 
   meta = with stdenv.lib; {
     homepage = http://mujs.com/;
     description = "A lightweight, embeddable Javascript interpreter";
-    platforms = stdenv.lib.platforms.linux;
+    platforms = platforms.unix;
     maintainers = with maintainers; [ pSub ];
     license = licenses.gpl3;
   };
diff --git a/nixpkgs/pkgs/development/interpreters/perl/default.nix b/nixpkgs/pkgs/development/interpreters/perl/default.nix
index 8d21d92ef430..5e8f5e2d59b6 100644
--- a/nixpkgs/pkgs/development/interpreters/perl/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/perl/default.nix
@@ -42,13 +42,14 @@ let
     patches =
       [
         # Do not look in /usr etc. for dependencies.
-        ./no-sys-dirs-5.26.patch
+        (if (versionOlder version "5.29.6") then ./no-sys-dirs-5.26.patch else ./no-sys-dirs-5.29.patch)
+      ]
+      ++ optional (versionOlder version "5.29.6")
         # Fix parallel building: https://rt.perl.org/Public/Bug/Display.html?id=132360
         (fetchurlBoot {
           url = "https://rt.perl.org/Public/Ticket/Attachment/1502646/807252/0001-Fix-missing-build-dependency-for-pods.patch";
           sha256 = "1bb4mldfp8kq1scv480wm64n2jdsqa3ar46cjp1mjpby8h5dr2r0";
         })
-      ]
       ++ optional stdenv.isSunOS ./ld-shared.patch
       ++ optionals stdenv.isDarwin [ ./cpp-precomp.patch ./sw_vers.patch ]
       ++ optional crossCompiling ./MakeMaker-cross.patch;
@@ -153,11 +154,11 @@ let
       platforms = platforms.all;
     };
   } // stdenv.lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) rec {
-    crossVersion = "ab8d05c9e695d3db4f7dc15c70f23623349c2f49"; # Oct 03, 2018
+    crossVersion = "276849e62f472c1b241d9e7b38a28e4cc9f98563"; # Dez 02, 2018
 
     perl-cross-src = fetchurlBoot {
       url = "https://github.com/arsv/perl-cross/archive/${crossVersion}.tar.gz";
-      sha256 = "1g7p7mqmx8x3diqvbh881gr72d106cn6yvm4gx7f0ars3n3b3wj0";
+      sha256 = "1fpr1m9lgkwdp1vmdr0s6gvmcpd0m8q6jwn024bkczc2h37bdynd";
     };
 
     depsBuildBuild = [ buildPackages.stdenv.cc makeWrapper ];
@@ -173,20 +174,15 @@ let
     setupHook = ./setup-hook-cross.sh;
   });
 in rec {
-  perl526 = common {
-    version = "5.26.2";
-    sha256 = "03gpnxx1g6hvlh0v4aqx00580h787sfywp1vlvw64q2xcbm9qbsp";
-  };
-
   # the latest Maint version
   perl528 = common {
-    version = "5.28.0";
-    sha256 = "1a3f822lcl8dr8v0hk80yyhpzqlljg49z9flb48rs3nbsij9z4ky";
+    version = "5.28.1";
+    sha256 = "0iy3as4hnbjfyws4in3j9d6zhhjxgl5m95i5n9jy2bnzcpz8bgry";
   };
 
   # the latest Devel version
   perldevel = common {
-    version = "5.29.4";
-    sha256 = "153r0f6jdqrl7hxrvhfivf5g8ivhbvggfhg841q3hi3db5rc86k4";
+    version = "5.29.6";
+    sha256 = "0wj2bia8s30788f69mf5s533l72zbhqpdr85kkk97yrh1c9sgcd6";
   };
 }
diff --git a/nixpkgs/pkgs/development/interpreters/perl/no-sys-dirs-5.29.patch b/nixpkgs/pkgs/development/interpreters/perl/no-sys-dirs-5.29.patch
new file mode 100644
index 000000000000..0ccf6254b782
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/perl/no-sys-dirs-5.29.patch
@@ -0,0 +1,251 @@
+diff -ru -x '*~' -x '*.rej' perl-5.20.0-orig/Configure perl-5.20.0/Configure
+--- perl-5.20.0-orig/Configure	2014-05-26 15:34:18.000000000 +0200
++++ perl-5.20.0/Configure	2014-06-25 10:43:35.368285986 +0200
+@@ -106,15 +106,7 @@
+ fi
+ 
+ : Proper PATH setting
+-paths='/bin /usr/bin /usr/local/bin /usr/ucb /usr/local /usr/lbin'
+-paths="$paths /opt/bin /opt/local/bin /opt/local /opt/lbin"
+-paths="$paths /usr/5bin /etc /usr/gnu/bin /usr/new /usr/new/bin /usr/nbin"
+-paths="$paths /opt/gnu/bin /opt/new /opt/new/bin /opt/nbin"
+-paths="$paths /sys5.3/bin /sys5.3/usr/bin /bsd4.3/bin /bsd4.3/usr/ucb"
+-paths="$paths /bsd4.3/usr/bin /usr/bsd /bsd43/bin /opt/ansic/bin /usr/ccs/bin"
+-paths="$paths /etc /usr/lib /usr/ucblib /lib /usr/ccs/lib"
+-paths="$paths /sbin /usr/sbin /usr/libexec"
+-paths="$paths /system/gnu_library/bin"
++paths=''
+ 
+ for p in $paths
+ do
+@@ -1337,8 +1329,7 @@
+ archname=''
+ : Possible local include directories to search.
+ : Set locincpth to "" in a hint file to defeat local include searches.
+-locincpth="/usr/local/include /opt/local/include /usr/gnu/include"
+-locincpth="$locincpth /opt/gnu/include /usr/GNU/include /opt/GNU/include"
++locincpth=""
+ :
+ : no include file wanted by default
+ inclwanted=''
+@@ -1349,17 +1340,12 @@
+ 
+ libnames=''
+ : change the next line if compiling for Xenix/286 on Xenix/386
+-xlibpth='/usr/lib/386 /lib/386'
++xlibpth=''
+ : Possible local library directories to search.
+-loclibpth="/usr/local/lib /opt/local/lib /usr/gnu/lib"
+-loclibpth="$loclibpth /opt/gnu/lib /usr/GNU/lib /opt/GNU/lib"
++loclibpth=""
+ 
+ : general looking path for locating libraries
+-glibpth="/lib /usr/lib $xlibpth"
+-glibpth="$glibpth /usr/ccs/lib /usr/ucblib /usr/local/lib"
+-test -f /usr/shlib/libc.so && glibpth="/usr/shlib $glibpth"
+-test -f /shlib/libc.so     && glibpth="/shlib $glibpth"
+-test -d /usr/lib64         && glibpth="$glibpth /lib64 /usr/lib64 /usr/local/lib64"
++glibpth=""
+ 
+ : Private path used by Configure to find libraries.  Its value
+ : is prepended to libpth. This variable takes care of special
+@@ -1391,8 +1377,6 @@
+ libswanted="$libswanted m crypt sec util c cposix posix ucb bsd BSD"
+ : We probably want to search /usr/shlib before most other libraries.
+ : This is only used by the lib/ExtUtils/MakeMaker.pm routine extliblist.
+-glibpth=`echo " $glibpth " | sed -e 's! /usr/shlib ! !'`
+-glibpth="/usr/shlib $glibpth"
+ : Do not use vfork unless overridden by a hint file.
+ usevfork=false
+ 
+@@ -2446,7 +2430,6 @@
+ zip
+ "
+ pth=`echo $PATH | sed -e "s/$p_/ /g"`
+-pth="$pth $sysroot/lib $sysroot/usr/lib"
+ for file in $loclist; do
+ 	eval xxx=\$$file
+ 	case "$xxx" in
+@@ -4936,7 +4919,7 @@
+ : Set private lib path
+ case "$plibpth" in
+ '') if ./mips; then
+-	plibpth="$incpath/usr/lib $sysroot/usr/local/lib $sysroot/usr/ccs/lib"
++	plibpth="$incpath/usr/lib"
+     fi;;
+ esac
+ case "$libpth" in
+@@ -8600,13 +8583,8 @@
+ echo " "
+ case "$sysman" in
+ '')
+-	syspath='/usr/share/man/man1 /usr/man/man1'
+-	syspath="$syspath /usr/man/mann /usr/man/manl /usr/man/local/man1"
+-	syspath="$syspath /usr/man/u_man/man1"
+-	syspath="$syspath /usr/catman/u_man/man1 /usr/man/l_man/man1"
+-	syspath="$syspath /usr/local/man/u_man/man1 /usr/local/man/l_man/man1"
+-	syspath="$syspath /usr/man/man.L /local/man/man1 /usr/local/man/man1"
+-	sysman=`./loc . /usr/man/man1 $syspath`
++	syspath=''
++	sysman=''
+ 	;;
+ esac
+ if $test -d "$sysman"; then
+@@ -19900,9 +19878,10 @@
+ case "$full_ar" in
+ '') full_ar=$ar ;;
+ esac
++full_ar=ar
+ 
+ : Store the full pathname to the sed program for use in the C program
+-full_sed=$sed
++full_sed=sed
+ 
+ : see what type gids are declared as in the kernel
+ echo " "
+Only in perl-5.20.0/: Configure.orig
+diff -ru -x '*~' -x '*.rej' perl-5.20.0-orig/ext/Errno/Errno_pm.PL perl-5.20.0/ext/Errno/Errno_pm.PL
+--- perl-5.20.0-orig/ext/Errno/Errno_pm.PL	2014-05-26 15:34:20.000000000 +0200
++++ perl-5.20.0/ext/Errno/Errno_pm.PL	2014-06-25 10:31:24.317970047 +0200
+@@ -134,12 +126,7 @@
+ 	if ($dep =~ /(\S+errno\.h)/) {
+ 	     $file{$1} = 1;
+ 	}
+-    } elsif ($^O eq 'linux' &&
+-	      $Config{gccversion} ne '' && 
+-	      $Config{gccversion} !~ /intel/i &&
+-	      # might be using, say, Intel's icc
+-	      $linux_errno_h
+-	     ) {
++    } elsif (0) {
+	$file{$linux_errno_h} = 1;
+     } elsif ($^O eq 'haiku') {
+	# hidden in a special place
+Only in perl-5.20.0/ext/Errno: Errno_pm.PL.orig
+diff -ru -x '*~' -x '*.rej' perl-5.20.0-orig/hints/freebsd.sh perl-5.20.0/hints/freebsd.sh
+--- perl-5.20.0-orig/hints/freebsd.sh	2014-01-31 22:55:51.000000000 +0100
++++ perl-5.20.0/hints/freebsd.sh	2014-06-25 10:25:53.263964680 +0200
+@@ -119,21 +119,21 @@
+         objformat=`/usr/bin/objformat`
+         if [ x$objformat = xaout ]; then
+             if [ -e /usr/lib/aout ]; then
+-                libpth="/usr/lib/aout /usr/local/lib /usr/lib"
+-                glibpth="/usr/lib/aout /usr/local/lib /usr/lib"
++                libpth=""
++                glibpth=""
+             fi
+             lddlflags='-Bshareable'
+         else
+-            libpth="/usr/lib /usr/local/lib"
+-            glibpth="/usr/lib /usr/local/lib"
++            libpth=""
++            glibpth=""
+             ldflags="-Wl,-E "
+             lddlflags="-shared "
+         fi
+         cccdlflags='-DPIC -fPIC'
+         ;;
+ *)
+-       libpth="/usr/lib /usr/local/lib"
+-       glibpth="/usr/lib /usr/local/lib"
++       libpth=""
++       glibpth=""
+        ldflags="-Wl,-E "
+         lddlflags="-shared "
+         cccdlflags='-DPIC -fPIC'
+diff -ru -x '*~' -x '*.rej' perl-5.20.0-orig/hints/linux.sh perl-5.20.0/hints/linux.sh
+--- perl-5.20.0-orig/hints/linux.sh	2014-05-26 15:34:20.000000000 +0200
++++ perl-5.20.0/hints/linux.sh	2014-06-25 10:33:47.354883843 +0200
+@@ -150,25 +150,6 @@
+     ;;
+ esac
+ 
+-# Ubuntu 11.04 (and later, presumably) doesn't keep most libraries
+-# (such as -lm) in /lib or /usr/lib.  So we have to ask gcc to tell us
+-# where to look.  We don't want gcc's own libraries, however, so we
+-# filter those out.
+-# This could be conditional on Unbuntu, but other distributions may
+-# follow suit, and this scheme seems to work even on rather old gcc's.
+-# This unconditionally uses gcc because even if the user is using another
+-# compiler, we still need to find the math library and friends, and I don't
+-# know how other compilers will cope with that situation.
+-# Morever, if the user has their own gcc earlier in $PATH than the system gcc,
+-# we don't want its libraries. So we try to prefer the system gcc
+-# Still, as an escape hatch, allow Configure command line overrides to
+-# plibpth to bypass this check.
+-if [ -x /usr/bin/gcc ] ; then
+-    gcc=/usr/bin/gcc
+-else
+-    gcc=gcc
+-fi
+-
+ case "$plibpth" in
+ '') plibpth=`LANG=C LC_ALL=C $gcc $ccflags $ldflags -print-search-dirs | grep libraries |
+ 	cut -f2- -d= | tr ':' $trnl | grep -v 'gcc' | sed -e 's:/$::'`
+@@ -178,32 +159,6 @@
+     ;;
+ esac
+ 
+-case "$libc" in
+-'')
+-# If you have glibc, then report the version for ./myconfig bug reporting.
+-# (Configure doesn't need to know the specific version since it just uses
+-# gcc to load the library for all tests.)
+-# We don't use __GLIBC__ and  __GLIBC_MINOR__ because they
+-# are insufficiently precise to distinguish things like
+-# libc-2.0.6 and libc-2.0.7.
+-    for p in $plibpth
+-    do
+-        for trylib in libc.so.6 libc.so
+-        do
+-            if $test -e $p/$trylib; then
+-                libc=`ls -l $p/$trylib | awk '{print $NF}'`
+-                if $test "X$libc" != X; then
+-                    break
+-                fi
+-            fi
+-        done
+-        if $test "X$libc" != X; then
+-            break
+-        fi
+-    done
+-    ;;
+-esac
+-
+ if ${sh:-/bin/sh} -c exit; then
+   echo ''
+   echo 'You appear to have a working bash.  Good.'
+@@ -367,33 +322,6 @@
+ 	;;
+ esac
+ 
+-# SuSE8.2 has /usr/lib/libndbm* which are ld scripts rather than
+-# true libraries. The scripts cause binding against static
+-# version of -lgdbm which is a bad idea. So if we have 'nm'
+-# make sure it can read the file
+-# NI-S 2003/08/07
+-case "$nm" in
+-    '') ;;
+-    *)
+-    for p in $plibpth
+-    do
+-        if $test -r $p/libndbm.so; then
+-            if $nm $p/libndbm.so >/dev/null 2>&1 ; then
+-                echo 'Your shared -lndbm seems to be a real library.'
+-                _libndbm_real=1
+-                break
+-            fi
+-        fi
+-    done
+-    if $test "X$_libndbm_real" = X; then
+-        echo 'Your shared -lndbm is not a real library.'
+-        set `echo X "$libswanted "| sed -e 's/ ndbm / /'`
+-        shift
+-        libswanted="$*"
+-    fi
+-    ;;
+-esac
+-
+ # Linux on Synology.
+ if [ -f /etc/synoinfo.conf -a -d /usr/syno ]; then
+     # Tested on Synology DS213 and DS413
diff --git a/nixpkgs/pkgs/development/interpreters/php/default.nix b/nixpkgs/pkgs/development/interpreters/php/default.nix
index 2757b9bd4bab..3d9235757c6e 100644
--- a/nixpkgs/pkgs/development/interpreters/php/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/php/default.nix
@@ -245,30 +245,26 @@ let
 
 in {
   php71 = generic {
-    version = "7.1.25";
-    sha256 = "1b5az5vhap593ggjxirs1zdlg20hcv9h94iq5kgaxky71a4dqb00";
+    version = "7.1.26";
+    sha256 = "1riaaizyl0jv9p6b8sm8xxj8iqz4p4dddwdag03n1r67dfl1qdav";
 
     # https://bugs.php.net/bug.php?id=76826
     extraPatches = optional stdenv.isDarwin ./php71-darwin-isfinite.patch;
   };
 
   php72 = generic {
-    version = "7.2.13";
-    sha256 = "0bg9nfc250p24hxn4bdjz7ngcw75h8rpf4qjxqzcs6s9fvxlcjjv";
+    version = "7.2.14";
+    sha256 = "15v5gbdxi6jkgdflpj5rqqzzfvwdb55hls4azh71xgy793934qgm";
 
-    # https://bugs.php.net/bug.php?id=71041
     # https://bugs.php.net/bug.php?id=76826
-    extraPatches = [ ./fix-bug-71041.patch ]
-      ++ optional stdenv.isDarwin ./php72-darwin-isfinite.patch;
+    extraPatches = optional stdenv.isDarwin ./php72-darwin-isfinite.patch;
   };
 
   php73 = generic {
-    version = "7.3.0";
-    sha256 = "0rvwx37dsmxivgrf4wfc1y778iln498c6a40biy9k6lnr6p7s9ks";
+    version = "7.3.1";
+    sha256 = "13iqfkz9rmx9vy106lvw1nbk88qgwdkvxam0l5s14r7jsw62pvxg";
 
-    # https://bugs.php.net/bug.php?id=71041
     # https://bugs.php.net/bug.php?id=76826
-    extraPatches = [ ./fix-bug-71041.patch ]
-      ++ optional stdenv.isDarwin ./php73-darwin-isfinite.patch;
+    extraPatches = optional stdenv.isDarwin ./php73-darwin-isfinite.patch;
   };
 }
diff --git a/nixpkgs/pkgs/development/interpreters/php/fix-bug-71041.patch b/nixpkgs/pkgs/development/interpreters/php/fix-bug-71041.patch
deleted file mode 100644
index 350b635bdf36..000000000000
--- a/nixpkgs/pkgs/development/interpreters/php/fix-bug-71041.patch
+++ /dev/null
@@ -1,25 +0,0 @@
-diff --git a/Zend/zend_signal.c b/Zend/zend_signal.c
-index 24d454d..6307620 100644
---- a/Zend/zend_signal.c
-+++ b/Zend/zend_signal.c
-@@ -399,7 +399,7 @@ void zend_signal_init(void) /* {{{ */
- 
- /* {{{ zend_signal_startup
-  * alloc zend signal globals */
--void zend_signal_startup(void)
-+ZEND_API void zend_signal_startup(void)
- {
- 
- #ifdef ZTS
-diff --git a/Zend/zend_signal.h b/Zend/zend_signal.h
-index e8ee7d6..462d06f 100644
---- a/Zend/zend_signal.h
-+++ b/Zend/zend_signal.h
-@@ -89,7 +89,7 @@ ZEND_API void zend_signal_handler_unblock(void);
- void zend_signal_activate(void);
- void zend_signal_deactivate(void);
- BEGIN_EXTERN_C()
--void zend_signal_startup(void);
-+ZEND_API void zend_signal_startup(void);
- END_EXTERN_C()
- void zend_signal_init(void);
diff --git a/nixpkgs/pkgs/development/interpreters/picolisp/default.nix b/nixpkgs/pkgs/development/interpreters/picolisp/default.nix
index 37a5bdd0ce94..058a83b6b436 100644
--- a/nixpkgs/pkgs/development/interpreters/picolisp/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/picolisp/default.nix
@@ -1,22 +1,26 @@
-{ stdenv, fetchurl, jdk }:
+{ stdenv, fetchurl, jdk, makeWrapper }:
 with stdenv.lib;
 
 stdenv.mkDerivation rec {
   name = "picoLisp-${version}";
-  version = "16.12";
+  version = "18.12";
   src = fetchurl {
     url = "https://www.software-lab.de/${name}.tgz";
-    sha256 = "1k3x6mvk9b34iiyml142bzh3gf241f25ywjlaagbxzb9vklpws75";
+    sha256 = "0hvgq2vc03bki528jqn95xmvv7mw8xx832spfczhxc16wwbrnrhk";
   };
-  buildInputs = optional stdenv.is64bit jdk;
-  patchPhase = optionalString stdenv.isAarch32 ''
-    sed -i s/-m32//g Makefile
-    cat >>Makefile <<EOF
-    ext.o: ext.c
-    	\$(CC) \$(CFLAGS) -fPIC -D_OS='"\$(OS)"' \$*.c
-    ht.o: ht.c
-    	\$(CC) \$(CFLAGS) -fPIC -D_OS='"\$(OS)"' \$*.c
-    EOF
+  buildInputs = [makeWrapper] ++ optional stdenv.is64bit jdk;
+  patchPhase = ''
+    sed -i "s/which java/command -v java/g" mkAsm
+
+    ${optionalString stdenv.isAarch32 ''
+      sed -i s/-m32//g Makefile
+      cat >>Makefile <<EOF
+      ext.o: ext.c
+        \$(CC) \$(CFLAGS) -fPIC -D_OS='"\$(OS)"' \$*.c
+      ht.o: ht.c
+        \$(CC) \$(CFLAGS) -fPIC -D_OS='"\$(OS)"' \$*.c
+      EOF
+    ''}
   '';
   sourceRoot = ''picoLisp/src${optionalString stdenv.is64bit "64"}'';
   installPhase = ''
@@ -27,11 +31,13 @@ stdenv.mkDerivation rec {
     ln -s "$out/share/picolisp/build-dir" "$out/lib/picolisp"
     ln -s "$out/lib/picolisp/bin/picolisp" "$out/bin/picolisp"
 
-    cat >"$out/bin/pil" <<EOF
-    #! /bin/sh
-    exec $out/bin/picolisp $out/lib/picolisp/lib.l @lib/misc.l @lib/btree.l @lib/db.l @lib/pilog.l
-    EOF
-    chmod +x "$out/bin/pil"
+
+    makeWrapper $out/bin/picolisp $out/bin/pil \
+      --add-flags "$out/lib/picolisp/lib.l" \
+      --add-flags "@lib/misc.l" \
+      --add-flags "@lib/btree.l" \
+      --add-flags "@lib/db.l" \
+      --add-flags "@lib/pilog.l"
 
     mkdir -p "$out/share/emacs"
     ln -s "$out/lib/picolisp/lib/el" "$out/share/emacs/site-lisp"
diff --git a/nixpkgs/pkgs/development/interpreters/pixie/default.nix b/nixpkgs/pkgs/development/interpreters/pixie/default.nix
index 928a55173243..d1f2edce936d 100644
--- a/nixpkgs/pkgs/development/interpreters/pixie/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/pixie/default.nix
@@ -35,7 +35,7 @@ let
     nativeBuildInputs = [ makeWrapper pkgconfig ];
     buildInputs = libs;
     PYTHON = if buildWithPypy
-      then "${pypy}/pypy-c/.pypy-c-wrapped"
+      then "${pypy}/pypy-c/pypy-c"
       else "${python2.interpreter}";
     unpackPhase = ''
       cp -R ${pixie-src} pixie-src
diff --git a/nixpkgs/pkgs/development/interpreters/pure/default.nix b/nixpkgs/pkgs/development/interpreters/pure/default.nix
index c2b120576ea2..188058a73b52 100644
--- a/nixpkgs/pkgs/development/interpreters/pure/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/pure/default.nix
@@ -13,6 +13,7 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ bison flex makeWrapper ];
   propagatedBuildInputs = [ llvm gmp mpfr readline ];
+  NIX_LDFLAGS = [ "-lLLVMJIT" ];
 
   postPatch = ''
     for f in expr.cc matcher.cc printer.cc symtable.cc parserdefs.hh; do
diff --git a/nixpkgs/pkgs/development/interpreters/python/build-python-package-common.nix b/nixpkgs/pkgs/development/interpreters/python/build-python-package-common.nix
index 2b383fe985d1..0f8e088d434a 100644
--- a/nixpkgs/pkgs/development/interpreters/python/build-python-package-common.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/build-python-package-common.nix
@@ -1,7 +1,6 @@
 # This function provides generic bits to install a Python wheel.
 
 { python
-, bootstrapped-pip
 }:
 
 { buildInputs ? []
@@ -10,7 +9,7 @@
 , ... } @ attrs:
 
 attrs // {
-  buildInputs = buildInputs ++ [ bootstrapped-pip ];
+  buildInputs = buildInputs ++ [ python.pythonForBuild.pkgs.bootstrapped-pip ];
 
   configurePhase = attrs.configurePhase or ''
     runHook preConfigure
@@ -24,7 +23,7 @@ attrs // {
     export PYTHONPATH="$out/${python.sitePackages}:$PYTHONPATH"
 
     pushd dist
-    ${bootstrapped-pip}/bin/pip install *.whl --no-index --prefix=$out --no-cache ${toString installFlags} --build tmpbuild
+    ${python.pythonForBuild.pkgs.bootstrapped-pip}/bin/pip install *.whl --no-index --prefix=$out --no-cache ${toString installFlags} --build tmpbuild
     popd
 
     runHook postInstall
diff --git a/nixpkgs/pkgs/development/interpreters/python/build-python-package-setuptools.nix b/nixpkgs/pkgs/development/interpreters/python/build-python-package-setuptools.nix
index bc512357acd5..4c66fdec5f6b 100644
--- a/nixpkgs/pkgs/development/interpreters/python/build-python-package-setuptools.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/build-python-package-setuptools.nix
@@ -2,7 +2,6 @@
 
 { lib
 , python
-, bootstrapped-pip
 }:
 
 {
@@ -26,13 +25,13 @@ in attrs // {
   buildPhase = attrs.buildPhase or ''
     runHook preBuild
     cp ${setuppy} nix_run_setup
-    ${python.interpreter} nix_run_setup ${lib.optionalString (setupPyBuildFlags != []) ("build_ext " + (lib.concatStringsSep " " setupPyBuildFlags))} bdist_wheel
+    ${python.pythonForBuild.interpreter} nix_run_setup ${lib.optionalString (setupPyBuildFlags != []) ("build_ext " + (lib.concatStringsSep " " setupPyBuildFlags))} bdist_wheel
     runHook postBuild
   '';
 
   installCheckPhase = attrs.checkPhase or ''
     runHook preCheck
-    ${python.interpreter} nix_run_setup test
+    ${python.pythonForBuild.interpreter} nix_run_setup test
     runHook postCheck
   '';
 
@@ -47,9 +46,9 @@ in attrs // {
     if test -e setup.py; then
       tmp_path=$(mktemp -d)
       export PATH="$tmp_path/bin:$PATH"
-      export PYTHONPATH="$tmp_path/${python.sitePackages}:$PYTHONPATH"
-      mkdir -p $tmp_path/${python.sitePackages}
-      ${bootstrapped-pip}/bin/pip install -e . --prefix $tmp_path >&2
+      export PYTHONPATH="$tmp_path/${python.pythonForBuild.sitePackages}:$PYTHONPATH"
+      mkdir -p $tmp_path/${python.pythonForBuild.sitePackages}
+      ${python.pythonForBuild.pkgs.bootstrapped-pip}/bin/pip install -e . --prefix $tmp_path >&2
     fi
     ${postShellHook}
   '';
diff --git a/nixpkgs/pkgs/development/interpreters/python/build-python-package.nix b/nixpkgs/pkgs/development/interpreters/python/build-python-package.nix
index 391086a662ec..b664cf0b14f4 100644
--- a/nixpkgs/pkgs/development/interpreters/python/build-python-package.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/build-python-package.nix
@@ -10,17 +10,16 @@
 , ensureNewerSourcesForZipFilesHook
 , toPythonModule
 , namePrefix
-, bootstrapped-pip
 , flit
 , writeScript
 , update-python-libraries
 }:
 
 let
-  setuptools-specific = import ./build-python-package-setuptools.nix { inherit lib python bootstrapped-pip; };
+  setuptools-specific = import ./build-python-package-setuptools.nix { inherit lib python; };
   flit-specific = import ./build-python-package-flit.nix { inherit python flit; };
   wheel-specific = import ./build-python-package-wheel.nix { };
-  common = import ./build-python-package-common.nix { inherit python bootstrapped-pip; };
+  common = import ./build-python-package-common.nix { inherit python; };
   mkPythonDerivation = import ./mk-python-derivation.nix {
     inherit lib config python wrapPython setuptools unzip ensureNewerSourcesForZipFilesHook;
     inherit toPythonModule namePrefix writeScript update-python-libraries;
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/boot.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/boot.nix
index 976d30819dbe..ccb366903c5c 100644
--- a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/boot.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/boot.nix
@@ -77,8 +77,6 @@ stdenv.mkDerivation rec {
     ''
       ln -s $out/share/man/man1/{python2.7.1.gz,python.1.gz}
 
-      paxmark E $out/bin/python2.7
-
       rm "$out"/lib/python*/plat-*/regen # refers to glibc.dev
     '';
 
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix
index 63dad3bf42ff..249c4ac9cf79 100644
--- a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix
@@ -1,7 +1,9 @@
-{ stdenv, buildPackages, fetchurl
+{ stdenv, fetchurl, fetchpatch
 , bzip2
+, expat
+, libffi
 , gdbm
-, fetchpatch
+, db
 , ncurses
 , openssl
 , readline
@@ -10,15 +12,16 @@
 , zlib
 , callPackage
 , self
-, db
-, expat
-, libffi
 , CF, configd, coreutils
 , python-setup-hook
 # Some proprietary libs assume UCS2 unicode, especially on darwin :(
 , ucsEncoding ? 4
 # For the Python package set
 , packageOverrides ? (self: super: {})
+, buildPackages
+, sourceVersion
+, sha256
+, passthruFun
 }:
 
 assert x11Support -> tcl != null
@@ -29,16 +32,26 @@ assert x11Support -> tcl != null
 with stdenv.lib;
 
 let
-  majorVersion = "2.7";
-  minorVersion = "15";
-  minorVersionSuffix = "";
-  version = "${majorVersion}.${minorVersion}${minorVersionSuffix}";
-  libPrefix = "python${majorVersion}";
-  sitePackages = "lib/${libPrefix}/site-packages";
+
+  pythonForBuild = buildPackages.${"python${sourceVersion.major}${sourceVersion.minor}"};
+
+  passthru = passthruFun rec {
+    inherit self sourceVersion packageOverrides;
+    implementation = "cpython";
+    libPrefix = "python${pythonVersion}";
+    executable = libPrefix;
+    pythonVersion = with sourceVersion; "${major}.${minor}";
+    sitePackages = "lib/${libPrefix}/site-packages";
+    inherit pythonForBuild;
+  } // {
+    inherit ucsEncoding;
+  };
+
+  version = with sourceVersion; "${major}.${minor}.${patch}${suffix}";
 
   src = fetchurl {
-    url = "https://www.python.org/ftp/python/${majorVersion}.${minorVersion}/Python-${version}.tar.xz";
-    sha256 = "0x2mvz9dp11wj7p5ccvmk9s0hzjk2fa1m462p395l4r6bfnb3n92";
+    url = with sourceVersion; "https://www.python.org/ftp/python/${major}.${minor}.${patch}/Python-${version}.tar.xz";
+    inherit sha256;
   };
 
   hasDistutilsCxxPatch = !(stdenv.cc.isGNU or false);
@@ -191,12 +204,11 @@ let
   # Build the basic Python interpreter without modules that have
   # external dependencies.
 
-in stdenv.mkDerivation ({
-    name = "python-${version}";
-    pythonVersion = majorVersion;
+in with passthru; stdenv.mkDerivation ({
+    pname = "python";
+    inherit version;
 
-    inherit majorVersion version src patches buildInputs nativeBuildInputs
-            preConfigure configureFlags;
+    inherit src patches buildInputs nativeBuildInputs preConfigure configureFlags;
 
     LDFLAGS = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
     inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
@@ -215,7 +227,7 @@ in stdenv.mkDerivation ({
       ''
         # needed for some packages, especially packages that backport
         # functionality to 2.x from 3.x
-        for item in $out/lib/python${majorVersion}/test/*; do
+        for item in $out/lib/${libPrefix}/test/*; do
           if [[ "$item" != */test_support.py*
              && "$item" != */test/support
              && "$item" != */test/regrtest.py* ]]; then
@@ -224,13 +236,11 @@ in stdenv.mkDerivation ({
             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}
+        touch $out/lib/${libPrefix}/test/__init__.py
+        ln -s $out/lib/${libPrefix}/pdb.py $out/bin/pdb
+        ln -s $out/lib/${libPrefix}/pdb.py $out/bin/pdb${sourceVersion.major}.${sourceVersion.minor}
         ln -s $out/share/man/man1/{python2.7.1.gz,python.1.gz}
 
-        paxmark E $out/bin/python${majorVersion}
-
         # Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484
         echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py
 
@@ -251,21 +261,7 @@ in stdenv.mkDerivation ({
         cp libpython2.7.dll.a $out/lib
       '';
 
-    passthru = let
-      pythonPackages = callPackage ../../../../../top-level/python-packages.nix {
-        python = self;
-        overrides = packageOverrides;
-      };
-    in rec {
-      inherit libPrefix sitePackages x11Support hasDistutilsCxxPatch ucsEncoding;
-      executable = libPrefix;
-      buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
-      withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
-      pkgs = pythonPackages;
-      isPy2 = true;
-      isPy27 = true;
-      interpreter = "${self}/bin/${executable}";
-    };
+    inherit passthru;
 
     enableParallelBuilding = true;
 
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/3.5/default.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/3.5/default.nix
deleted file mode 100644
index 92c277aacd4f..000000000000
--- a/nixpkgs/pkgs/development/interpreters/python/cpython/3.5/default.nix
+++ /dev/null
@@ -1,213 +0,0 @@
-{ stdenv, fetchurl, fetchpatch
-, bzip2
-, expat
-, libffi
-, gdbm
-, lzma
-, ncurses
-, openssl
-, readline
-, sqlite
-, tcl ? null, tk ? null, tix ? null, libX11 ? null, xproto ? null, x11Support ? false
-, zlib
-, callPackage
-, self
-, CF, configd
-, python-setup-hook
-# For the Python package set
-, packageOverrides ? (self: super: {})
-}:
-
-assert x11Support -> tcl != null
-                  && tk != null
-                  && xproto != null
-                  && libX11 != null;
-
-with stdenv.lib;
-
-let
-  majorVersion = "3.5";
-  minorVersion = "6";
-  minorVersionSuffix = "";
-  version = "${majorVersion}.${minorVersion}${minorVersionSuffix}";
-  libPrefix = "python${majorVersion}";
-  sitePackages = "lib/${libPrefix}/site-packages";
-
-  buildInputs = filter (p: p != null) [
-    zlib bzip2 expat lzma libffi gdbm sqlite readline ncurses openssl ]
-    ++ optionals x11Support [ tcl tk libX11 xproto ]
-    ++ optionals stdenv.isDarwin [ CF configd ];
-
-  hasDistutilsCxxPatch = !(stdenv.cc.isGNU or false);
-
-in stdenv.mkDerivation {
-  name = "python3-${version}";
-  pythonVersion = majorVersion;
-  inherit majorVersion version;
-
-  inherit buildInputs;
-
-  src = fetchurl {
-    url = "https://www.python.org/ftp/python/${majorVersion}.${minorVersion}/Python-${version}.tar.xz";
-    sha256 = "0pqmf51zy2lzhbaj4yya2py2qr653j9152d0rg3p7wi1yl2dwp7m";
-  };
-
-  NIX_LDFLAGS = optionalString stdenv.isLinux "-lgcc_s";
-
-  # Determinism: The interpreter is patched to write null timestamps when compiling python files.
-  # This way python doesn't try to update them when we freeze timestamps in nix store.
-  DETERMINISTIC_BUILD=1;
-  # Determinism: We fix the hashes of str, bytes and datetime objects.
-  PYTHONHASHSEED=0;
-
-  prePatch = optionalString stdenv.isDarwin ''
-    substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
-    substituteInPlace configure --replace '-Wl,-stack_size,1000000' ' '
-  '';
-
-  patches = [
-    ./no-ldconfig.patch
-    ./ld_library_path.patch
-  ] ++ optionals stdenv.isDarwin [
-    # Fix for https://bugs.python.org/issue24658
-    (fetchpatch {
-      url = "https://bugs.python.org/file45178/issue24658-3-3.6.diff";
-      sha256 = "1x060hs80nl34mcl2ji2i7l4shxkmxwgq8h8lcmav8rjqqz1nb4a";
-    })
-  ] ++ optionals (x11Support && stdenv.isDarwin) [
-    ./use-correct-tcl-tk-on-darwin.patch
-  ] ++ optionals hasDistutilsCxxPatch [
-    # Fix for http://bugs.python.org/issue1222585
-    # Upstream distutils is calling C compiler to compile C++ code, which
-    # only works for GCC and Apple Clang. This makes distutils to call C++
-    # compiler when needed.
-    (fetchpatch {
-      url = "https://bugs.python.org/file47046/python-3.x-distutils-C++.patch";
-      sha256 = "0dgdn9k2kmw4wh90vdnjcrnn97ylxgx7mbn9l87fwz6j501jqvk8";
-      extraPrefix = "";
-    })
-  ];
-
-  postPatch = ''
-    # Determinism
-    substituteInPlace "Lib/py_compile.py" --replace "source_stats['mtime']" "(1 if 'DETERMINISTIC_BUILD' in os.environ else source_stats['mtime'])"
-    # Determinism. This is done unconditionally
-    substituteInPlace "Lib/importlib/_bootstrap_external.py" --replace "source_mtime = int(st['mtime'])" "source_mtime = 1"
-  '' + optionalString (x11Support && (tix != null)) ''
-    substituteInPlace "Lib/tkinter/tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'"
-  '';
-
-  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"}";
-
-  configureFlags = [
-    "--enable-shared"
-    "--with-threads"
-    "--without-ensurepip"
-    "--with-system-expat"
-    "--with-system-ffi"
-  ]
-    # Never even try to use lchmod on linux,
-    # don't rely on detecting glibc-isms.
-  ++ optional stdenv.hostPlatform.isLinux "ac_cv_func_lchmod=no";
-
-  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
-     ''
-     + optionalString stdenv.hostPlatform.isMusl ''
-      export NIX_CFLAGS_COMPILE+=" -DTHREAD_STACK_SIZE=0x100000"
-     ''}
-  '';
-
-  setupHook = python-setup-hook sitePackages;
-
-  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*
-         && "$item" != */test/support
-         && "$item" != */test/libregrtest
-         && "$item" != */test/regrtest.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}
-
-    # Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484
-    echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py
-
-    # Determinism: Windows installers were not deterministic.
-    # We're also not interested in building Windows installers.
-    find "$out" -name 'wininst*.exe' | xargs -r rm -f
-
-    # Use Python3 as default python
-    ln -s "$out/bin/idle3" "$out/bin/idle"
-    ln -s "$out/bin/pydoc3" "$out/bin/pydoc"
-    ln -s "$out/bin/python3" "$out/bin/python"
-    ln -s "$out/bin/python3-config" "$out/bin/python-config"
-    ln -s "$out/lib/pkgconfig/python3.pc" "$out/lib/pkgconfig/python.pc"
-
-    # Get rid of retained dependencies on -dev packages, and remove
-    # some $TMPDIR references to improve binary reproducibility.
-    # Note that the .pyc file of _sysconfigdata.py should be regenerated!
-    for i in $out/lib/python${majorVersion}/_sysconfigdata.py $out/lib/python${majorVersion}/config-${majorVersion}m/Makefile; do
-      sed -i $i -e "s|-I/nix/store/[^ ']*||g" -e "s|-L/nix/store/[^ ']*||g" -e "s|$TMPDIR|/no-such-path|g"
-    done
-
-    # Determinism: rebuild all bytecode
-    # We exclude lib2to3 because that's Python 2 code which fails
-    # We rebuild three times, once for each optimization level
-    find $out -name "*.py" | $out/bin/python -m compileall -q -f -x "lib2to3" -i -
-    find $out -name "*.py" | $out/bin/python -O -m compileall -q -f -x "lib2to3" -i -
-    find $out -name "*.py" | $out/bin/python -OO -m compileall -q -f -x "lib2to3" -i -
-  '';
-
-  passthru = let
-    pythonPackages = callPackage ../../../../../top-level/python-packages.nix {
-      python = self;
-      overrides = packageOverrides;
-    };
-  in rec {
-    inherit libPrefix sitePackages x11Support hasDistutilsCxxPatch;
-    executable = "${libPrefix}m";
-    buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
-    withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
-    pkgs = pythonPackages;
-    isPy3 = true;
-    isPy35 = true;
-    interpreter = "${self}/bin/${executable}";
-  };
-
-  enableParallelBuilding = true;
-
-  doCheck = false; # expensive, and fails
-
-  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; [ fridh ];
-  };
-}
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/3.7/default.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/3.7/default.nix
deleted file mode 100644
index a008be707c2c..000000000000
--- a/nixpkgs/pkgs/development/interpreters/python/cpython/3.7/default.nix
+++ /dev/null
@@ -1,196 +0,0 @@
-{ stdenv, fetchurl, fetchpatch
-, bzip2
-, expat
-, libffi
-, gdbm
-, lzma
-, ncurses
-, openssl
-, readline
-, sqlite
-, tcl ? null, tk ? null, tix ? null, libX11 ? null, xproto ? null, x11Support ? false
-, zlib
-, callPackage
-, self
-, CF, configd
-, python-setup-hook
-# For the Python package set
-, packageOverrides ? (self: super: {})
-}:
-
-assert x11Support -> tcl != null
-                  && tk != null
-                  && xproto != null
-                  && libX11 != null;
-with stdenv.lib;
-
-let
-  majorVersion = "3.7";
-  minorVersion = "2";
-  minorVersionSuffix = "";
-  version = "${majorVersion}.${minorVersion}${minorVersionSuffix}";
-  libPrefix = "python${majorVersion}";
-  sitePackages = "lib/${libPrefix}/site-packages";
-
-  buildInputs = filter (p: p != null) [
-    zlib bzip2 expat lzma libffi gdbm sqlite readline ncurses openssl ]
-    ++ optionals x11Support [ tcl tk libX11 xproto ]
-    ++ optionals stdenv.isDarwin [ CF configd ];
-
-  hasDistutilsCxxPatch = !(stdenv.cc.isGNU or false);
-
-in stdenv.mkDerivation {
-  name = "python3-${version}";
-  pythonVersion = majorVersion;
-  inherit majorVersion version;
-
-  inherit buildInputs;
-
-  src = fetchurl {
-    url = "https://www.python.org/ftp/python/${majorVersion}.${minorVersion}/Python-${version}.tar.xz";
-    sha256 = "1fzi9d2gibh0wzwidyckzbywsxcsbckgsl05ryxlifxia77fhgyq";
-  };
-
-  NIX_LDFLAGS = optionalString stdenv.isLinux "-lgcc_s";
-
-  # Determinism: We fix the hashes of str, bytes and datetime objects.
-  PYTHONHASHSEED=0;
-
-  prePatch = optionalString stdenv.isDarwin ''
-    substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
-    substituteInPlace configure --replace '-Wl,-stack_size,1000000' ' '
-  '';
-
-  patches = [
-    ./no-ldconfig.patch
-    # Fix darwin build https://bugs.python.org/issue34027
-    (fetchpatch {
-      url = https://bugs.python.org/file47666/darwin-libutil.patch;
-      sha256 = "0242gihnw3wfskl4fydp2xanpl8k5q7fj4dp7dbbqf46a4iwdzpa";
-    })
-  ] ++ optionals hasDistutilsCxxPatch [
-    # Fix for http://bugs.python.org/issue1222585
-    # Upstream distutils is calling C compiler to compile C++ code, which
-    # only works for GCC and Apple Clang. This makes distutils to call C++
-    # compiler when needed.
-    (fetchpatch {
-      url = "https://bugs.python.org/file48016/python-3.x-distutils-C++.patch";
-      sha256 = "1h18lnpx539h5lfxyk379dxwr8m2raigcjixkf133l4xy3f4bzi2";
-    })
-  ];
-
-  postPatch = ''
-  '' + optionalString (x11Support && (tix != null)) ''
-    substituteInPlace "Lib/tkinter/tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'"
-  '';
-
-  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"}";
-
-  configureFlags = [
-    "--enable-shared"
-    "--with-threads"
-    "--without-ensurepip"
-    "--with-system-expat"
-    "--with-system-ffi"
-    "--with-openssl=${openssl.dev}"
-  ];
-
-  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
-     ''}
-  '';
-
-  setupHook = python-setup-hook sitePackages;
-
-  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*
-         && "$item" != */test/support
-         && "$item" != */test/libregrtest
-         && "$item" != */test/regrtest.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}
-
-    # Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484
-    echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py
-
-    # Determinism: Windows installers were not deterministic.
-    # We're also not interested in building Windows installers.
-    find "$out" -name 'wininst*.exe' | xargs -r rm -f
-
-    # Use Python3 as default python
-    ln -s "$out/bin/idle3" "$out/bin/idle"
-    ln -s "$out/bin/pydoc3" "$out/bin/pydoc"
-    ln -s "$out/bin/python3" "$out/bin/python"
-    ln -s "$out/bin/python3-config" "$out/bin/python-config"
-    ln -s "$out/lib/pkgconfig/python3.pc" "$out/lib/pkgconfig/python.pc"
-
-    # Get rid of retained dependencies on -dev packages, and remove
-    # some $TMPDIR references to improve binary reproducibility.
-    # Note that the .pyc file of _sysconfigdata.py should be regenerated!
-    for i in $out/lib/python${majorVersion}/_sysconfigdata*.py $out/lib/python${majorVersion}/config-${majorVersion}m*/Makefile; do
-      sed -i $i -e "s|-I/nix/store/[^ ']*||g" -e "s|-L/nix/store/[^ ']*||g" -e "s|$TMPDIR|/no-such-path|g"
-    done
-
-    # Determinism: rebuild all bytecode
-    # We exclude lib2to3 because that's Python 2 code which fails
-    # We rebuild three times, once for each optimization level
-    # Python 3.7 implements PEP 552, introducing support for deterministic bytecode.
-    # This is automatically used when `SOURCE_DATE_EPOCH` is set.
-    find $out -name "*.py" | $out/bin/python     -m compileall -q -f -x "lib2to3" -i -
-    find $out -name "*.py" | $out/bin/python -O  -m compileall -q -f -x "lib2to3" -i -
-    find $out -name "*.py" | $out/bin/python -OO -m compileall -q -f -x "lib2to3" -i -
-  '';
-
-  passthru = let
-    pythonPackages = callPackage ../../../../../top-level/python-packages.nix {
-      python = self;
-      overrides = packageOverrides;
-    };
-  in rec {
-    inherit libPrefix sitePackages x11Support hasDistutilsCxxPatch;
-    executable = "${libPrefix}m";
-    buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
-    withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
-    pkgs = pythonPackages;
-    isPy3 = true;
-    isPy37 = true;
-    is_py3k = true;  # deprecated
-    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; [ fridh kragniz ];
-  };
-}
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/3.6/default.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/default.nix
index cad35cac53a8..1b4a5e751377 100644
--- a/nixpkgs/pkgs/development/interpreters/python/cpython/3.6/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, fetchpatch, buildPackages
+{ stdenv, fetchurl, fetchpatch
 , bzip2
 , expat
 , libffi
@@ -8,70 +8,95 @@
 , openssl
 , readline
 , sqlite
-, tcl ? null, tk ? null, tix ? null, libX11 ? null, xproto ? null, x11Support ? false
+, tcl ? null, tk ? null, tix ? null, libX11 ? null, xorgproto ? null, x11Support ? false
 , zlib
 , callPackage
 , self
 , CF, configd
 , python-setup-hook
+, nukeReferences
 # For the Python package set
 , packageOverrides ? (self: super: {})
+, buildPackages
+, sourceVersion
+, sha256
+, passthruFun
+, bash
 }:
 
 assert x11Support -> tcl != null
                   && tk != null
-                  && xproto != null
+                  && xorgproto != null
                   && libX11 != null;
 with stdenv.lib;
 
 let
-  majorVersion = "3.6";
-  minorVersion = "8";
-  minorVersionSuffix = "";
-  version = "${majorVersion}.${minorVersion}${minorVersionSuffix}";
-  libPrefix = "python${majorVersion}";
-  sitePackages = "lib/${libPrefix}/site-packages";
+
+  passthru = passthruFun rec {
+    inherit self sourceVersion packageOverrides;
+    implementation = "cpython";
+    libPrefix = "python${pythonVersion}";
+    executable = libPrefix;
+    pythonVersion = with sourceVersion; "${major}.${minor}";
+    sitePackages = "lib/${libPrefix}/site-packages";
+    inherit pythonForBuild;
+  };
+
+  version = with sourceVersion; "${major}.${minor}.${patch}${suffix}";
+
+  nativeBuildInputs = [
+    nukeReferences
+  ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
+    buildPackages.stdenv.cc
+    pythonForBuild
+  ];
 
   buildInputs = filter (p: p != null) [
     zlib bzip2 expat lzma libffi gdbm sqlite readline ncurses openssl ]
-    ++ optionals x11Support [ tcl tk libX11 xproto ]
+    ++ optionals x11Support [ tcl tk libX11 xorgproto ]
     ++ optionals stdenv.isDarwin [ CF configd ];
 
-  nativeBuildInputs =
-    optional (stdenv.hostPlatform != stdenv.buildPlatform) buildPackages.python3;
-
   hasDistutilsCxxPatch = !(stdenv.cc.isGNU or false);
 
-in stdenv.mkDerivation {
-  name = "python3-${version}";
-  pythonVersion = majorVersion;
-  inherit majorVersion version;
+  pythonForBuild = buildPackages.${"python${sourceVersion.major}${sourceVersion.minor}"};
+
+  pythonForBuildInterpreter = if stdenv.hostPlatform == stdenv.buildPlatform then
+    "$out/bin/python"
+  else pythonForBuild.interpreter;
+
+in with passthru; stdenv.mkDerivation {
+  pname = "python3";
+  inherit version;
 
   inherit buildInputs nativeBuildInputs;
 
   src = fetchurl {
-    url = "https://www.python.org/ftp/python/${majorVersion}.${minorVersion}/Python-${version}.tar.xz";
-    sha256 = "14qi6n5gpcjnwy165wi9hkfcmbadc95ny6bxxldknxwmx50n4i1m";
+    url = with sourceVersion; "https://www.python.org/ftp/python/${major}.${minor}.${patch}/Python-${version}.tar.xz";
+    inherit sha256;
   };
 
-  NIX_LDFLAGS = optionalString stdenv.isLinux "-lgcc_s";
-
-  # Determinism: The interpreter is patched to write null timestamps when compiling python files.
-  # This way python doesn't try to update them when we freeze timestamps in nix store.
-  DETERMINISTIC_BUILD=1;
-  # Determinism: We fix the hashes of str, bytes and datetime objects.
-  PYTHONHASHSEED=0;
-
   prePatch = optionalString stdenv.isDarwin ''
     substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
     substituteInPlace configure --replace '-Wl,-stack_size,1000000' ' '
   '';
 
   patches = [
-    ./no-ldconfig.patch
-  ] ++ optionals (x11Support && stdenv.isDarwin) [
-    ./use-correct-tcl-tk-on-darwin.patch
-  ] ++ optionals hasDistutilsCxxPatch [
+    # 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).
+    (./. + "/${sourceVersion.major}.${sourceVersion.minor}/no-ldconfig.patch")
+  ] ++ optionals isPy35 [
+    # Backports support for LD_LIBRARY_PATH from 3.6
+    ./3.5/ld_library_path.patch
+  ] ++ optionals isPy37 [
+    # Fix darwin build https://bugs.python.org/issue34027
+    (fetchpatch {
+      url = https://bugs.python.org/file47666/darwin-libutil.patch;
+      sha256 = "0242gihnw3wfskl4fydp2xanpl8k5q7fj4dp7dbbqf46a4iwdzpa";
+    })
+  ] ++ optionals (isPy3k && hasDistutilsCxxPatch) [
     # Fix for http://bugs.python.org/issue1222585
     # Upstream distutils is calling C compiler to compile C++ code, which
     # only works for GCC and Apple Clang. This makes distutils to call C++
@@ -83,17 +108,16 @@ in stdenv.mkDerivation {
   ];
 
   postPatch = ''
-    # Determinism
-    substituteInPlace "Lib/py_compile.py" --replace "source_stats['mtime']" "(1 if 'DETERMINISTIC_BUILD' in os.environ else source_stats['mtime'])"
-    # Determinism. This is done unconditionally
-    substituteInPlace "Lib/importlib/_bootstrap_external.py" --replace "source_mtime = int(st['mtime'])" "source_mtime = 1"
   '' + optionalString (x11Support && (tix != null)) ''
     substituteInPlace "Lib/tkinter/tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'"
   '';
 
-  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"}";
+  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"}";
+  NIX_LDFLAGS = optionalString stdenv.isLinux "-lgcc_s";
+  # Determinism: We fix the hashes of str, bytes and datetime objects.
+  PYTHONHASHSEED=0;
 
   configureFlags = [
     "--enable-shared"
@@ -101,6 +125,7 @@ in stdenv.mkDerivation {
     "--without-ensurepip"
     "--with-system-expat"
     "--with-system-ffi"
+    "--with-openssl=${openssl.dev}"
   ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
     "ac_cv_buggy_getaddrinfo=no"
     # Assume little-endian IEEE 754 floating point when cross compiling
@@ -122,22 +147,25 @@ in stdenv.mkDerivation {
     "ac_cv_computed_gotos=yes"
     "ac_cv_file__dev_ptmx=yes"
     "ac_cv_file__dev_ptc=yes"
-  ]
+  ] ++ optionals stdenv.hostPlatform.isLinux [
     # Never even try to use lchmod on linux,
     # don't rely on detecting glibc-isms.
-  ++ optional stdenv.hostPlatform.isLinux "ac_cv_func_lchmod=no";
+    "ac_cv_func_lchmod=no"
+  ];
 
   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
-     ''
-     + optionalString stdenv.hostPlatform.isMusl ''
-      export NIX_CFLAGS_COMPILE+=" -DTHREAD_STACK_SIZE=0x100000"
-     ''}
+  '' + optionalString stdenv.isDarwin ''
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -msse2"
+    export MACOSX_DEPLOYMENT_TARGET=10.6
+  '' + optionalString (isPy3k && pythonOlder "3.7") ''
+    # Determinism: The interpreter is patched to write null timestamps when compiling python files.
+    # This way python does not try to update them when we freeze timestamps in nix store.
+    export DETERMINISTIC_BUILD=1;
+  '' + optionalString stdenv.hostPlatform.isMusl ''
+    export NIX_CFLAGS_COMPILE+=" -DTHREAD_STACK_SIZE=0x100000"
   '';
 
   setupHook = python-setup-hook sitePackages;
@@ -145,7 +173,7 @@ in stdenv.mkDerivation {
   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
+    for item in $out/lib/${libPrefix}/test/*; do
       if [[ "$item" != */test_support.py*
          && "$item" != */test/support
          && "$item" != */test/libregrtest
@@ -155,10 +183,9 @@ in stdenv.mkDerivation {
         echo $item
       fi
     done
-    touch $out/lib/python${majorVersion}/test/__init__.py
+    touch $out/lib/${libPrefix}/test/__init__.py
 
-    ln -s "$out/include/python${majorVersion}m" "$out/include/python${majorVersion}"
-    paxmark E $out/bin/python${majorVersion}
+    ln -s "$out/include/${executable}m" "$out/include/${executable}"
 
     # Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484
     echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py
@@ -177,38 +204,42 @@ in stdenv.mkDerivation {
     # Get rid of retained dependencies on -dev packages, and remove
     # some $TMPDIR references to improve binary reproducibility.
     # Note that the .pyc file of _sysconfigdata.py should be regenerated!
-    for i in $out/lib/python${majorVersion}/_sysconfigdata*.py $out/lib/python${majorVersion}/config-${majorVersion}m*/Makefile; do
-      sed -i $i -e "s|-I/nix/store/[^ ']*||g" -e "s|-L/nix/store/[^ ']*||g" -e "s|$TMPDIR|/no-such-path|g"
+    for i in $out/lib/${libPrefix}/_sysconfigdata*.py $out/lib/${libPrefix}/config-${sourceVersion.major}${sourceVersion.minor}*/Makefile; do
+       sed -i $i -e "s|$TMPDIR|/no-such-path|g"
     done
-  '' + optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
+
+    # Further get rid of references. https://github.com/NixOS/nixpkgs/issues/51668
+    find $out/lib/python*/config-* -type f -print -exec nuke-refs '{}' +
+    find $out/lib -name '_sysconfigdata*.py*' -print -exec nuke-refs '{}' +
+
     # Determinism: rebuild all bytecode
     # We exclude lib2to3 because that's Python 2 code which fails
     # We rebuild three times, once for each optimization level
-    find $out -name "*.py" | $out/bin/python -m compileall -q -f -x "lib2to3" -i -
-    find $out -name "*.py" | $out/bin/python -O -m compileall -q -f -x "lib2to3" -i -
-    find $out -name "*.py" | $out/bin/python -OO -m compileall -q -f -x "lib2to3" -i -
+    # Python 3.7 implements PEP 552, introducing support for deterministic bytecode.
+    # This is automatically used when `SOURCE_DATE_EPOCH` is set.
+    find $out -name "*.py" | ${pythonForBuildInterpreter}     -m compileall -q -f -x "lib2to3" -i -
+    find $out -name "*.py" | ${pythonForBuildInterpreter} -O  -m compileall -q -f -x "lib2to3" -i -
+    find $out -name "*.py" | ${pythonForBuildInterpreter} -OO -m compileall -q -f -x "lib2to3" -i -
   '';
 
-  passthru = let
-    pythonPackages = callPackage ../../../../../top-level/python-packages.nix {
-      python = self;
-      overrides = packageOverrides;
-    };
-  in rec {
-    inherit libPrefix sitePackages x11Support hasDistutilsCxxPatch;
-    executable = "${libPrefix}m";
-    buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
-    withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
-    pkgs = pythonPackages;
-    isPy3 = true;
-    isPy36 = true;
-    is_py3k = true;  # deprecated
-    interpreter = "${self}/bin/${executable}";
-  };
+  preFixup = stdenv.lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
+    # Ensure patch-shebangs uses shebangs of host interpreter.
+    export PATH=${stdenv.lib.makeBinPath [ "$out" bash ]}:$PATH
+  '';
 
-  enableParallelBuilding = true;
+  # Enforce that we don't have references to the OpenSSL -dev package, which we
+  # explicitly specify in our configure flags above.
+  disallowedReferences = [
+    openssl.dev
+  ] ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
+    # Ensure we don't have references to build-time packages.
+    # These typically end up in shebangs.
+    pythonForBuild buildPackages.bash
+  ];
+
+  inherit passthru;
 
-  doCheck = false; # expensive, and fails
+  enableParallelBuilding = true;
 
   meta = {
     homepage = http://python.org;
@@ -224,6 +255,6 @@ in stdenv.mkDerivation {
     '';
     license = licenses.psfl;
     platforms = with platforms; linux ++ darwin;
-    maintainers = with maintainers; [ fridh kragniz ];
+    maintainers = with maintainers; [ fridh ];
   };
 }
diff --git a/nixpkgs/pkgs/development/interpreters/python/default.nix b/nixpkgs/pkgs/development/interpreters/python/default.nix
new file mode 100644
index 000000000000..f1461d784be0
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/default.nix
@@ -0,0 +1,156 @@
+{ pkgs, lib }:
+
+with pkgs;
+
+(let
+
+  # Common passthru for all Python interpreters.
+  passthruFun =
+    { implementation
+    , libPrefix
+    , executable
+    , sourceVersion
+    , pythonVersion
+    , packageOverrides
+    , sitePackages
+    , pythonForBuild
+    , self
+    }: let
+      pythonPackages = callPackage ../../../top-level/python-packages.nix {
+        python = self;
+        overrides = packageOverrides;
+      };
+    in rec {
+        isPy27 = pythonVersion == "2.7";
+        isPy33 = pythonVersion == "3.3"; # TODO: remove
+        isPy34 = pythonVersion == "3.4"; # TODO: remove
+        isPy35 = pythonVersion == "3.5";
+        isPy36 = pythonVersion == "3.6";
+        isPy37 = pythonVersion == "3.7";
+        isPy2 = lib.strings.substring 0 1 pythonVersion == "2";
+        isPy3 = lib.strings.substring 0 1 pythonVersion == "3";
+        isPy3k = isPy3;
+        isPyPy = interpreter == "pypy";
+
+        buildEnv = callPackage ./wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
+        withPackages = import ./with-packages.nix { inherit buildEnv pythonPackages;};
+        pkgs = pythonPackages;
+        interpreter = "${self}/bin/${executable}";
+        inherit executable implementation libPrefix pythonVersion sitePackages;
+        inherit sourceVersion;
+        pythonAtLeast = lib.versionAtLeast pythonVersion;
+        pythonOlder = lib.versionOlder pythonVersion;
+        inherit pythonForBuild;
+  };
+
+in {
+
+  python27 = callPackage ./cpython/2.7 {
+    self = python27;
+    sourceVersion = {
+      major = "2";
+      minor = "7";
+      patch = "15";
+      suffix = "";
+    };
+    sha256 = "0x2mvz9dp11wj7p5ccvmk9s0hzjk2fa1m462p395l4r6bfnb3n92";
+    inherit (darwin) CF configd;
+    inherit passthruFun;
+  };
+
+  python35 = callPackage ./cpython {
+    self = python35;
+    sourceVersion = {
+      major = "3";
+      minor = "5";
+      patch = "6";
+      suffix = "";
+    };
+    sha256 = "0pqmf51zy2lzhbaj4yya2py2qr653j9152d0rg3p7wi1yl2dwp7m";
+    inherit (darwin) CF configd;
+    inherit passthruFun;
+  };
+
+  python36 = callPackage ./cpython {
+    self = python36;
+    sourceVersion = {
+      major = "3";
+      minor = "6";
+      patch = "8";
+      suffix = "";
+    };
+    sha256 = "14qi6n5gpcjnwy165wi9hkfcmbadc95ny6bxxldknxwmx50n4i1m";
+    inherit (darwin) CF configd;
+    inherit passthruFun;
+  };
+
+  python37 = callPackage ./cpython {
+    self = python37;
+    sourceVersion = {
+      major = "3";
+      minor = "7";
+      patch = "2";
+      suffix = "";
+    };
+    sha256 = "1fzi9d2gibh0wzwidyckzbywsxcsbckgsl05ryxlifxia77fhgyq";
+    inherit (darwin) CF configd;
+    inherit passthruFun;
+  };
+
+  pypy27 = callPackage ./pypy {
+    self = pypy27;
+    sourceVersion = {
+      major = "6";
+      minor = "0";
+      patch = "0";
+    };
+    sha256 = "1qjwpc8n68sxxlfg36s5vn1h2gdfvvd6lxvr4lzbvfwhzrgqahsw";
+    pythonVersion = "2.7";
+    db = db.override { dbmSupport = true; };
+    python = python27;
+    inherit passthruFun;
+  };
+
+  pypy35 = callPackage ./pypy {
+    self = pypy35;
+    sourceVersion = {
+      major = "6";
+      minor = "0";
+      patch = "0";
+    };
+    sha256 = "0lwq8nn0r5yj01bwmkk5p7xvvrp4s550l8184mkmn74d3gphrlwg";
+    pythonVersion = "3.5";
+    db = db.override { dbmSupport = true; };
+    python = python27;
+    inherit passthruFun;
+  };
+
+  pypy27_prebuilt = callPackage ./pypy/prebuilt.nix {
+    # Not included at top-level
+    self = pythonInterpreters.pypy27_prebuilt;
+    sourceVersion = {
+      major = "6";
+      minor = "0";
+      patch = "0";
+    };
+    sha256 = "0rxgnp3fm18b87ln8bbjr13g2fsf4ka4abkaim6m03y9lwmr9gvc"; # linux64
+    pythonVersion = "2.7";
+    inherit passthruFun;
+    ncurses = ncurses5;
+  };
+
+  pypy35_prebuilt = callPackage ./pypy/prebuilt.nix {
+  # Not included at top-level
+    self = pythonInterpreters.pypy35_prebuilt;
+    sourceVersion = {
+      major = "6";
+      minor = "0";
+      patch = "0";
+    };
+    sha256 = "0j3h08s7wpglghasmym3baycpif5jshvmk9rpav4pwwy5clzmzsc"; # linux64
+    pythonVersion = "3.5";
+    inherit passthruFun;
+    ncurses = ncurses5;
+  };
+
+})
\ No newline at end of file
diff --git a/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix b/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix
index b9a6835908f9..7718bdfde5d3 100644
--- a/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix
@@ -77,7 +77,7 @@ let self = toPythonModule (python.stdenv.mkDerivation (builtins.removeAttrs attr
 
   buildInputs = [ wrapPython ]
     ++ lib.optional (lib.hasSuffix "zip" (attrs.src.name or "")) unzip
-    ++ lib.optional catchConflicts setuptools # If we no longer propagate setuptools
+#     ++ lib.optional catchConflicts setuptools # If we no longer propagate setuptools
     ++ buildInputs
     ++ pythonPath;
 
@@ -100,9 +100,12 @@ let self = toPythonModule (python.stdenv.mkDerivation (builtins.removeAttrs attr
     # Check if we have two packages with the same name in the closure and fail.
     # If this happens, something went wrong with the dependencies specs.
     # Intentionally kept in a subdirectory, see catch_conflicts/README.md.
-    ${python.interpreter} ${./catch_conflicts}/catch_conflicts.py
+    ${python.pythonForBuild.interpreter} ${./catch_conflicts}/catch_conflicts.py
   '' + attrs.postFixup or '''';
 
+  # Python packages built through cross-compilation are always for the host platform.
+  disallowedReferences = lib.optionals (python.stdenv.hostPlatform != python.stdenv.buildPlatform) [ python.pythonForBuild ];
+
   meta = {
     # default to python's platforms
     platforms = python.meta.platforms;
diff --git a/nixpkgs/pkgs/development/interpreters/python/pypy/2.7/default.nix b/nixpkgs/pkgs/development/interpreters/python/pypy/2.7/default.nix
deleted file mode 100644
index 6f7fa9622960..000000000000
--- a/nixpkgs/pkgs/development/interpreters/python/pypy/2.7/default.nix
+++ /dev/null
@@ -1,136 +0,0 @@
-{ stdenv, substituteAll, fetchurl
-, zlib ? null, zlibSupport ? true, bzip2, pkgconfig, libffi
-, sqlite, openssl, ncurses, python, expat, tcl, tk, tix, xlibsWrapper, libX11
-, makeWrapper, callPackage, self, gdbm, db
-, python-setup-hook
-# For the Python package set
-, packageOverrides ? (self: super: {})
-}:
-
-assert zlibSupport -> zlib != null;
-
-let
-  version = "6.0.0";
-  pythonVersion = "2.7";
-  libPrefix = "pypy${pythonVersion}";
-  sitePackages = "site-packages";
-
-  pythonForPypy = python.withPackages (ppkgs: [ ppkgs.pycparser ]);
-
-in stdenv.mkDerivation rec {
-  name = "pypy-${version}";
-  inherit version pythonVersion;
-
-  src = fetchurl {
-    url = "https://bitbucket.org/pypy/pypy/get/release-pypy${pythonVersion}-v${version}.tar.bz2";
-    sha256 = "1qjwpc8n68sxxlfg36s5vn1h2gdfvvd6lxvr4lzbvfwhzrgqahsw";
-  };
-
-  nativeBuildInputs = [ pkgconfig makeWrapper ];
-  buildInputs = [
-    bzip2 openssl pythonForPypy libffi ncurses expat sqlite tk tcl xlibsWrapper libX11 gdbm db
-  ] ++ stdenv.lib.optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc
-    ++ stdenv.lib.optional zlibSupport zlib;
-
-  hardeningDisable = stdenv.lib.optional stdenv.isi686 "pic";
-
-  C_INCLUDE_PATH = stdenv.lib.makeSearchPathOutput "dev" "include" buildInputs;
-  LIBRARY_PATH = stdenv.lib.makeLibraryPath buildInputs;
-  LD_LIBRARY_PATH = stdenv.lib.makeLibraryPath (stdenv.lib.filter (x : x.outPath != stdenv.cc.libc.outPath or "") buildInputs);
-
-  patches = [
-    (substituteAll {
-      src = ./tk_tcl_paths.patch;
-      inherit tk tcl;
-      tk_dev = tk.dev;
-      tcl_dev = tcl;
-      tk_libprefix = tk.libPrefix;
-      tcl_libprefix = tcl.libPrefix;
-    })
-  ];
-
-  postPatch = ''
-    substituteInPlace "lib-python/2.7/lib-tk/Tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'"
-
-    # hint pypy to find nix ncurses
-    substituteInPlace pypy/module/_minimal_curses/fficurses.py \
-      --replace "/usr/include/ncurses/curses.h" "${ncurses.dev}/include/curses.h" \
-      --replace "ncurses/curses.h" "${ncurses.dev}/include/curses.h" \
-      --replace "ncurses/term.h" "${ncurses.dev}/include/term.h" \
-      --replace "libraries=['curses']" "libraries=['ncurses']"
-
-    sed -i "s@libraries=\['sqlite3'\]\$@libraries=['sqlite3'], include_dirs=['${sqlite.dev}/include'], library_dirs=['${sqlite.out}/lib']@" lib_pypy/_sqlite3_build.py
-  '';
-
-  buildPhase = ''
-    ${pythonForPypy.interpreter} rpython/bin/rpython \
-      --make-jobs="$NIX_BUILD_CORES" \
-      -Ojit \
-      --batch pypy/goal/targetpypystandalone.py
-  '';
-
-  setupHook = python-setup-hook sitePackages;
-
-  doCheck = true;
-  checkPhase = ''
-    export TERMINFO="${ncurses.out}/share/terminfo/";
-    export TERM="xterm";
-    export HOME="$TMPDIR";
-    # disable shutils because it assumes gid 0 exists
-    # disable socket because it has two actual network tests that fail
-    # disable test_urllib2net, test_urllib2_localnet, and test_urllibnet because they require networking (example.com)
-    ./pypy-c ./pypy/test_all.py --pypy=./pypy-c -k 'not ( test_urllib2net or test_urllibnet or test_urllib2_localnet or test_socket or test_shutil )' lib-python
-  '';
-
-  installPhase = ''
-    mkdir -p $out/{bin,include,lib,pypy-c}
-
-    cp -R {include,lib_pypy,lib-python,pypy-c} $out/pypy-c
-    cp libpypy-c.so $out/lib/
-    ln -s $out/pypy-c/pypy-c $out/bin/pypy
-    chmod +x $out/bin/pypy
-
-    # other packages expect to find stuff according to libPrefix
-    ln -s $out/pypy-c/include $out/include/${libPrefix}
-    ln -s $out/pypy-c/lib-python/${pythonVersion} $out/lib/${libPrefix}
-
-    # We must wrap the original, not the symlink.
-    # PyPy uses argv[0] to find its standard library, and while it knows
-    # how to follow symlinks, it doesn't know about wrappers. So, it
-    # will think the wrapper is the original. As long as the wrapper has
-    # the same path as the original, this is OK.
-    wrapProgram "$out/pypy-c/pypy-c" \
-      --set LD_LIBRARY_PATH "${LD_LIBRARY_PATH}:$out/lib" \
-      --set LIBRARY_PATH "${LIBRARY_PATH}:$out/lib"
-
-    # verify cffi modules
-    $out/bin/pypy -c "import Tkinter;import sqlite3;import curses"
-
-    # Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484
-    echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py
-  '';
-
-  passthru = let
-    pythonPackages = callPackage ../../../../../top-level/python-packages.nix {python=self; overrides=packageOverrides;};
-  in rec {
-    inherit zlibSupport libPrefix sitePackages;
-    executable = "pypy";
-    isPypy = true;
-    isPy2 = true;
-    isPy27 = true;
-    buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
-    interpreter = "${self}/bin/${executable}";
-    withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
-    pkgs = pythonPackages;
-  };
-
-  enableParallelBuilding = true;  # almost no parallelization without STM
-
-  meta = with stdenv.lib; {
-    homepage = http://pypy.org/;
-    description = "Fast, compliant alternative implementation of the Python language (2.7.13)";
-    license = licenses.mit;
-    platforms = [ "i686-linux" "x86_64-linux" ];
-    maintainers = with maintainers; [ ];
-  };
-}
diff --git a/nixpkgs/pkgs/development/interpreters/python/pypy/3/default.nix b/nixpkgs/pkgs/development/interpreters/python/pypy/3/default.nix
deleted file mode 100644
index 23e239d925ba..000000000000
--- a/nixpkgs/pkgs/development/interpreters/python/pypy/3/default.nix
+++ /dev/null
@@ -1,138 +0,0 @@
-{ stdenv, substituteAll, fetchurl
-, zlib ? null, zlibSupport ? true, bzip2, pkgconfig, libffi
-, sqlite, openssl, ncurses, python, expat, tcl, tk, tix, xlibsWrapper, libX11
-, makeWrapper, callPackage, self, gdbm, db, lzma
-, python-setup-hook
-# For the Python package set
-, packageOverrides ? (self: super: {})
-}:
-
-assert zlibSupport -> zlib != null;
-
-let
-  version = "6.0.0";
-  pythonVersion = "3.5";
-  libPrefix = "pypy${pythonVersion}";
-  sitePackages = "site-packages";
-
-  pythonForPypy = python.withPackages (ppkgs: [ ppkgs.pycparser ]);
-
-in stdenv.mkDerivation rec {
-  name = "pypy3-${version}";
-  inherit version pythonVersion;
-
-  src = fetchurl {
-    url = "https://bitbucket.org/pypy/pypy/get/release-pypy${pythonVersion}-v${version}.tar.bz2";
-    sha256 = "0lwq8nn0r5yj01bwmkk5p7xvvrp4s550l8184mkmn74d3gphrlwg";
-  };
-
-  nativeBuildInputs = [ pkgconfig makeWrapper ];
-  buildInputs = [
-    bzip2 openssl pythonForPypy libffi ncurses expat sqlite tk tcl xlibsWrapper libX11 gdbm db lzma
-  ] ++ stdenv.lib.optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc
-    ++ stdenv.lib.optional zlibSupport zlib;
-
-  hardeningDisable = stdenv.lib.optional stdenv.isi686 "pic";
-
-  C_INCLUDE_PATH = stdenv.lib.makeSearchPathOutput "dev" "include" buildInputs;
-  LIBRARY_PATH = stdenv.lib.makeLibraryPath buildInputs;
-  LD_LIBRARY_PATH = stdenv.lib.makeLibraryPath (stdenv.lib.filter (x : x.outPath != stdenv.cc.libc.outPath or "") buildInputs);
-
-  patches = [
-    (substituteAll {
-      src = ./tk_tcl_paths.patch;
-      inherit tk tcl;
-      tk_dev = tk.dev;
-      tcl_dev = tcl;
-      tk_libprefix = tk.libPrefix;
-      tcl_libprefix = tcl.libPrefix;
-    })
-  ];
-
-  postPatch = ''
-    substituteInPlace "lib-python/3/tkinter/tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'"
-
-    # hint pypy to find nix ncurses
-    substituteInPlace pypy/module/_minimal_curses/fficurses.py \
-      --replace "/usr/include/ncurses/curses.h" "${ncurses.dev}/include/curses.h" \
-      --replace "ncurses/curses.h" "${ncurses.dev}/include/curses.h" \
-      --replace "ncurses/term.h" "${ncurses.dev}/include/term.h" \
-      --replace "libraries=['curses']" "libraries=['ncurses']"
-
-    sed -i "s@libraries=\['sqlite3'\]\$@libraries=['sqlite3'], include_dirs=['${sqlite.dev}/include'], library_dirs=['${sqlite.out}/lib']@" lib_pypy/_sqlite3_build.py
-  '';
-
-  buildPhase = ''
-    ${pythonForPypy.interpreter} rpython/bin/rpython \
-      --make-jobs="$NIX_BUILD_CORES" \
-      -Ojit \
-      --batch pypy/goal/targetpypystandalone.py
-  '';
-
-  setupHook = python-setup-hook sitePackages;
-
-  doCheck = true;
-  checkPhase = ''
-    export TERMINFO="${ncurses.out}/share/terminfo/";
-    export TERM="xterm";
-    export HOME="$TMPDIR";
-    # disable asyncio due to https://github.com/NixOS/nix/issues/1238
-    # disable os due to https://github.com/NixOS/nixpkgs/issues/10496
-    # disable pathlib due to https://bitbucket.org/pypy/pypy/pull-requests/594
-    # disable shutils because it assumes gid 0 exists
-    # disable socket because it has two actual network tests that fail
-    # disable tarfile because it assumes gid 0 exists
-    ${pythonForPypy.interpreter} ./pypy/test_all.py --pypy=./pypy3-c -k 'not ( test_asyncio or test_os or test_pathlib or test_shutil or test_socket or test_tarfile )' lib-python
-  '';
-
-  installPhase = ''
-    mkdir -p $out/{bin,include,lib,pypy3-c}
-
-    cp -R {include,lib_pypy,lib-python,pypy3-c} $out/pypy3-c
-    cp libpypy3-c.so $out/lib/
-    ln -s $out/pypy3-c/pypy3-c $out/bin/pypy3
-
-    # other packages expect to find stuff according to libPrefix
-    ln -s $out/pypy3-c/include $out/include/${libPrefix}
-    ln -s $out/pypy3-c/lib-python/3 $out/lib/${libPrefix}
-
-    # We must wrap the original, not the symlink.
-    # PyPy uses argv[0] to find its standard library, and while it knows
-    # how to follow symlinks, it doesn't know about wrappers. So, it
-    # will think the wrapper is the original. As long as the wrapper has
-    # the same path as the original, this is OK.
-    wrapProgram "$out/pypy3-c/pypy3-c" \
-      --set LD_LIBRARY_PATH "${LD_LIBRARY_PATH}:$out/lib" \
-      --set LIBRARY_PATH "${LIBRARY_PATH}:$out/lib"
-
-    # verify cffi modules
-    $out/bin/pypy3 -c "import tkinter;import sqlite3;import curses;import lzma"
-
-    # Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484
-    echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py
-  '';
-
-  passthru = let
-    pythonPackages = callPackage ../../../../../top-level/python-packages.nix {python=self; overrides=packageOverrides;};
-  in rec {
-    inherit zlibSupport libPrefix sitePackages;
-    executable = "pypy3";
-    isPypy = true;
-    isPy3 = true;
-    isPy35 = true;
-    buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
-    interpreter = "${self}/bin/${executable}";
-    withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
-    pkgs = pythonPackages;
-  };
-
-  enableParallelBuilding = true;  # almost no parallelization without STM
-
-  meta = with stdenv.lib; {
-    homepage = http://pypy.org/;
-    description = "Fast, compliant alternative implementation of the Python language (3.5.3)";
-    license = licenses.mit;
-    platforms = [ "i686-linux" "x86_64-linux" ];
-    maintainers = with maintainers; [ andersk ];
-  };
-}
diff --git a/nixpkgs/pkgs/development/interpreters/python/pypy/3/tk_tcl_paths.patch b/nixpkgs/pkgs/development/interpreters/python/pypy/3/tk_tcl_paths.patch
deleted file mode 100644
index 92bbfc557b35..000000000000
--- a/nixpkgs/pkgs/development/interpreters/python/pypy/3/tk_tcl_paths.patch
+++ /dev/null
@@ -1,17 +0,0 @@
---- pypy-pypy-84a2f3e6a7f8.org/lib_pypy/_tkinter/tklib_build.py	2017-10-03 11:49:20.000000000 +0100
-+++ pypy-pypy-84a2f3e6a7f8/lib_pypy/_tkinter/tklib_build.py	2017-11-21 13:20:51.398607530 +0000
-@@ -24,11 +24,11 @@
- else:
-     # On some Linux distributions, the tcl and tk libraries are
-     # stored in /usr/include, so we must check this case also
--    libdirs = []
-+    libdirs = ["@tcl@/lib", "@tk@/lib"]
-     found = False
-     for _ver in ['', '8.6', '8.5']:
--        incdirs = ['/usr/include/tcl' + _ver]
--        linklibs = ['tcl' + _ver, 'tk' + _ver]
-+        incdirs = ['@tcl_dev@/include', '@tk_dev@/include']
-+        linklibs = ['@tcl_libprefix@', '@tk_libprefix@']
-         if os.path.isdir(incdirs[0]):
-             found = True
-             break
diff --git a/nixpkgs/pkgs/development/interpreters/python/pypy/default.nix b/nixpkgs/pkgs/development/interpreters/python/pypy/default.nix
new file mode 100644
index 000000000000..193f134e5c6c
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/pypy/default.nix
@@ -0,0 +1,148 @@
+{ stdenv, substituteAll, fetchurl
+, zlib ? null, zlibSupport ? true, bzip2, pkgconfig, libffi
+, sqlite, openssl, ncurses, python, expat, tcl, tk, tix, xlibsWrapper, libX11
+, callPackage, self, gdbm, db, lzma
+, python-setup-hook
+# For the Python package set
+, packageOverrides ? (self: super: {})
+, sourceVersion
+, pythonVersion
+, sha256
+, passthruFun
+}:
+
+assert zlibSupport -> zlib != null;
+
+with stdenv.lib;
+
+let
+  isPy3k = substring 0 1 pythonVersion == "3";
+  passthru = passthruFun rec {
+    inherit self sourceVersion pythonVersion packageOverrides;
+    implementation = "pypy";
+    libPrefix = "pypy${pythonVersion}";
+    executable = "pypy${if isPy3k then "3" else ""}";
+    pythonForBuild = self; # No cross-compiling for now.
+    sitePackages = "site-packages";
+  };
+  pname = passthru.executable;
+  version = with sourceVersion; "${major}.${minor}.${patch}";
+  pythonForPypy = python.withPackages (ppkgs: [ ppkgs.pycparser ]);
+
+in with passthru; stdenv.mkDerivation rec {
+  inherit pname version;
+
+  src = fetchurl {
+    url = "https://bitbucket.org/pypy/pypy/get/release-pypy${pythonVersion}-v${version}.tar.bz2";
+    inherit sha256;
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [
+    bzip2 openssl pythonForPypy libffi ncurses expat sqlite tk tcl xlibsWrapper libX11 gdbm db
+  ]  ++ optionals isPy3k [
+    lzma
+  ] ++ optionals (stdenv ? cc && stdenv.cc.libc != null) [
+    stdenv.cc.libc
+  ] ++ optionals zlibSupport [
+    zlib
+  ];
+
+  hardeningDisable = optional stdenv.isi686 "pic";
+
+  C_INCLUDE_PATH = makeSearchPathOutput "dev" "include" buildInputs;
+  LIBRARY_PATH = makeLibraryPath buildInputs;
+  LD_LIBRARY_PATH = makeLibraryPath (filter (x : x.outPath != stdenv.cc.libc.outPath or "") buildInputs);
+
+  patches = [
+    (substituteAll {
+      src = ./tk_tcl_paths.patch;
+      inherit tk tcl;
+      tk_dev = tk.dev;
+      tcl_dev = tcl;
+      tk_libprefix = tk.libPrefix;
+      tcl_libprefix = tcl.libPrefix;
+    })
+  ];
+
+  postPatch = ''
+    substituteInPlace "lib-python/${if isPy3k then "3/tkinter/tix.py" else "2.7/lib-tk/Tix.py"}" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'"
+
+    # hint pypy to find nix ncurses
+    substituteInPlace pypy/module/_minimal_curses/fficurses.py \
+      --replace "/usr/include/ncurses/curses.h" "${ncurses.dev}/include/curses.h" \
+      --replace "ncurses/curses.h" "${ncurses.dev}/include/curses.h" \
+      --replace "ncurses/term.h" "${ncurses.dev}/include/term.h" \
+      --replace "libraries=['curses']" "libraries=['ncurses']"
+
+    sed -i "s@libraries=\['sqlite3'\]\$@libraries=['sqlite3'], include_dirs=['${sqlite.dev}/include'], library_dirs=['${sqlite.out}/lib']@" lib_pypy/_sqlite3_build.py
+  '';
+
+  buildPhase = ''
+    ${pythonForPypy.interpreter} rpython/bin/rpython \
+      --make-jobs="$NIX_BUILD_CORES" \
+      -Ojit \
+      --batch pypy/goal/targetpypystandalone.py
+  '';
+
+  setupHook = python-setup-hook sitePackages;
+
+  doCheck = true;
+  checkPhase = let
+    disabledTests = [
+      # disable shutils because it assumes gid 0 exists
+      "test_shutil"
+      # disable socket because it has two actual network tests that fail
+      "test_socket"
+    ] ++ optionals (!isPy3k) [
+      # disable test_urllib2net, test_urllib2_localnet, and test_urllibnet because they require networking (example.com)
+      "test_urllib2net"
+      "test_urllibnet"
+      "test_urllib2_localnet"
+    ] ++ optionals isPy3k [
+      # disable asyncio due to https://github.com/NixOS/nix/issues/1238
+      "test_asyncio"
+      # disable os due to https://github.com/NixOS/nixpkgs/issues/10496
+      "test_os"
+      # disable pathlib due to https://bitbucket.org/pypy/pypy/pull-requests/594
+      "test_pathlib"
+      # disable tarfile because it assumes gid 0 exists
+      "test_tarfile"
+    ];
+  in ''
+    export TERMINFO="${ncurses.out}/share/terminfo/";
+    export TERM="xterm";
+    export HOME="$TMPDIR";
+
+    ${pythonForPypy.interpreter} ./pypy/test_all.py --pypy=./${executable}-c -k 'not (${concatStringsSep " or " disabledTests})' lib-python
+  '';
+
+  installPhase = ''
+    mkdir -p $out/{bin,include,lib,${executable}-c}
+
+    cp -R {include,lib_pypy,lib-python,${executable}-c} $out/${executable}-c
+    cp lib${executable}-c.so $out/lib/
+    ln -s $out/${executable}-c/${executable}-c $out/bin/${executable}
+
+    # other packages expect to find stuff according to libPrefix
+    ln -s $out/${executable}/include $out/include/${libPrefix}
+    ln -s $out/${executable}-c/lib-python/${if isPy3k then "3" else pythonVersion} $out/lib/${libPrefix}
+
+    # verify cffi modules
+    $out/bin/${executable} -c ${if isPy3k then "'import tkinter;import sqlite3;import curses;import lzma'" else "'import Tkinter;import sqlite3;import curses'"}
+
+    # Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484
+    echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py
+  '';
+
+  inherit passthru;
+  enableParallelBuilding = true;  # almost no parallelization without STM
+
+  meta = with stdenv.lib; {
+    homepage = http://pypy.org/;
+    description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})";
+    license = licenses.mit;
+    platforms = [ "i686-linux" "x86_64-linux" ];
+    maintainers = with maintainers; [ andersk ];
+  };
+}
diff --git a/nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix b/nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix
new file mode 100644
index 000000000000..ee556ba05bf5
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix
@@ -0,0 +1,123 @@
+{ stdenv
+, fetchurl
+, python-setup-hook
+, self
+, which
+# Dependencies
+, bzip2
+, zlib
+, openssl
+, expat
+, libffi
+, ncurses
+, tcl
+, tk
+# For the Python package set
+, packageOverrides ? (self: super: {})
+, sourceVersion
+, pythonVersion
+, sha256
+, passthruFun
+}:
+
+# This version of PyPy is primarily added to speed-up translation of
+# our PyPy source build when developing that expression.
+
+with stdenv.lib;
+
+let
+  isPy3k = majorVersion == "3";
+  passthru = passthruFun rec {
+    inherit self sourceVersion pythonVersion packageOverrides;
+    implementation = "pypy";
+    libPrefix = "pypy${pythonVersion}";
+    executable = "pypy${if isPy3k then "3" else ""}";
+    pythonForBuild = self; # Not possible to cross-compile with.
+    sitePackages = "site-packages";
+  };
+  pname = "${passthru.executable}_prebuilt";
+  version = with sourceVersion; "${major}.${minor}.${patch}";
+
+  majorVersion = substring 0 1 pythonVersion;
+
+  setupHook = python-setup-hook sitePackages;
+
+  deps = [
+    bzip2
+    zlib
+    openssl
+    expat
+    libffi
+    ncurses
+    tcl
+    tk
+  ];
+
+in with passthru; stdenv.mkDerivation {
+  inherit pname version;
+
+  src = fetchurl {
+    url= "https://bitbucket.org/pypy/pypy/downloads/pypy${majorVersion}-v${version}-linux64.tar.bz2";
+    inherit sha256;
+  };
+
+  buildInputs = [ which ];
+
+  installPhase = ''
+    mkdir -p $out/lib
+    echo "Moving files to $out"
+    mv -t $out bin include lib-python lib_pypy site-packages
+
+    mv $out/bin/libpypy*-c.so $out/lib/
+
+    rm $out/bin/*.debug
+
+    echo "Patching binaries"
+    interpreter=$(patchelf --print-interpreter $(readlink -f $(which patchelf)))
+    patchelf --set-interpreter $interpreter \
+             --set-rpath $out/lib \
+             $out/bin/pypy*
+
+    pushd $out
+    find {lib,lib_pypy*} -name "*.so" -exec patchelf --replace-needed "libbz2.so.1.0" "libbz2.so.1" {} \;
+    find {lib,lib_pypy*} -name "*.so" -exec patchelf --set-rpath ${stdenv.lib.makeLibraryPath deps} {} \;
+
+    echo "Removing bytecode"
+    find . -name "__pycache__" -type d -depth -exec rm -rf {} \;
+    popd
+  '';
+
+  doInstallCheck = true;
+
+  # Check whether importing of (extension) modules functions
+  installCheckPhase = let
+    modules = [
+      "ssl"
+      "sys"
+      "curses"
+    ] ++ optionals (!isPy3k) [
+      "Tkinter"
+    ] ++ optionals isPy3k [
+      "tkinter"
+    ];
+    imports = concatMapStringsSep "; " (x: "import ${x}") modules;
+  in ''
+    echo "Testing whether we can import modules"
+    $out/bin/${executable} -c '${imports}'
+  '';
+
+  setupHook = python-setup-hook sitePackages;
+
+  donPatchElf = true;
+  dontStrip = true;
+
+  inherit passthru;
+
+  meta = with stdenv.lib; {
+    homepage = http://pypy.org/;
+    description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})";
+    license = licenses.mit;
+    platforms = [ "x86_64-linux" ];
+  };
+
+}
\ No newline at end of file
diff --git a/nixpkgs/pkgs/development/interpreters/python/pypy/2.7/tk_tcl_paths.patch b/nixpkgs/pkgs/development/interpreters/python/pypy/tk_tcl_paths.patch
index 92bbfc557b35..92bbfc557b35 100644
--- a/nixpkgs/pkgs/development/interpreters/python/pypy/2.7/tk_tcl_paths.patch
+++ b/nixpkgs/pkgs/development/interpreters/python/pypy/tk_tcl_paths.patch
diff --git a/nixpkgs/pkgs/development/interpreters/python/wrap-python.nix b/nixpkgs/pkgs/development/interpreters/python/wrap-python.nix
index 1efd777bb052..6a19a2152419 100644
--- a/nixpkgs/pkgs/development/interpreters/python/wrap-python.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/wrap-python.nix
@@ -7,9 +7,10 @@ with lib;
 
 makeSetupHook {
       deps = makeWrapper;
-      substitutions.libPrefix = python.libPrefix;
+      substitutions.sitePackages = python.sitePackages;
       substitutions.executable = python.interpreter;
-      substitutions.python = python;
+      substitutions.python = python.pythonForBuild;
+      substitutions.pythonHost = python;
       substitutions.magicalSedExpression = let
         # Looks weird? Of course, it's between single quoted shell strings.
         # NOTE: Order DOES matter here, so single character quotes need to be
diff --git a/nixpkgs/pkgs/development/interpreters/python/wrap.sh b/nixpkgs/pkgs/development/interpreters/python/wrap.sh
index 01b573e6ad5d..b2d65422db45 100644
--- a/nixpkgs/pkgs/development/interpreters/python/wrap.sh
+++ b/nixpkgs/pkgs/development/interpreters/python/wrap.sh
@@ -16,8 +16,8 @@ buildPythonPath() {
     declare -A pythonPathsSeen=()
     program_PYTHONPATH=
     program_PATH=
-    pythonPathsSeen["@python@"]=1
-    addToSearchPath program_PATH @python@/bin
+    pythonPathsSeen["@pythonHost@"]=1
+    addToSearchPath program_PATH @pythonHost@/bin
     for path in $pythonPath; do
         _addToPythonPath $path
     done
@@ -53,7 +53,13 @@ wrapPythonProgramsIn() {
             # Strip suffix, like "3" or "2.7m" -- we don't have any choice on which
             # Python to use besides one with this hook anyway.
             if head -n1 "$f" | grep -q '#!.*/env.*\(python\|pypy\)'; then
-                sed -i "$f" -e "1 s^.*/env[ ]*\(python\|pypy\)[^ ]*^#! @executable@^"
+                sed -i "$f" -e "1 s^.*/env[ ]*\(python\|pypy\)[^ ]*^#!@executable@^"
+            fi
+
+            if head -n1 "$f" | grep -q '#!.*'; then
+                # Cross-compilation hack: ensure shebangs are for the host
+                echo "Rewriting $(head -n 1 $f) to #!@pythonHost@"
+                sed -i "$f" -e "1 s^#!@python@^#!@pythonHost@^"
             fi
 
             # catch /python and /.python-wrapped
@@ -92,7 +98,7 @@ _addToPythonPath() {
     pythonPathsSeen[$dir]=1
     # addToSearchPath is defined in stdenv/generic/setup.sh. It will have
     # the effect of calling `export program_X=$dir/...:$program_X`.
-    addToSearchPath program_PYTHONPATH $dir/lib/@libPrefix@/site-packages
+    addToSearchPath program_PYTHONPATH $dir/@sitePackages@
     addToSearchPath program_PATH $dir/bin
 
     # Inspect the propagated inputs (if they exist) and recur on them.
@@ -113,9 +119,9 @@ createBuildInputsPth() {
             if $(echo -n $x |grep -q python-recursive-pth-loader); then
                 continue
             fi
-            if test -d "$x"/lib/@libPrefix@/site-packages; then
-                echo $x/lib/@libPrefix@/site-packages \
-                    >> "$out"/lib/@libPrefix@/site-packages/${name}-nix-python-$category.pth
+            if test -d "$x"/@sitePackages@; then
+                echo $x/@sitePackages@ \
+                    >> "$out"/@sitePackages@/${name}-nix-python-$category.pth
             fi
         done
     fi
diff --git a/nixpkgs/pkgs/development/interpreters/racket/default.nix b/nixpkgs/pkgs/development/interpreters/racket/default.nix
index ba66404062be..2d4008d69b98 100644
--- a/nixpkgs/pkgs/development/interpreters/racket/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/racket/default.nix
@@ -10,6 +10,7 @@
 , disableDocs ? false
 , CoreFoundation
 , gsettings-desktop-schemas
+, wrapGAppsHook
 }:
 
 let
@@ -40,7 +41,7 @@ in
 
 stdenv.mkDerivation rec {
   name = "racket-${version}";
-  version = "7.1"; # always change at once with ./minimal.nix
+  version = "7.2"; # always change at once with ./minimal.nix
 
   src = (stdenv.lib.makeOverridable ({ name, sha256 }:
     fetchurl rec {
@@ -49,7 +50,7 @@ stdenv.mkDerivation rec {
     }
   )) {
     inherit name;
-    sha256 = "180z0z6srzyipi9wfnbh61nbvzxr5d1cls7wxapv6fw92y52jwz9";
+    sha256 = "12cq0kiigmf9bxb4rcgxdhwc2fcdwvlyb1q3f8x4hswcpgq1ybg4";
   };
 
   FONTCONFIG_FILE = fontsConf;
@@ -59,16 +60,20 @@ stdenv.mkDerivation rec {
     (stdenv.lib.optionalString stdenv.isDarwin "-framework CoreFoundation")
   ];
 
-  buildInputs = [ fontconfig libffi libtool makeWrapper sqlite gsettings-desktop-schemas gtk3 ]
+  nativeBuildInputs = [ wrapGAppsHook ];
+
+  buildInputs = [ fontconfig libffi libtool sqlite gsettings-desktop-schemas gtk3 ]
     ++ stdenv.lib.optionals stdenv.isDarwin [ libiconv CoreFoundation ];
 
   preConfigure = ''
     unset AR
-    for f in src/configure src/racket/src/string.c; do
+    for f in src/lt/configure src/cs/c/configure src/racket/src/string.c; do
       substituteInPlace "$f" --replace /usr/bin/uname ${coreutils}/bin/uname
     done
     mkdir src/build
     cd src/build
+
+    gappsWrapperArgs+=("--prefix" "LD_LIBRARY_PATH" ":" ${LD_LIBRARY_PATH})
   '';
 
   shared = if stdenv.isDarwin then "dylib" else "shared";
@@ -80,13 +85,6 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = false;
 
-  postInstall = ''
-    for p in $(ls $out/bin/) ; do
-      wrapProgram $out/bin/$p \
-        --prefix LD_LIBRARY_PATH ":" "${LD_LIBRARY_PATH}" \
-        --prefix XDG_DATA_DIRS ":" "$GSETTINGS_SCHEMAS_PATH";
-    done
-  '';
 
   meta = with stdenv.lib; {
     description = "A programmable programming language";
@@ -103,5 +101,6 @@ stdenv.mkDerivation rec {
     license = licenses.lgpl3;
     maintainers = with maintainers; [ kkallio henrytill vrthra ];
     platforms = [ "x86_64-darwin" "x86_64-linux" ];
+    broken = stdenv.isDarwin; # No support yet for setting FFI lookup path
   };
 }
diff --git a/nixpkgs/pkgs/development/interpreters/racket/minimal.nix b/nixpkgs/pkgs/development/interpreters/racket/minimal.nix
index 114023defcd4..0710c4e2d2a6 100644
--- a/nixpkgs/pkgs/development/interpreters/racket/minimal.nix
+++ b/nixpkgs/pkgs/development/interpreters/racket/minimal.nix
@@ -5,7 +5,7 @@ racket.overrideAttrs (oldAttrs: rec {
   name = "racket-minimal-${oldAttrs.version}";
   src = oldAttrs.src.override {
     inherit name;
-    sha256 = "11vcqxdgyarv89ijd46wzrdl2wk7xjirg7ynlz7r0smdcqrcl711";
+    sha256 = "01wsiyqfiiwn2n4xxk8d8di92l2ng7yhc4bfmgrvkgaqzy3zfhhx";
   };
 
   meta = oldAttrs.meta // {
@@ -15,5 +15,6 @@ racket.overrideAttrs (oldAttrs: rec {
       and the pkg library are still bundled.
     '';
     platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
+    broken = false; # Minimal build does not require working FFI
   };
 })
diff --git a/nixpkgs/pkgs/development/interpreters/ruby/default.nix b/nixpkgs/pkgs/development/interpreters/ruby/default.nix
index 3408a4c2a648..7563593556ca 100644
--- a/nixpkgs/pkgs/development/interpreters/ruby/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/ruby/default.nix
@@ -75,15 +75,12 @@ let
         # Have `configure' avoid `/usr/bin/nroff' in non-chroot builds.
         NROFF = if docSupport then "${groff}/bin/nroff" else null;
 
-        nativeBuildInputs =
-             ops useRailsExpress [ autoreconfHook bison ]
-          ++ ops (stdenv.buildPlatform != stdenv.hostPlatform) [
-               buildPackages.ruby
-             ];
+        nativeBuildInputs = [ autoreconfHook bison ]
+          ++ (op docSupport groff)
+          ++ op (stdenv.buildPlatform != stdenv.hostPlatform) buildPackages.ruby;
         buildInputs =
              (op fiddleSupport libffi)
           ++ (ops cursesSupport [ ncurses readline ])
-          ++ (op docSupport groff)
           ++ (op zlibSupport zlib)
           ++ (op opensslSupport openssl)
           ++ (op gdbmSupport gdbm)
@@ -160,7 +157,7 @@ let
         postInstall = ''
           # Update rubygems
           pushd rubygems
-          ${buildRuby} setup.rb
+          ${buildRuby} setup.rb --destdir $GEM_HOME
           popd
 
           # Remove unnecessary groff reference from runtime closure, since it's big
@@ -269,10 +266,10 @@ in {
   };
 
   ruby_2_6 = generic {
-    version = rubyVersion "2" "6" "0" "";
+    version = rubyVersion "2" "6" "1" "";
     sha256 = {
-      src = "0wn0gxlx6xhhqrm2caxp0h6cj4nw7knnv5gh27qqzj0i9a95phzk";
-      git = "0bwbl4hz18dd5aij2l4s6xy90dc17d03kk577gdl34l9mbd9m7mn";
+      src = "1f0w37jz2ryvlx260rw3s3wl0wg7dkzphb54lpvrqg90pfvly0hp";
+      git = "07gp7df1izw9rdbp9ciw4q5kq8icx3zd5w1xrhwsw0dfbsmmnsrj";
     };
   };
 }
diff --git a/nixpkgs/pkgs/development/interpreters/ruby/patchsets.nix b/nixpkgs/pkgs/development/interpreters/ruby/patchsets.nix
index 4dc25834314b..0c8415732e60 100644
--- a/nixpkgs/pkgs/development/interpreters/ruby/patchsets.nix
+++ b/nixpkgs/pkgs/development/interpreters/ruby/patchsets.nix
@@ -70,6 +70,6 @@ rec {
     "${patchSet}/patches/ruby/2.5/head/railsexpress/02-improve-gc-stats.patch"
     "${patchSet}/patches/ruby/2.5/head/railsexpress/03-more-detailed-stacktrace.patch"
   ];
-  "2.6.0" = ops useRailsExpress [ # no Rails Express patchset yet (2018-12-26)
+  "2.6.1" = ops useRailsExpress [ # no Rails Express patchset yet (2019-01-30)
   ];
 }
diff --git a/nixpkgs/pkgs/development/interpreters/spidermonkey/1.8.5.nix b/nixpkgs/pkgs/development/interpreters/spidermonkey/1.8.5.nix
index 466371955868..9c81b230ada2 100644
--- a/nixpkgs/pkgs/development/interpreters/spidermonkey/1.8.5.nix
+++ b/nixpkgs/pkgs/development/interpreters/spidermonkey/1.8.5.nix
@@ -44,7 +44,7 @@ stdenv.mkDerivation rec {
   # so the failure of that test does not matter much.
   configureFlags = [ "--enable-threadsafe" "--with-system-nspr" ] ++
     stdenv.lib.optionals (stdenv.hostPlatform.system == "armv5tel-linux") [
-        "--with-cpu-arch=armv5t" 
+        "--with-cpu-arch=armv5t"
         "--disable-tracejit" ];
 
   # hack around a make problem, see https://github.com/NixOS/nixpkgs/issues/1279#issuecomment-29547393
@@ -59,9 +59,6 @@ stdenv.mkDerivation rec {
 
   preCheck = ''
     rm jit-test/tests/sunspider/check-date-format-tofte.js    # https://bugzil.la/600522
-
-    paxmark mr shell/js
-    paxmark mr jsapi-tests/jsapi-tests
   '';
 
   meta = with stdenv.lib; {
diff --git a/nixpkgs/pkgs/development/interpreters/tcl/generic.nix b/nixpkgs/pkgs/development/interpreters/tcl/generic.nix
index a472ccaafbf2..11c02acf1de3 100644
--- a/nixpkgs/pkgs/development/interpreters/tcl/generic.nix
+++ b/nixpkgs/pkgs/development/interpreters/tcl/generic.nix
@@ -15,15 +15,19 @@ stdenv.mkDerivation rec {
   setOutputFlags = false;
 
   preConfigure = ''
-    # Note: using $out instead of $man to prevent a runtime dependency on $man.
-    configureFlagsArray+=(--mandir=$out/share/man --enable-man-symlinks)
-
-    # Don't install tzdata because NixOS already has a more up-to-date copy.
-    configureFlagsArray+=(--with-tzdata=no)
-
     cd unix
   '';
 
+  configureFlags = [
+    "--enable-threads"
+    # Note: using $out instead of $man to prevent a runtime dependency on $man.
+    "--mandir=${placeholder "out"}/share/man"
+    "--enable-man-symlinks"
+    # Don't install tzdata because NixOS already has a more up-to-date copy.
+    "--with-tzdata=no"
+    "tcl_cv_strtod_unbroken=ok"
+  ] ++ stdenv.lib.optional stdenv.is64bit "--enable-64bit";
+
   enableParallelBuilding = true;
 
   postInstall = ''
@@ -36,7 +40,7 @@ stdenv.mkDerivation rec {
     homepage = http://www.tcl.tk/;
     license = licenses.tcltk;
     platforms = platforms.all;
-    maintainers = with maintainers; [ wkennington vrthra ];
+    maintainers = with maintainers; [ vrthra ];
   };
 
   passthru = rec {
diff --git a/nixpkgs/pkgs/development/interpreters/tinyscheme/default.nix b/nixpkgs/pkgs/development/interpreters/tinyscheme/default.nix
new file mode 100644
index 000000000000..f2c5fd938cec
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/tinyscheme/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "tinyscheme-${version}";
+  version = "1.41";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/tinyscheme/${name}.tar.gz";
+    sha256 = "168rk4zrlhsknbvldq2jsgabpwlqkx6la44gkqmijmf7jhs11h7a";
+  };
+
+  patchPhase = ''
+    substituteInPlace scheme.c --replace "init.scm" "$out/lib/init.scm"
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin $out/lib
+    cp init.scm $out/lib
+    cp scheme $out/bin/tinyscheme
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Lightweight Scheme implementation";
+    longDescription = ''
+      TinyScheme is a lightweight Scheme interpreter that implements as large a
+      subset of R5RS as was possible without getting very large and complicated.
+    '';
+    homepage = http://tinyscheme.sourceforge.net/;
+    license = licenses.bsdOriginal;
+    maintainers = [ maintainers.ebzzry ];
+    platforms = platforms.unix;
+  };
+}