From 3a6bafbdf59140a330bc0836bcaafaae0afe3272 Mon Sep 17 00:00:00 2001 From: Vincenzo Mantova <1962985+xworld21@users.noreply.github.com> Date: Sat, 23 May 2026 13:17:17 +0100 Subject: [PATCH] texlive.withPackages: allow tlDeps to be a function, drop unused requiredTeXPackages --- doc/languages-frameworks/texlive.section.md | 13 +++++----- .../typesetting/tex/texlive/build-tex-env.nix | 6 ++++- .../tex/texlive/combine-wrapper.nix | 7 ++++- .../tools/typesetting/tex/texlive/default.nix | 26 ++++++++++++++----- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/doc/languages-frameworks/texlive.section.md b/doc/languages-frameworks/texlive.section.md index 9822cfca0347..4a378fee2d9b 100644 --- a/doc/languages-frameworks/texlive.section.md +++ b/doc/languages-frameworks/texlive.section.md @@ -110,7 +110,7 @@ Release 23.11 ships with a new interface that will eventually replace `texlive.c ## Custom packages {#sec-language-texlive-custom-packages} -You may find that you need to use an external TeX package. A derivation for such package has to provide the contents of the "texmf" directory in its `"tex"` output, according to the [TeX Directory Structure](https://tug.ctan.org/tds/tds.html). Dependencies on other TeX packages can be listed in the attribute `tlDeps`. +You may find that you need to use an external TeX package. A derivation for such package has to provide the contents of the "texmf" directory in its `"tex"` output, according to the [TeX Directory Structure](https://tug.ctan.org/tds/tds.html). Dependencies on other TeX packages can be listed in the attribute `passthru.tlDeps`, which is a function taking a package set and returning a list of packages. The functions `texlive.combine` and `texlive.withPackages` recognise the following outputs: @@ -136,7 +136,7 @@ let "tex" "texdoc" ]; - passthru.tlDeps = with texlive; [ latex ]; + passthru.tlDeps = ps: [ ps.latex ]; srcs = [ (fetchurl { @@ -167,13 +167,14 @@ let latexmk ] )) - # multiple-outputs.sh fails if $out is not defined - (writeShellScript "force-tex-output.sh" '' - out="''${tex-}" - '') writableTmpDirAsHomeHook # Need a writable $HOME for latexmk ]; + # multiple-outputs.sh fails if $out is not defined + preHook = '' + out="''${tex-}" + ''; + dontConfigure = true; buildPhase = '' diff --git a/pkgs/tools/typesetting/tex/texlive/build-tex-env.nix b/pkgs/tools/typesetting/tex/texlive/build-tex-env.nix index 17d31e0303e7..01ae7e52c427 100644 --- a/pkgs/tools/typesetting/tex/texlive/build-tex-env.nix +++ b/pkgs/tools/typesetting/tex/texlive/build-tex-env.nix @@ -70,7 +70,11 @@ lib.fix ( p.pname or p.name + lib.optionalString (p.outputSpecified or false) ("-" + p.tlOutputName or p.outputName or ""); inherit p; - tlDeps = if p ? tlDeps then ensurePkgSets p.tlDeps else (p.requiredTeXPackages or (_: [ ]) tl); + tlDeps = + if p ? tlDeps then + (if builtins.isFunction p.tlDeps then p.tlDeps tl else ensurePkgSets p.tlDeps) + else + [ ]; }; in # texlive.combine: the wrapper already resolves all dependencies diff --git a/pkgs/tools/typesetting/tex/texlive/combine-wrapper.nix b/pkgs/tools/typesetting/tex/texlive/combine-wrapper.nix index e7bd78ff720a..e0ed2bc8f1fa 100644 --- a/pkgs/tools/typesetting/tex/texlive/combine-wrapper.nix +++ b/pkgs/tools/typesetting/tex/texlive/combine-wrapper.nix @@ -2,6 +2,7 @@ { lib, toTLPkgList, + tl, buildTeXEnv, }: args@{ @@ -45,7 +46,11 @@ let in builtins.genericClosure { startSet = pkgListToSets pkgList; - operator = { pkg, ... }: pkgListToSets (pkg.tlDeps or [ ]); + operator = + { pkg, ... }: + pkgListToSets ( + if pkg ? tlDeps then if builtins.isFunction pkg.tlDeps then pkg.tlDeps tl else pkg.tlDeps else [ ] + ); } ); combined = combinePkgs (lib.attrValues pkgSet); diff --git a/pkgs/tools/typesetting/tex/texlive/default.nix b/pkgs/tools/typesetting/tex/texlive/default.nix index 5f486f608e2a..c819f4b32112 100644 --- a/pkgs/tools/typesetting/tex/texlive/default.nix +++ b/pkgs/tools/typesetting/tex/texlive/default.nix @@ -257,19 +257,31 @@ let # respecting specified outputs toTLPkgList = drv: + let + drvWithoutDeps = removeAttrs drv [ "tlDeps" ]; + drvWithDeps = + if (drv ? tlDeps) then + drv // { tlDeps = if builtins.isFunction drv.tlDeps then drv.tlDeps tl else drv.tlDeps; } + else + drv; + in if drv.outputSpecified or false then let tlType = drv.tlType or tlOutToType.${drv.tlOutputName or drv.outputName} or null; in - lib.optional (tlType != null) (drv // { inherit tlType; }) + lib.optional (tlType != null) (drvWithDeps // { inherit tlType; }) else - [ (drv.tex // { tlType = "run"; }) ] + lib.optional (drv ? tex) (drvWithDeps.tex // { tlType = "run"; }) ++ lib.optional (drv ? texdoc) ( - drv.texdoc // { tlType = "doc"; } // lib.optionalAttrs (drv ? man) { hasManpages = true; } + drvWithoutDeps.texdoc + // { + tlType = "doc"; + } + // lib.optionalAttrs (drv ? man) { hasManpages = true; } ) - ++ lib.optional (drv ? texsource) (drv.texsource // { tlType = "source"; }) - ++ lib.optional (drv ? tlpkg) (drv.tlpkg // { tlType = "tlpkg"; }) - ++ lib.optional (drv ? out) (drv.out // { tlType = "bin"; }); + ++ lib.optional (drv ? texsource) (drvWithoutDeps.texsource // { tlType = "source"; }) + ++ lib.optional (drv ? tlpkg) (drvWithDeps.tlpkg // { tlType = "tlpkg"; }) + ++ lib.optional (drv ? out) (drvWithDeps.out // { tlType = "bin"; }); tlOutToType = { out = "bin"; tex = "run"; @@ -312,8 +324,8 @@ let inherit buildTeXEnv lib + tl toTLPkgList - toTLPkgSets ; };