Hi everyone,
I’m running into an issue when building a custom LaTeX environment using Nix flakes. My setup combines the full TeX Live distribution (texliveFull
) with an external LaTeX class (lipics
). The build fails with a “Permission denied” error related to creating a symlink in the Nix store.
Error Message
Here’s the error message I receive during the build process (hashes removed):
texlive: generating format symlinks
ln: failed to create symbolic link '/nix/store/...-texlive-2023-env/share/texmf/...-texlive-2023-env-texmfdist': Permission denied
error: builder for '/nix/store/...-texlive-env.drv' failed with exit code 1;
Here is the full log.
Flake Configuration
Below is a minimal reproduction flake.nix
. This, and other required files, are available on GitHub.
{
description = "A Nix flake to build a LaTeX document using TeX Live and TikZ";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
};
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
lipicsPkg = pkgs.stdenv.mkDerivation {
name = "lipics";
pname = "lipics";
src = ./lipics;
outputs = [ "out" "tex" ];
installPhase = ''
mkdir -p $out/share/texmf/tex/latex/lipics/
mkdir -p $tex/tex/latex/lipics/
cp *.cls $out/share/texmf/tex/latex/lipics/
cp *.cls $tex/tex/latex/lipics/
'';
};
texliveBundle = pkgs.texliveFull.withPackages (ps: [
ps.latexmk
lipicsPkg
]);
in
{
packages.${system}.default = pkgs.stdenv.mkDerivation {
name = "build-paper";
src = ./.;
nativeBuildInputs = [
texliveBundle
];
buildPhase = ''
export XDG_CACHE_HOME=$(mktemp -d)
latexmk -pdf --shell-escape paper.tex
'';
installPhase = ''
mkdir -p $out
cp paper.pdf $out/
'';
};
};
}
This flake does the following:
- Defines a custom derivation (
lipicsPkg
) for the external LaTeX classlipics
, which includeslipics-v2021.cls
. - Combines this package with
texliveFull
usingwithPackages
. - Builds a minimal LaTeX document (
paper.tex
) that uses thelipics
class.
The only files other than the flake that are needed are:
lipics/lipics-v2021.cls
: The custom LaTeX class.paper.tex
: A minimal LaTeX document that incrrentcludes thelipics
class.
Observations
- The error occurs during the symlink creation phase of the TeX Live environment setup.
- If I remove the external package (
lipicsPkg
), the build succeeds without issues. - If I change the TeX Live bundle constructor to
texlive.combine
then - Based on my understanding, TeX Live tries to generate symlinks dynamically during its configuration phase, which seems to conflict with Nix’s immutability constraints.
- This appears to be related to GitHub issue 10375, however this is marked as fixed, so I shouldn’t be seeing this in my current version.
Questions
- What is causing this symlink permission error when adding an external package to the TeX Live environment?
- Is it intended to create this symlink or is the symlink being created by an error in my flake.
- Is there a way to configure TeX Live or Nix to avoid writing symlinks directly into the Nix store?
- Are there alternative approaches for including external LaTeX packages in a TeX Live environment built with flakes?
Any help or insights would be greatly appreciated!