Files
nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt_2_7.nix
John Ericson c8e1365d31 pypy: Stop the prebuilt interpreters depending on Tcl/Tk 8.5
`prebuilt.nix` (3.10, 3.11) asked for Tcl/Tk 8.5 on Linux, but the
`_tkinter` extension in those tarballs is linked against `libtcl8.6.so`
and `libtk8.6.so`. It resolved anyway, because the tarball vendors its own
copy of both under `lib/`. So the declared dependency was doing nothing,
and `tkinter` -- which is stdlib, not an optional extra -- was quietly
running against a bundled Tcl that we do not update.

Point it at our 8.6 instead, and delete the vendored libraries so it has
to. The vendored *script* libraries have to go too: `init.tcl` checks the
exact patchlevel, so our 8.6.16 rejects the bundled 8.6.14 copy as "not
usable" and `Tcl_Init` fails. Note that the existing `installCheckPhase`
does not catch that, as `import tkinter` never creates an interpreter;
`tkinter.Tcl()` does.

`prebuilt_2_7.nix` genuinely needs 8.5 -- its `tklib_cffi` asks for
`libtcl8.5.so` and its `installPhase` does not keep the bundled `lib/` --
but it exists only to bootstrap the source build of PyPy2, where nothing
imports `tkinter`. Let the module go unresolved and drop it from the
import check rather than keep an end-of-life Tcl alive for it.

Assisted-by: Claude Code (Claude Opus 5)
2026-08-22 21:37:53 -04:00

186 lines
5.2 KiB
Nix

{
lib,
stdenv,
fetchurl,
autoPatchelfHook,
python-setup-hook,
self,
# Dependencies
bzip2,
expat,
gdbm,
ncurses6,
sqlite,
tcl-8_6,
tk-8_6,
zlib,
# For the Python package set
packageOverrides ? (self: super: { }),
sourceVersion,
pythonVersion,
hash,
passthruFun,
}:
# This version of PyPy is primarily added to speed-up translation of
# our PyPy source build when developing that expression.
let
isPy3k = majorVersion == "3";
passthru = passthruFun {
inherit
self
sourceVersion
pythonVersion
packageOverrides
;
implementation = "pypy";
libPrefix = "pypy${pythonVersion}";
executable = "pypy${lib.optionalString isPy3k "3"}";
sitePackages = "site-packages";
hasDistutilsCxxPatch = false;
# Not possible to cross-compile with.
pythonOnBuildForBuild = throw "${pname} does not support cross compilation";
pythonOnBuildForHost = self;
pythonOnBuildForTarget = throw "${pname} does not support cross compilation";
pythonOnHostForHost = throw "${pname} does not support cross compilation";
pythonOnTargetForTarget = throw "${pname} does not support cross compilation";
pythonABITags = [
"none"
"pypy${lib.concatStrings (lib.take 2 (lib.splitString "." pythonVersion))}_pp${sourceVersion.major}${sourceVersion.minor}"
];
};
pname = "${passthru.executable}_prebuilt";
version = with sourceVersion; "${major}.${minor}.${patch}";
majorVersion = lib.versions.major pythonVersion;
downloadUrls = {
aarch64-linux = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-aarch64.tar.bz2";
x86_64-linux = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-linux64.tar.bz2";
aarch64-darwin = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-macos_arm64.tar.bz2";
};
in
with passthru;
stdenv.mkDerivation {
inherit pname version;
src = fetchurl {
url = downloadUrls.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}");
inherit hash;
};
buildInputs = [
bzip2
expat
gdbm
ncurses6
sqlite
zlib
stdenv.cc.cc.libgcc or null
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
tcl-8_6
tk-8_6
];
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
# Only a bootstrap interpreter, so its `tkinter` is never imported. The
# tarball bundles the Tcl/Tk it wants but `installPhase` does not keep
# `lib/`, so rather than depend on a Tcl this old just to satisfy a module
# nobody loads, let the module stay unresolved.
autoPatchelfIgnoreMissingDeps = lib.optionals stdenv.hostPlatform.isLinux [
"libtcl8.5.so"
"libtk8.5.so"
];
installPhase = ''
runHook preInstall
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${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/
${lib.optionalString stdenv.hostPlatform.isLinux ''
rm $out/bin/*.debug
''}
echo "Removing bytecode"
find . -name "__pycache__" -type d -depth -delete
# Include a sitecustomize.py file
cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
runHook postInstall
'';
preFixup =
lib.optionalString (stdenv.hostPlatform.isLinux) ''
find $out/{lib,lib_pypy*} -name "*.so" \
-exec patchelf \
--replace-needed libtinfow.so.6 libncursesw.so.6 \
--replace-needed libgdbm.so.4 libgdbm_compat.so.4 {} \;
''
+ lib.optionalString (stdenv.hostPlatform.isDarwin) ''
install_name_tool \
-change \
@rpath/lib${executable}-c.dylib \
$out/lib/lib${executable}-c.dylib \
$out/bin/${executable}
install_name_tool \
-change \
/opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtcl8.6.dylib \
${tcl-8_6}/lib/libtcl8.6.dylib \
$out/lib_pypy/_tkinter/*.so
install_name_tool \
-change \
/opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtk8.6.dylib \
${tk-8_6}/lib/libtk8.6.dylib \
$out/lib_pypy/_tkinter/*.so
'';
doInstallCheck = true;
# Check whether importing of (extension) modules functions
installCheckPhase =
let
modules = [
"ssl"
"sys"
"curses"
]
# Only Linux gives up on `tkinter`; Darwin still links it against a Tcl
# of ours in `preFixup`.
++ lib.optionals (!isPy3k && !stdenv.hostPlatform.isLinux) [
"Tkinter"
]
++ lib.optionals (isPy3k && !stdenv.hostPlatform.isLinux) [
"tkinter"
];
imports = lib.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 = {
homepage = "http://pypy.org/";
description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})";
license = lib.licenses.mit;
platforms = lib.attrNames downloadUrls;
};
}