1{
2 lib,
3 writeScript,
4 fetchFromGitHub,
5 replaceVars,
6 inkscape,
7 pdflatex,
8 lualatex,
9 python3,
10 wrapGAppsHook3,
11 gobject-introspection,
12 gtk3,
13 gtksourceview3,
14}:
15
16let
17 launchScript = writeScript "launch.sh" ''
18 cd $(dirname $0)
19 ./__main__.py $*
20 '';
21in
22python3.pkgs.buildPythonApplication rec {
23 pname = "textext";
24 version = "1.12.0";
25 format = "setuptools";
26
27 src = fetchFromGitHub {
28 owner = "textext";
29 repo = "textext";
30 tag = version;
31 sha256 = "sha256-Ka8NIvzhMZYPlc3q0U5Je7eXyBT61dJ3O++ETl+D7w0=";
32 };
33
34 patches = [
35 # Make sure we can point directly to pdflatex in the extension,
36 # instead of relying on the PATH (which might not have it)
37 (replaceVars ./fix-paths.patch {
38 inherit pdflatex lualatex;
39 })
40
41 # Since we are wrapping the extension, we need to change the interpreter
42 # from Python to Bash.
43 ./interpreter.patch
44 ];
45
46 nativeBuildInputs = [
47 wrapGAppsHook3
48 gobject-introspection
49 ];
50
51 buildInputs = [
52 gtk3
53 gtksourceview3
54 ];
55
56 propagatedBuildInputs = [
57 python3.pkgs.pygobject3
58 # lxml, cssselect and numpy are required by inkex but is not inherited from inkscape when we use custom Python interpreter:
59 python3.pkgs.lxml
60 python3.pkgs.cssselect
61 python3.pkgs.numpy
62 python3.pkgs.tinycss2
63 ];
64
65 # strictDeps do not play nicely with introspection setup hooks.
66 # https://github.com/NixOS/nixpkgs/issues/56943
67 strictDeps = false;
68
69 # TexText doesn’t have a 'bdist_wheel' target.
70 dontUseSetuptoolsBuild = true;
71
72 # TexText doesn’t have a 'test' target.
73 doCheck = false;
74
75 # Avoid wrapping two times by just using Python’s wrapping.
76 dontWrapGApps = true;
77
78 buildPhase = ''
79 runHook preBuild
80
81 mkdir dist
82
83 # source/setup.py creates a config file in HOME (that we ignore)
84 mkdir buildhome
85 export HOME=$(pwd)/buildhome
86
87 python setup.py \
88 --inkscape-executable=${inkscape}/bin/inkscape \
89 --pdflatex-executable=${pdflatex}/bin/pdflatex \
90 --lualatex-executable=${lualatex}/bin/lualatex \
91 --inkscape-extensions-path=dist
92
93 runHook postBuild
94 '';
95
96 installPhase = ''
97 runHook preInstall
98
99 mkdir -p $out/share/inkscape/extensions
100 cp -r dist/textext $out/share/inkscape/extensions
101
102 runHook postInstall
103 '';
104
105 preFixup = ''
106 # Prepare for wrapping
107 chmod +x "$out/share/inkscape/extensions/textext/__main__.py"
108 sed -i '1i#!/usr/bin/env python3' "$out/share/inkscape/extensions/textext/__main__.py"
109
110 # Include gobject-introspection typelibs in the wrapper.
111 makeWrapperArgs+=("''${gappsWrapperArgs[@]}")
112 '';
113
114 postFixup = ''
115 # Wrap the project so it can find runtime dependencies.
116 wrapPythonProgramsIn "$out/share/inkscape/extensions/textext" "$out $pythonPath"
117 cp ${launchScript} $out/share/inkscape/extensions/textext/launch.sh
118 '';
119
120 meta = with lib; {
121 description = "Re-editable LaTeX graphics for Inkscape";
122 homepage = "https://textext.github.io/textext/";
123 license = licenses.bsd3;
124 maintainers = [ maintainers.raboof ];
125 platforms = platforms.all;
126 };
127}