From 5c0d493df447ac51917908b71f22361d47bb8a56 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Sat, 17 Aug 2019 16:30:26 +0100 Subject: [PATCH 1/8] python: Enable building without openssl --- pkgs/development/interpreters/python/cpython/default.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 2f398d8dccb..e2286c21029 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -134,6 +134,7 @@ in with passthru; stdenv.mkDerivation { "--without-ensurepip" "--with-system-expat" "--with-system-ffi" + ] ++ optionals (openssl != null) [ "--with-openssl=${openssl.dev}" ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "ac_cv_buggy_getaddrinfo=no" @@ -241,9 +242,9 @@ in with passthru; stdenv.mkDerivation { # 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) [ + disallowedReferences = + stdenv.lib.optionals (openssl != null) [ 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 From 414cde4df44e61115682d8e846fbfb9db0471eea Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 18 Aug 2019 22:23:13 +0200 Subject: [PATCH 2/8] python: allow stripping IDLE --- pkgs/development/interpreters/python/cpython/default.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index e2286c21029..c1e2cd86634 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -21,6 +21,7 @@ , sha256 , passthruFun , bash +, stripIdlelib ? false }: assert x11Support -> tcl != null @@ -222,6 +223,10 @@ in with passthru; stdenv.mkDerivation { find $out/lib/python*/config-* -type f -print -exec nuke-refs -e $out '{}' + find $out/lib -name '_sysconfigdata*.py*' -print -exec nuke-refs -e $out '{}' + + '' + optionalString stripIdlelib '' + # Strip IDLE (and turtledemo, which uses it) + rm -R $out/bin/idle* $out/lib/python*/{idlelib,turtledemo} + '' + '' # Include a sitecustomize.py file cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py From d03283c029f4551ba077d612262c54a6cd9343e9 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 18 Aug 2019 22:34:12 +0200 Subject: [PATCH 3/8] python: allow stripping tests --- pkgs/development/interpreters/python/cpython/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index c1e2cd86634..420d4b18ea7 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -22,6 +22,7 @@ , passthruFun , bash , stripIdlelib ? false +, stripTests ? false }: assert x11Support -> tcl != null @@ -226,6 +227,9 @@ in with passthru; stdenv.mkDerivation { '' + optionalString stripIdlelib '' # Strip IDLE (and turtledemo, which uses it) rm -R $out/bin/idle* $out/lib/python*/{idlelib,turtledemo} + '' + optionalString stripTests '' + # Strip tests + rm -R $out/lib/python*/test $out/lib/python*/**/test{,s} '' + '' # Include a sitecustomize.py file cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py From 8335f3dd5cd7a8da3bd35114d740e1c73a5b502b Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 18 Aug 2019 23:10:20 +0200 Subject: [PATCH 4/8] python: allow stripping config --- pkgs/development/interpreters/python/cpython/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 420d4b18ea7..071450ab84e 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -21,6 +21,7 @@ , sha256 , passthruFun , bash +, stripConfig ? false , stripIdlelib ? false , stripTests ? false }: @@ -224,6 +225,8 @@ in with passthru; stdenv.mkDerivation { find $out/lib/python*/config-* -type f -print -exec nuke-refs -e $out '{}' + find $out/lib -name '_sysconfigdata*.py*' -print -exec nuke-refs -e $out '{}' + + '' + optionalString stripConfig '' + rm -R $out/bin/python*-config $out/lib/python*/config-* '' + optionalString stripIdlelib '' # Strip IDLE (and turtledemo, which uses it) rm -R $out/bin/idle* $out/lib/python*/{idlelib,turtledemo} From 52fcbbff44980b27183087f210bf27a820a50541 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 18 Aug 2019 23:31:32 +0200 Subject: [PATCH 5/8] python: make rebuilding bytecode optional --- pkgs/development/interpreters/python/cpython/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 071450ab84e..3f2e7ebaf02 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -24,6 +24,7 @@ , stripConfig ? false , stripIdlelib ? false , stripTests ? false +, rebuildBytecode ? true }: assert x11Support -> tcl != null @@ -236,6 +237,7 @@ in with passthru; stdenv.mkDerivation { '' + '' # Include a sitecustomize.py file cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py + '' + optionalString rebuildBytecode '' # Determinism: rebuild all bytecode # We exclude lib2to3 because that's Python 2 code which fails From db087f226d8fe649f1c437e7afe7f105375c729d Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 18 Aug 2019 23:31:45 +0200 Subject: [PATCH 6/8] python: allow stripping bytecode --- pkgs/development/interpreters/python/cpython/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 3f2e7ebaf02..3eddadeda1d 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -25,6 +25,7 @@ , stripIdlelib ? false , stripTests ? false , rebuildBytecode ? true +, stripBytecode ? false }: assert x11Support -> tcl != null @@ -247,6 +248,8 @@ in with passthru; stdenv.mkDerivation { 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 - + '' + optionalString stripBytecode '' + find $out -type d -name __pycache__ -print0 | xargs -0 -I {} rm -rf "{}" ''; preFixup = stdenv.lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' From 100eae3b77f7ef9c36aa4ff509b2a58c10fcce55 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 19 Aug 2019 00:11:17 +0200 Subject: [PATCH 7/8] python: allow stripping tkinter --- pkgs/development/interpreters/python/cpython/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 3eddadeda1d..7561fdad785 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -24,6 +24,7 @@ , stripConfig ? false , stripIdlelib ? false , stripTests ? false +, stripTkinter ? false , rebuildBytecode ? true , stripBytecode ? false }: @@ -232,6 +233,8 @@ in with passthru; stdenv.mkDerivation { '' + optionalString stripIdlelib '' # Strip IDLE (and turtledemo, which uses it) rm -R $out/bin/idle* $out/lib/python*/{idlelib,turtledemo} + '' + optionalString stripTkinter '' + rm -R $out/lib/python*/tkinter '' + optionalString stripTests '' # Strip tests rm -R $out/lib/python*/test $out/lib/python*/**/test{,s} From 99e6ca2bdc58eb70eed9a75854872f8b02fb5930 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Sat, 17 Aug 2019 16:33:13 +0100 Subject: [PATCH 8/8] python3Minimal: Add top-level for a minimal Python 3 build This builds Python without optional dependencies. We can't just use python3.override, as things like python3Minimal.withPackages would pass the wrong python derivation into these modules. --- .../interpreters/python/default.nix | 32 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/pkgs/development/interpreters/python/default.nix b/pkgs/development/interpreters/python/default.nix index c8856ea2aa3..bab7a047b15 100644 --- a/pkgs/development/interpreters/python/default.nix +++ b/pkgs/development/interpreters/python/default.nix @@ -111,6 +111,38 @@ in { inherit passthruFun; }; + # Minimal versions of Python (built without optional dependencies) + python3Minimal = (callPackage ./cpython { + self = python3Minimal; + sourceVersion = { + major = "3"; + minor = "7"; + patch = "4"; + suffix = ""; + }; + sha256 = "0gxiv5617zd7dnqm5k9r4q2188lk327nf9jznwq9j6b8p0s92ygv"; + inherit (darwin) CF configd; + inherit passthruFun; + + # strip down that python version as much as possible + openssl = null; + readline = null; + ncurses = null; + gdbm = null; + sqlite = null; + stripConfig = true; + stripIdlelib = true; + stripTests = true; + stripTkinter = true; + rebuildBytecode = false; + stripBytecode = true; + }).overrideAttrs(old: { + pname = "python3-minimal"; + meta = old.meta // { + maintainers = []; + }; + }); + pypy27 = callPackage ./pypy { self = pypy27; sourceVersion = { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c2df042eae2..9142a33aeda 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8754,7 +8754,7 @@ in python3Packages = python3.pkgs; pythonInterpreters = callPackage ./../development/interpreters/python {}; - inherit (pythonInterpreters) python27 python35 python36 python37 python38 pypy27 pypy36; + inherit (pythonInterpreters) python27 python35 python36 python37 python38 python3Minimal pypy27 pypy36; # Python package sets. python27Packages = lib.hiPrioSet (recurseIntoAttrs python27.pkgs);