Files
CM Geldenhuys d37982385b textext: fix GUI library (GTK3) detection
TexText probes for a GUI toolkit by spawning a subprocess (roughly
`import gi; gi.require_version('Gtk', '3.0'); from gi.repository import Gtk`)
instead of importing in-process. The Python wrapper makes runtime dependencies
importable via a site.addsitedir preamble and deliberately does not export
PYTHONPATH, so the spawned probe interpreter cannot import gi. TexText then
reports "Neither GTK nor TkInter has been found" and refuses to launch.

Export PYTHONPATH on the wrapper so the probe subprocess inherits the runtime
dependencies too.

Resolves #384042
2026-07-21 20:45:04 +02:00

142 lines
3.8 KiB
Nix
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
lib,
writeScript,
fetchFromGitHub,
replaceVars,
inkscape,
pdflatex,
lualatex,
python3,
wrapGAppsHook3,
gobject-introspection,
gtk3,
gtksourceview3,
}:
let
launchScript = writeScript "launch.sh" ''
cd $(dirname $0)
./__main__.py $*
'';
in
python3.pkgs.buildPythonApplication (finalAttrs: {
pname = "textext";
version = "1.13.0";
format = "setuptools";
src = fetchFromGitHub {
owner = "textext";
repo = "textext";
tag = finalAttrs.version;
sha256 = "sha256-fEPSpI9uO+r3d5p+gV1XcorYvUPw0sLgG9nHUPeTtYs=";
};
patches = [
# Make sure we can point directly to pdflatex in the extension,
# instead of relying on the PATH (which might not have it)
(replaceVars ./fix-paths.patch {
inherit pdflatex lualatex;
})
# Since we are wrapping the extension, we need to change the interpreter
# from Python to Bash.
./interpreter.patch
];
nativeBuildInputs = [
wrapGAppsHook3
gobject-introspection
];
buildInputs = [
gtk3
gtksourceview3
];
propagatedBuildInputs = [
python3.pkgs.pygobject3
# lxml, cssselect and numpy are required by inkex but is not inherited from inkscape when we use custom Python interpreter:
python3.pkgs.lxml
python3.pkgs.cssselect
python3.pkgs.numpy
python3.pkgs.tinycss2
];
# strictDeps do not play nicely with introspection setup hooks.
# https://github.com/NixOS/nixpkgs/issues/56943
strictDeps = false;
# TexText doesnt have a 'bdist_wheel' target.
dontUseSetuptoolsBuild = true;
# TexText doesnt have a 'test' target.
doCheck = false;
# Avoid wrapping two times by just using Pythons wrapping.
dontWrapGApps = true;
buildPhase = ''
runHook preBuild
mkdir dist
# source/setup.py creates a config file in HOME (that we ignore)
mkdir buildhome
export HOME=$(pwd)/buildhome
python setup.py \
--inkscape-executable=${inkscape}/bin/inkscape \
--pdflatex-executable=${pdflatex}/bin/pdflatex \
--lualatex-executable=${lualatex}/bin/lualatex \
--inkscape-extensions-path=dist
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/share/inkscape/extensions
cp -r dist/textext $out/share/inkscape/extensions
runHook postInstall
'';
preFixup = ''
# Prepare for wrapping
chmod +x "$out/share/inkscape/extensions/textext/__main__.py"
sed -i '1i#!/usr/bin/env python3' "$out/share/inkscape/extensions/textext/__main__.py"
# Include gobject-introspection typelibs in the wrapper.
makeWrapperArgs+=("''${gappsWrapperArgs[@]}")
# TexText probes for a GUI toolkit by spawning a subprocess
# (`sys.executable -c "import gi; gi.require_version('Gtk', '3.0'); ..."`)
# instead of importing in-process. The Python wrapper makes runtime
# dependencies importable via a site.addsitedir preamble and deliberately
# does not export PYTHONPATH, so the spawned probe interpreter cannot import
# gi and TexText aborts with "Neither GTK nor TkInter has been found".
# Export PYTHONPATH so the probe subprocess inherits the dependencies too.
# See https://github.com/NixOS/nixpkgs/issues/384042
makeWrapperArgs+=(--prefix PYTHONPATH : "${
lib.makeSearchPath python3.sitePackages (
finalAttrs.propagatedBuildInputs ++ [ python3.pkgs.pycairo ]
)
}")
'';
postFixup = ''
# Wrap the project so it can find runtime dependencies.
wrapPythonProgramsIn "$out/share/inkscape/extensions/textext" "$out ''${pythonPath[*]}"
cp ${launchScript} $out/share/inkscape/extensions/textext/launch.sh
'';
meta = {
description = "Re-editable LaTeX graphics for Inkscape";
homepage = "https://textext.github.io/textext/";
license = lib.licenses.bsd3;
maintainers = [ lib.maintainers.raboof ];
platforms = lib.platforms.all;
};
})