texlive.withPackages: allow tlDeps to be a function, drop unused requiredTeXPackages

This commit is contained in:
Vincenzo Mantova
2026-05-23 13:17:17 +01:00
parent c8b6540469
commit 3a6bafbdf5
4 changed files with 37 additions and 15 deletions

View File

@@ -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 = ''

View File

@@ -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

View File

@@ -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);

View File

@@ -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
;
};