From 8de9ac5bd49762ad365dd2ec6cfeda863ea8ff2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Sun, 12 Oct 2014 14:58:07 +0200 Subject: [PATCH 1/3] python: make 2.6 and 2.7 expr similar, introduce includeModules When includeModules is true, python is built with all optional modules as part of derivation. --- .../interpreters/python/2.6/default.nix | 53 +++++++++------- .../interpreters/python/2.7/default.nix | 63 ++++++++----------- 2 files changed, 54 insertions(+), 62 deletions(-) diff --git a/pkgs/development/interpreters/python/2.6/default.nix b/pkgs/development/interpreters/python/2.6/default.nix index 3b2239791ae..dcbb16f5523 100644 --- a/pkgs/development/interpreters/python/2.6/default.nix +++ b/pkgs/development/interpreters/python/2.6/default.nix @@ -1,13 +1,11 @@ -{ stdenv, fetchurl, zlib ? null, zlibSupport ? true, bzip2 -, sqlite, tcl, tk, x11, openssl, readline, db, ncurses, gdbm -}: +{ stdenv, fetchurl, zlib ? null, zlibSupport ? true, bzip2, includeModules ? false +, sqlite, tcl, tk, x11, openssl, readline, db, ncurses, gdbm}: assert zlibSupport -> zlib != null; with stdenv.lib; let - majorVersion = "2.6"; version = "${majorVersion}.9"; @@ -27,37 +25,42 @@ let # the Nix store to 1. So treat that as a special case. ./nix-store-mtime.patch ]; + + preConfigure = '' + # Purity. + for i in /usr /sw /opt /pkg; do + substituteInPlace ./setup.py --replace $i /no-such-path + done + '' + optionalString (stdenv ? gcc && stdenv.gcc.libc != null) '' + for i in Lib/plat-*/regen; do + substituteInPlace $i --replace /usr/include/ ${stdenv.gcc.libc}/include/ + done + '' + optionalString stdenv.isCygwin '' + # On Cygwin, `make install' tries to read this Makefile. + mkdir -p $out/lib/python${majorVersion}/config + touch $out/lib/python${majorVersion}/config/Makefile + mkdir -p $out/include/python${majorVersion} + touch $out/include/python${majorVersion}/pyconfig.h + ''; buildInputs = optional (stdenv ? gcc && stdenv.gcc.libc != null) stdenv.gcc.libc ++ - [ bzip2 openssl ] + [ bzip2 openssl ]++ optionals includeModules [ db openssl ncurses gdbm readline x11 tcl tk sqlite ] ++ optional zlibSupport zlib; # Build the basic Python interpreter without modules that have # external dependencies. python = stdenv.mkDerivation { - name = "python-${version}"; + name = "python${if includeModules then "" else "-minimal"}-${version}"; - inherit majorVersion version src patches buildInputs; + inherit majorVersion version src patches buildInputs preConfigure; C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs); LIBRARY_PATH = concatStringsSep ":" (map (p: "${p}/lib") buildInputs); configureFlags = "--enable-shared --with-threads --enable-unicode"; - preConfigure = - '' - # Purity. - for i in /usr /sw /opt /pkg; do - substituteInPlace ./setup.py --replace $i /no-such-path - done - '' + optionalString (stdenv ? gcc && stdenv.gcc.libc != null) '' - for i in Lib/plat-*/regen; do - substituteInPlace $i --replace /usr/include/ ${stdenv.gcc.libc}/include/ - done - ''; - NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2"; setupHook = ./setup-hook.sh; @@ -69,6 +72,10 @@ let ln -s $out/lib/python${majorVersion}/pdb.py $out/bin/pdb${majorVersion} mv $out/share/man/man1/{python.1,python2.6.1} ln -s $out/share/man/man1/{python2.6.1,python.1} + + paxmark E $out/bin/python${majorVersion} + + ${ optionalString includeModules "$out/bin/python ./setup.py build_ext"} ''; passthru = rec { @@ -96,7 +103,7 @@ let ''; license = stdenv.lib.licenses.psfl; platforms = stdenv.lib.platforms.all; - maintainers = with stdenv.lib.maintainers; [ simons chaoflow ]; + maintainers = with stdenv.lib.maintainers; [ simons chaoflow iElectric ]; }; }; @@ -108,18 +115,16 @@ let , internalName ? "_" + moduleName , deps }: - stdenv.mkDerivation rec { + if (includeModules) then null else stdenv.mkDerivation rec { name = "python-${moduleName}-${python.version}"; - inherit src patches; + inherit src patches preConfigure; buildInputs = [ python ] ++ deps; C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs); LIBRARY_PATH = concatStringsSep ":" (map (p: "${p}/lib") buildInputs); - configurePhase = "true"; - buildPhase = '' # Fake the build environment that setup.py expects. diff --git a/pkgs/development/interpreters/python/2.7/default.nix b/pkgs/development/interpreters/python/2.7/default.nix index cf1d4bdc8da..9c6fd7d75cf 100644 --- a/pkgs/development/interpreters/python/2.7/default.nix +++ b/pkgs/development/interpreters/python/2.7/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchurl, zlib ? null, zlibSupport ? true, bzip2 +{ stdenv, fetchurl, zlib ? null, zlibSupport ? true, bzip2, includeModules ? false , sqlite, tcl, tk, x11, openssl, readline, db, ncurses, gdbm, libX11 }: assert zlibSupport -> zlib != null; @@ -6,7 +6,6 @@ assert zlibSupport -> zlib != null; with stdenv.lib; let - majorVersion = "2.7"; version = "${majorVersion}.8"; @@ -29,32 +28,35 @@ let # if DETERMINISTIC_BUILD env var is set ./deterministic-build.patch ]; - - postPatch = stdenv.lib.optionalString (stdenv.gcc.libc != null) '' - substituteInPlace ./Lib/plat-generic/regen \ - --replace /usr/include/netinet/in.h \ - ${stdenv.gcc.libc}/include/netinet/in.h - ''; - - buildInputs = - optional (stdenv ? gcc && stdenv.gcc.libc != null) stdenv.gcc.libc ++ - [ bzip2 openssl ] - ++ optional zlibSupport zlib; - - ensurePurity = - '' + + preConfigure = '' # Purity. for i in /usr /sw /opt /pkg; do substituteInPlace ./setup.py --replace $i /no-such-path done + '' + optionalString (stdenv ? gcc && stdenv.gcc.libc != null) '' + for i in Lib/plat-*/regen; do + substituteInPlace $i --replace /usr/include/ ${stdenv.gcc.libc}/include/ + done + '' + optionalString stdenv.isCygwin '' + # On Cygwin, `make install' tries to read this Makefile. + mkdir -p $out/lib/python${majorVersion}/config + touch $out/lib/python${majorVersion}/config/Makefile + mkdir -p $out/include/python${majorVersion} + touch $out/include/python${majorVersion}/pyconfig.h ''; + buildInputs = + optional (stdenv ? gcc && stdenv.gcc.libc != null) stdenv.gcc.libc ++ + [ bzip2 openssl ] ++ optionals includeModules [ db openssl ncurses gdbm libX11 readline x11 tcl tk sqlite ] + ++ optional zlibSupport zlib; + # Build the basic Python interpreter without modules that have # external dependencies. python = stdenv.mkDerivation { name = "python-${version}"; - inherit majorVersion version src patches postPatch buildInputs; + inherit majorVersion version src patches buildInputs preConfigure; LDFLAGS = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s"; C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs); @@ -62,15 +64,6 @@ let configureFlags = "--enable-shared --with-threads --enable-unicode"; - preConfigure = "${ensurePurity}" + optionalString stdenv.isCygwin - '' - # On Cygwin, `make install' tries to read this Makefile. - mkdir -p $out/lib/python${majorVersion}/config - touch $out/lib/python${majorVersion}/config/Makefile - mkdir -p $out/include/python${majorVersion} - touch $out/include/python${majorVersion}/pyconfig.h - ''; - NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2"; setupHook = ./setup-hook.sh; @@ -83,6 +76,8 @@ let ln -s $out/share/man/man1/{python2.7.1.gz,python.1.gz} paxmark E $out/bin/python${majorVersion} + + ${ optionalString includeModules "$out/bin/python ./setup.py build_ext"} ''; passthru = rec { @@ -110,7 +105,7 @@ let ''; license = stdenv.lib.licenses.psfl; platforms = stdenv.lib.platforms.all; - maintainers = with stdenv.lib.maintainers; [ simons chaoflow ]; + maintainers = with stdenv.lib.maintainers; [ simons chaoflow iElectric ]; }; }; @@ -122,25 +117,17 @@ let , internalName ? "_" + moduleName , deps }: - stdenv.mkDerivation rec { + if (includeModules) then null else stdenv.mkDerivation rec { name = "python-${moduleName}-${python.version}"; - inherit src patches postPatch; + inherit src patches preConfigure; buildInputs = [ python ] ++ deps; C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs); LIBRARY_PATH = concatStringsSep ":" (map (p: "${p}/lib") buildInputs); - configurePhase = "${ensurePurity}"; - - buildPhase = - '' - # Fake the build environment that setup.py expects. - ln -s ${python}/include/python*/pyconfig.h . - ln -s ${python}/lib/python*/config/Setup Modules/ - ln -s ${python}/lib/python*/config/Setup.local Modules/ - + buildPhase = '' substituteInPlace setup.py --replace 'self.extensions = extensions' \ 'self.extensions = [ext for ext in self.extensions if ext.name in ["${internalName}"]]' From a2a7abc67cff23d6a76fd960e807c08f5c48ac8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Sun, 12 Oct 2014 14:59:31 +0200 Subject: [PATCH 2/3] pythonFull -> python with all modules, pythonFullWithPkgs -> buildEnv --- pkgs/applications/misc/roxterm/default.nix | 2 +- .../interpreters/python/wrapper.nix | 7 +++-- pkgs/development/libraries/thrift/default.nix | 2 +- pkgs/servers/gpsd/default.nix | 2 +- pkgs/top-level/all-packages.nix | 27 ++++++++++--------- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/pkgs/applications/misc/roxterm/default.nix b/pkgs/applications/misc/roxterm/default.nix index a8338b80c9e..60322c2b911 100644 --- a/pkgs/applications/misc/roxterm/default.nix +++ b/pkgs/applications/misc/roxterm/default.nix @@ -29,7 +29,7 @@ in stdenv.mkDerivation rec { "-I${dbus_libs}/lib/dbus-1.0/include" ]; # Fix up python path so the lockfile library is on it. - PYTHONPATH = stdenv.lib.makeSearchPath "lib/${pythonFull.python.libPrefix}/site-packages" [ + PYTHONPATH = stdenv.lib.makeSearchPath "lib/${pythonFull.libPrefix}/site-packages" [ pythonPackages.curses pythonPackages.lockfile ]; diff --git a/pkgs/development/interpreters/python/wrapper.nix b/pkgs/development/interpreters/python/wrapper.nix index ccfbcfcdd42..37180b1472b 100644 --- a/pkgs/development/interpreters/python/wrapper.nix +++ b/pkgs/development/interpreters/python/wrapper.nix @@ -1,12 +1,11 @@ { stdenv, python, buildEnv, makeWrapper, recursivePthLoader, extraLibs ? [], postBuild ? "" -, stdLibs ? stdenv.lib.attrValues python.modules, ignoreCollisions ? false -}: +, ignoreCollisions ? false }: # Create a python executable that knows about additional packages. (buildEnv { - name = "python-${python.version}-wrapper"; - paths = stdenv.lib.filter (x : x ? pythonPath) (stdenv.lib.closePropagation extraLibs) ++ stdLibs ++ [ python recursivePthLoader ]; + name = "python-${python.version}-env"; + paths = stdenv.lib.filter (x : x ? pythonPath) (stdenv.lib.closePropagation extraLibs) ++ [ python recursivePthLoader ]; inherit ignoreCollisions; diff --git a/pkgs/development/libraries/thrift/default.nix b/pkgs/development/libraries/thrift/default.nix index 4f2b6ec49d7..f166e35af1e 100644 --- a/pkgs/development/libraries/thrift/default.nix +++ b/pkgs/development/libraries/thrift/default.nix @@ -21,7 +21,7 @@ stdenv.mkDerivation { patches = [ ./yylex.patch ]; # Workaround to make the python wrapper not drop this package: - # pythonFull.override { extraLibs = [ thrift ]; } + # pythonFullWithPkgs.override { extraLibs = [ thrift ]; } pythonPath = []; buildInputs = [ diff --git a/pkgs/servers/gpsd/default.nix b/pkgs/servers/gpsd/default.nix index 62fbd3337f7..17325ccb291 100644 --- a/pkgs/servers/gpsd/default.nix +++ b/pkgs/servers/gpsd/default.nix @@ -38,7 +38,7 @@ stdenv.mkDerivation rec { buildPhase = '' patchShebangs . mkdir -p "$out" - sed -e "s|python_lib_dir = .*|python_lib_dir = \"$out/lib/${pythonFull.python.libPrefix}/site-packages\"|" -i SConstruct + sed -e "s|python_lib_dir = .*|python_lib_dir = \"$out/lib/${pythonFull.libPrefix}/site-packages\"|" -i SConstruct scons prefix="$out" leapfetch=no gpsd_user=${gpsdUser} gpsd_group=${gpsdGroup} \ systemd=yes udevdir="$out/lib/udev" chrpath=no ''; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index fd93c5f0eb1..1c858ce652b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1875,7 +1875,7 @@ let openobex = callPackage ../tools/bluetooth/openobex { }; openopc = callPackage ../tools/misc/openopc { - pythonFull = python27Full.override { + pythonFull = python27FullWithPkgs.override { extraLibs = [ python27Packages.pyro3 ]; }; }; @@ -3931,9 +3931,6 @@ let python2Packages = python27Packages; python3Packages = python34Packages; - pythonFull = python2Full; - python2Full = python27Full; - python26 = callPackage ../development/interpreters/python/2.6 { db = db47; }; python27 = callPackage ../development/interpreters/python/2.7 { }; python32 = callPackage ../development/interpreters/python/3.2 { }; @@ -3942,18 +3939,24 @@ let pypy = callPackage ../development/interpreters/pypy/2.4 { }; - python26Full = callPackage ../development/interpreters/python/wrapper.nix { - extraLibs = []; - postBuild = ""; - python = python26; + pythonFull = python2Full; + python2Full = python27Full; + python26Full = python26.override { + includeModules = true; + }; + python27Full = python27.override { + includeModules = true; + }; + python26FullWithPkgs = callPackage ../development/interpreters/python/wrapper.nix { + python = python26Full; inherit (python26Packages) recursivePthLoader; }; - python27Full = callPackage ../development/interpreters/python/wrapper.nix { - extraLibs = []; - postBuild = ""; - python = python27; + python27FullWithPkgs = callPackage ../development/interpreters/python/wrapper.nix { + python = python27Full; inherit (python27Packages) recursivePthLoader; }; + pythonFullWithPkgs = python2FullWithPkgs; + python2FullWithPkgs = python27FullWithPkgs; python2nix = callPackage ../tools/package-management/python2nix { }; From 68b183e309df1e7c6d47dac62dfe220af9d16fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Sun, 12 Oct 2014 18:24:16 +0200 Subject: [PATCH 3/3] simplify --- pkgs/development/interpreters/python/2.6/default.nix | 2 +- pkgs/development/interpreters/python/2.7/default.nix | 2 +- pkgs/development/libraries/thrift/default.nix | 2 +- pkgs/top-level/all-packages.nix | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkgs/development/interpreters/python/2.6/default.nix b/pkgs/development/interpreters/python/2.6/default.nix index dcbb16f5523..cbdb55f4cc3 100644 --- a/pkgs/development/interpreters/python/2.6/default.nix +++ b/pkgs/development/interpreters/python/2.6/default.nix @@ -115,7 +115,7 @@ let , internalName ? "_" + moduleName , deps }: - if (includeModules) then null else stdenv.mkDerivation rec { + if includeModules then null else stdenv.mkDerivation rec { name = "python-${moduleName}-${python.version}"; inherit src patches preConfigure; diff --git a/pkgs/development/interpreters/python/2.7/default.nix b/pkgs/development/interpreters/python/2.7/default.nix index 9c6fd7d75cf..e5dff81410c 100644 --- a/pkgs/development/interpreters/python/2.7/default.nix +++ b/pkgs/development/interpreters/python/2.7/default.nix @@ -117,7 +117,7 @@ let , internalName ? "_" + moduleName , deps }: - if (includeModules) then null else stdenv.mkDerivation rec { + if includeModules then null else stdenv.mkDerivation rec { name = "python-${moduleName}-${python.version}"; inherit src patches preConfigure; diff --git a/pkgs/development/libraries/thrift/default.nix b/pkgs/development/libraries/thrift/default.nix index f166e35af1e..29b0c1a9b29 100644 --- a/pkgs/development/libraries/thrift/default.nix +++ b/pkgs/development/libraries/thrift/default.nix @@ -21,7 +21,7 @@ stdenv.mkDerivation { patches = [ ./yylex.patch ]; # Workaround to make the python wrapper not drop this package: - # pythonFullWithPkgs.override { extraLibs = [ thrift ]; } + # pythonFullBuildEnv.override { extraLibs = [ thrift ]; } pythonPath = []; buildInputs = [ diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 1c858ce652b..fc1ed26152d 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1875,7 +1875,7 @@ let openobex = callPackage ../tools/bluetooth/openobex { }; openopc = callPackage ../tools/misc/openopc { - pythonFull = python27FullWithPkgs.override { + pythonFull = python27FullBuildEnv.override { extraLibs = [ python27Packages.pyro3 ]; }; }; @@ -3947,16 +3947,16 @@ let python27Full = python27.override { includeModules = true; }; - python26FullWithPkgs = callPackage ../development/interpreters/python/wrapper.nix { + python26FullBuildEnv = callPackage ../development/interpreters/python/wrapper.nix { python = python26Full; inherit (python26Packages) recursivePthLoader; }; - python27FullWithPkgs = callPackage ../development/interpreters/python/wrapper.nix { + python27FullBuildEnv = callPackage ../development/interpreters/python/wrapper.nix { python = python27Full; inherit (python27Packages) recursivePthLoader; }; - pythonFullWithPkgs = python2FullWithPkgs; - python2FullWithPkgs = python27FullWithPkgs; + pythonFullBuildEnv = python2FullBuildEnv; + python2FullBuildEnv = python27FullBuildEnv; python2nix = callPackage ../tools/package-management/python2nix { };