From c43592e4980c4d60cfa8e76e2bdf95d90128b95e Mon Sep 17 00:00:00 2001 From: lillecarl Date: Fri, 6 Nov 2026 11:21:54 +0100 Subject: [PATCH] python3: add isFreeThreaded to the interpreter's passthru A package that builds differently on free-threaded Python has no attribute to ask. It must parse libPrefix or executable for the "t" ABI flag. Expose the interpreter's own setting: true when CPython is built with enableGIL = false, and false for every other interpreter. The package set passes it on as an argument, like pythonAtLeast. passthru is not part of the derivation, so nothing rebuilds. Assisted-by: Claude Code (Claude Opus 5.5) --- doc/languages-frameworks/python.section.md | 1 + pkgs/development/interpreters/python/cpython/default.nix | 1 + pkgs/development/interpreters/python/passthrufun.nix | 2 ++ pkgs/development/interpreters/python/python-packages-base.nix | 1 + 4 files changed, 5 insertions(+) diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index 4a8db80289fa..2fecf6ffa9c7 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -27,6 +27,7 @@ Each interpreter has the following attributes: - `withPackages`. Simpler interface to `buildEnv`. See [](#python.withpackages-function) for usage and documentation. - `sitePackages`. Alias for `lib/${libPrefix}/site-packages`. - `executable`. Name of the interpreter executable, e.g. `python3.10`. +- `isFreeThreaded`. Whether the interpreter is a free-threaded build (`enableGIL = false`), e.g. `python314FreeThreading`. - `pkgs`. Set of Python packages for that specific interpreter. The package set can be modified by overriding the interpreter and passing `packageOverrides`. ### Building packages and applications {#building-packages-and-applications} diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 81d7d51857f3..a2ac8e7626a1 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -217,6 +217,7 @@ let executable = "python${pythonVersion}${abiFlags}"; sitePackages = "lib/${libPrefix}/site-packages"; inherit hasDistutilsCxxPatch pythonAttr; + isFreeThreaded = !enableGIL; inherit (splices) pythonOnBuildForBuild pythonOnBuildForHost diff --git a/pkgs/development/interpreters/python/passthrufun.nix b/pkgs/development/interpreters/python/passthrufun.nix index 005ba62ba742..70aafed11466 100644 --- a/pkgs/development/interpreters/python/passthrufun.nix +++ b/pkgs/development/interpreters/python/passthrufun.nix @@ -24,6 +24,7 @@ pythonOnTargetForTarget, pythonAttr ? null, pythonABITags ? [ "none" ], + isFreeThreaded ? false, self, # is pythonOnHostForTarget }: let @@ -127,6 +128,7 @@ rec { inherit executable implementation + isFreeThreaded libPrefix pythonVersion sitePackages diff --git a/pkgs/development/interpreters/python/python-packages-base.nix b/pkgs/development/interpreters/python/python-packages-base.nix index ad335a1c0ac8..623f1cf876e4 100644 --- a/pkgs/development/interpreters/python/python-packages-base.nix +++ b/pkgs/development/interpreters/python/python-packages-base.nix @@ -203,6 +203,7 @@ in { inherit lib pkgs stdenv; inherit (python.passthru) + isFreeThreaded isPy311 isPy312 isPy313