From 2c18352f1e7ec35480ab07b7e5b58e1326b522f2 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Tue, 4 May 2021 18:14:11 +0200 Subject: [PATCH] inkscape-extensions.textext: init at 1.8.1 Introduce the 'textext' extension for including LaTeX graphics in Inkscape Test it with `nix-shell -p "inkscape-with-extensions.override { inkscapeExtensions = [ inkscape-extensions.textext ]; }" --run inkscape` Co-Authored-By: Jan Tojnar --- .../graphics/inkscape/extensions.nix | 5 + .../inkscape/extensions/textext/default.nix | 125 ++++++++++++++++++ .../extensions/textext/fix-paths.patch | 19 +++ .../extensions/textext/interpreter.patch | 10 ++ 4 files changed, 159 insertions(+) create mode 100644 pkgs/applications/graphics/inkscape/extensions/textext/default.nix create mode 100644 pkgs/applications/graphics/inkscape/extensions/textext/fix-paths.patch create mode 100644 pkgs/applications/graphics/inkscape/extensions/textext/interpreter.patch diff --git a/pkgs/applications/graphics/inkscape/extensions.nix b/pkgs/applications/graphics/inkscape/extensions.nix index 08260c968cfb..17dca7d5f387 100644 --- a/pkgs/applications/graphics/inkscape/extensions.nix +++ b/pkgs/applications/graphics/inkscape/extensions.nix @@ -3,6 +3,7 @@ , runCommand , inkcut , callPackage +, texlive }: { @@ -43,4 +44,8 @@ mkdir -p $out/share/inkscape/extensions cp ${inkcut}/share/inkscape/extensions/* $out/share/inkscape/extensions ''); + textext = callPackage ./extensions/textext { + pdflatex = texlive.combined.scheme-basic; + lualatex = texlive.combined.scheme-basic; + }; } diff --git a/pkgs/applications/graphics/inkscape/extensions/textext/default.nix b/pkgs/applications/graphics/inkscape/extensions/textext/default.nix new file mode 100644 index 000000000000..c049458808a5 --- /dev/null +++ b/pkgs/applications/graphics/inkscape/extensions/textext/default.nix @@ -0,0 +1,125 @@ +{ lib +, writeScript +, fetchFromGitHub +, substituteAll +, inkscape +, pdflatex +, lualatex +, python3 +, wrapGAppsHook +, gobject-introspection +, gtk3 +, gtksourceview3 +}: + +let + launchScript = writeScript "launch.sh" '' + cd $(dirname $0) + ./__main__.py $* + ''; +in +python3.pkgs.buildPythonApplication rec { + pname = "textext"; + version = "1.8.1"; + + src = fetchFromGitHub { + owner = "textext"; + repo = "textext"; + rev = version; + sha256 = "sha256-Qzd39X0X3DdwZ3pIIGvEbNjl6dxjDf3idzjwCkp3WRg="; + }; + + patches = [ + # Make sure we can point directly to pdflatex in the extension, + # instead of relying on the PATH (which might not have it) + (substituteAll { + src = ./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 = [ + wrapGAppsHook + 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 + ]; + + # strictDeps do not play nicely with introspection setup hooks. + # https://github.com/NixOS/nixpkgs/issues/56943 + strictDeps = false; + + # TexText doesn’t have a 'bdist_wheel' target. + dontUseSetuptoolsBuild = true; + + # TexText doesn’t have a 'test' target. + doCheck = false; + + # Avoid wrapping two times by just using Python’s 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[@]}") + ''; + + 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 = with lib; { + description = "Re-editable LaTeX graphics for Inkscape"; + homepage = "https://textext.github.io/textext/"; + license = licenses.bsd3; + maintainers = [ maintainers.raboof ]; + platforms = platforms.all; + }; +} diff --git a/pkgs/applications/graphics/inkscape/extensions/textext/fix-paths.patch b/pkgs/applications/graphics/inkscape/extensions/textext/fix-paths.patch new file mode 100644 index 000000000000..8c9d9a22e1b8 --- /dev/null +++ b/pkgs/applications/graphics/inkscape/extensions/textext/fix-paths.patch @@ -0,0 +1,19 @@ +--- a/textext/base.py ++++ b/textext/base.py +@@ -95,7 +95,16 @@ class TexText(inkex.EffectExtension): + def __init__(self): + + self.config = Settings(directory=defaults.textext_config_path) ++ # config.json is stored in ~/.config/inkscape/extensions/textext for ++ # the next invocation, but since that next invocation could be using ++ # a different latex derivation, make sure we overwrite the executable ++ # paths with updated ones: ++ self.config["pdflatex-executable"] = "@pdflatex@/bin/pdflatex"; ++ self.config["lualatex-executable"] = "@lualatex@/bin/lualatex"; + self.cache = Cache(directory=defaults.textext_config_path) ++ if "requirements_checker" in self.cache.values: ++ self.cache["requirements_checker"]["available_tex_to_pdf_converters"]["pdflatex"] = "@pdflatex@/bin/pdflatex"; ++ self.cache["requirements_checker"]["available_tex_to_pdf_converters"]["lualatex"] = "@lualatex@/bin/lualatex"; + previous_exit_code = self.cache.get("previous_exit_code", None) + + if previous_exit_code is None: diff --git a/pkgs/applications/graphics/inkscape/extensions/textext/interpreter.patch b/pkgs/applications/graphics/inkscape/extensions/textext/interpreter.patch new file mode 100644 index 000000000000..c7e9f7ce0394 --- /dev/null +++ b/pkgs/applications/graphics/inkscape/extensions/textext/interpreter.patch @@ -0,0 +1,10 @@ +--- a/textext/textext.inx ++++ b/textext/textext.inx +@@ -8,6 +8,6 @@ + + + +