You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am encountering an issue when using MakieTeX.jl on NixOS. The library fails to run Ghostscript to crop PDFs due to the specific way NixOS handles dynamically linked executables. Despite attempts to set the correct Ghostscript path, the library seems to continue using the bundled Ghostscript_jll instead of the custom path.
Steps to Reproduce:
Install MakieTeX.jl and its dependencies on NixOS. For instance here is my current flake.nix file:
{description="Julia environment";inputs={nixpkgs.url="github:nixos/nixpkgs/nixpkgs-unstable";flake-utils.url=github:numtide/flake-utils;};outputs={self,nixpkgs,flake-utils, ... }:
flake-utils.lib.eachDefaultSystem(system:
let# Override the Nix package set to allow unfree packagespkgs=importnixpkgs{system=system;config.allowUnfree=true;};# julia = pkgs.julia.withPackages [# "LanguageServer"# [...]# ];# WARN: Above doesn't support all packages, so rely on Julia package manager instead.# Use Julia in REPL mode, then package mode and install packages that way.julia=pkgs.julia-bin.overrideDerivation(oldAttrs: {doInstallCheck=false;});in{# development environmentdevShells.default=pkgs.mkShell{packages=[julia#wrappedGhostscriptpkgs.ghostscript# OpenGL dependenciespkgs.libGLpkgs.libglvndpkgs.glfwpkgs.mesapkgs.mesa.drivers# Font renderingpkgs.fontconfigpkgs.freetype# LaTeXpkgs.texlive.combined.scheme-fullpkgs.biberpkgs.gnumake# C/C++ developmentpkgs.gccpkgs.gnumakepkgs.gdbpkgs.valgrindpkgs.gurobi# Gurobi solver. Requires a license. Add it using command `grbgetkey <YOUR_LICENSE_KEY>`# Javapkgs.jdk23];shellHook='' export JULIA_NUM_THREADS="auto" export JULIA_PROJECT="turing" export LD_LIBRARY_PATH=${pkgs.gurobi}/lib:$LD_LIBRARY_PATH export GUROBI_HOME=${pkgs.gurobi} export GUROBI_VERSION=$(basename $(ls -d ${pkgs.gurobi}) | sed 's/.*-\([0-9]\+\)\.\([0-9]\+\).*/\1\2/') export LD_LIBRARY_PATH="/run/opengl-driver/lib:/run/opengl-driver-32/lib:$LD_LIBRARY_PATH" export GHOSTSCRIPT_PATH="${pkgs.ghostscript}/bin/gs" echo "Nix Shell environment is ready." echo "${pkgs.libGL}" '';};});}
Run the example script provided in the MakieTeX documentation:
using Makie, MakieTeX, CairoMakie
fig =Figure()
l1 =LTeX(
fig[1, 1], L"A \emph{convex} function $f \in C$ is \textcolor{blue}{denoted} as \tikz{\draw[line width=1pt, >->] (0, -2pt) arc (-180:0:8pt);}";
tellwidth =false, tellheight =true
)
ax1 =Axis(fig[2, 1])
heatmap!(ax1, Makie.peaks())
display(fig)
Observe the error when the script tries to crop the PDF using Ghostscript:
Ghostscript failed to get the bounding box of temp.pdf!
Files in temp directory are:
temp.aux,temp.fdb_latexmk,temp.fls,temp.log,temp.pdf,temp.tex
Stdout
Stderr
Could not start dynamically linked executable: /home/onyr/.julia/artifacts/4883a6685d86b068da934537a444a6d170d71730/bin/gs
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld
The culprit can be seen here where the code uses dynamically linked executable.
What I Have Tried:
Setting a Custom Ghostscript Path:
I added the NixOS Ghostscript binary to the PATH and set it explicitly in the environment:
using MakieTeX
MakieTeX.Ghostscript_jll.gs() =ENV["GHOSTSCRIPT_PATH"]
However, the library still uses the bundled Ghostscript_jll.
Verifying Ghostscript on NixOS:
Ran which gs to confirm the path:
❮onyr ★ nixos❯ ❮julia❯❯ which gs
/nix/store/dasn4h9r40sp4rrvf7vp2aqnzzxba73s-ghostscript-with-X-10.04.0/bin/gs
Tested the binary:
/nix/store/<path-to-ghostscript>/bin/gs -h
The binary works as expected.
Exploring Source Code:
Examined the get_pdf_bbox function in MakieTeX:
Ghostscript_jll.gs()
It seems to directly rely on the bundled Ghostscript_jll, which is incompatible with NixOS.
Environment:
Operating System: NixOS
Julia Version: 1.11.2 (2024-12-01)
MakieTeX.jl Version: v0.4.3
Expected Behavior:
The library should respect the custom Ghostscript path set via ENV["GHOSTSCRIPT_PATH"] or allow an explicit override for the Ghostscript executable, or even just check that the command gs is available on the current shell.
Suggested Fix:
Provide an option to completely bypass the bundled Ghostscript_jll and use a system-installed Ghostscript binary.
Allow users to configure the Ghostscript path in a straightforward manner, either through an environment variable or a function call.
Additional Context:
NixOS is a declarative Linux distribution where binaries are isolated, and dynamically linked executables intended for generic Linux environments may fail without additional configuration. The bundled Ghostscript_jll executable does not work on NixOS due to this reason.
So I created a PR to fix the issue. Now just including pkgs.ghostscript in your flake.nix and boom, it works !
However I'm fairly disappointed with the rendering. I get very pixelated results and no TikZ supports. It's strange since I have latexmk and lualatex available in my dev shell:
❮onyr ★ nixos❯ ❮julia❯❯ latexmk -v
Latexmk, John Collins, 7 Apr. 2024. Version 4.85
❮onyr ★ nixos❯ ❮julia❯❯ lualatex -v
This is LuaHBTeX, Version 1.18.0 (TeX Live 2024/nixos.org)
Development id: 7611
Execute 'luahbtex --credits' for credits and version details.
There is NO warranty. Redistribution of this software is covered by
the terms of the GNU General Public License, version 2 or (at your option)
any later version. For more information about these matters, see the file
named COPYING and the LuaTeX source.
LuaTeX is Copyright 2022 Taco Hoekwater and the LuaTeX Team.
On the examples in the README, I get:
using Makie
include("../src/MakieTeX.jl")
using.MakieTeX
using CairoMakie # or whichever other backend
fig =Figure()
l1 =LTeX(
fig[1, 1], L"A \emph{convex} function $f \in C$ is \textcolor{blue}{denoted} as \tikz{\draw[line width=1pt, >->] (0, -2pt) arc (-180:0:8pt);}";
tellwidth =false, tellheight =true
)
ax1 =Axis(
fig[2, 1];
)
heatmap!(ax1, Makie.peaks())
# Save the figure to a file in the current directorysave("output_image.png", fig)
display(fig)
And:
using Makie
include("../src/MakieTeX.jl")
using.MakieTeX
using CairoMakie # or whichever other backend
fig =Figure(size = (400, 300));
tex1 =LTeX(
fig[1, 1],
L"\int \mathbf E \cdot d\mathbf a = \frac{Q_{encl}}{4\pi\epsilon_0}",
scale=1,
);
tex2 =LTeX(
fig[2, 1],
L"\int \mathbf E \cdot d\mathbf a = \frac{Q_{encl}}{4\pi\epsilon_0}",
scale=2,
render_density =5
);
# Save the figure to a file in the current directorysave("output_image2.png", fig)
Description:
I am encountering an issue when using
MakieTeX.jl
on NixOS. The library fails to runGhostscript
to crop PDFs due to the specific way NixOS handles dynamically linked executables. Despite attempts to set the correctGhostscript
path, the library seems to continue using the bundledGhostscript_jll
instead of the custom path.Steps to Reproduce:
MakieTeX.jl
and its dependencies on NixOS. For instance here is my currentflake.nix
file:MakieTeX
documentation:Ghostscript
:Error Message:
The following error is raised during execution:
The culprit can be seen here where the code uses dynamically linked executable.
What I Have Tried:
Setting a Custom Ghostscript Path:
PATH
and set it explicitly in the environment:Ghostscript_jll
.Verifying Ghostscript on NixOS:
which gs
to confirm the path:Exploring Source Code:
get_pdf_bbox
function inMakieTeX
:Ghostscript_jll
, which is incompatible with NixOS.Environment:
1.11.2 (2024-12-01)
v0.4.3
Expected Behavior:
The library should respect the custom Ghostscript path set via
ENV["GHOSTSCRIPT_PATH"]
or allow an explicit override for the Ghostscript executable, or even just check that the commandgs
is available on the current shell.Suggested Fix:
Ghostscript_jll
and use a system-installed Ghostscript binary.Additional Context:
NixOS is a declarative Linux distribution where binaries are isolated, and dynamically linked executables intended for generic Linux environments may fail without additional configuration. The bundled
Ghostscript_jll
executable does not work on NixOS due to this reason.Relevant link: https://nix.dev/permalink/stub-ld
Any help or advice appreciated.
The text was updated successfully, but these errors were encountered: