Skip to content

Commit

Permalink
Merge pull request #119362 from xworld21/texlive-combine-fix-buildenv
Browse files Browse the repository at this point in the history
texlive.combine: split static $TEXMFDIST into a separate derivation
  • Loading branch information
veprbl authored Mar 17, 2023
2 parents 3ea2520 + 40a8b1a commit f6e0676
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 60 deletions.
6 changes: 3 additions & 3 deletions pkgs/test/texlive/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@
for fname in language.{dat,def,dat.lua} ; do
diff --ignore-matching-lines='^\(%\|--\) Generated by ' -u \
{"$hyphenBase","$schemeFull"/share/texmf}/tex/generic/config/"$fname" \
{"$hyphenBase","$schemeFull"/share/texmf-var}/tex/generic/config/"$fname" \
| tee "$out/scheme-full/$fname.patch"
diff --ignore-matching-lines='^\(%\|--\) Generated by ' -u \
{,"$schemeInfraOnly"/share/texmf/tex/generic/config/}"$fname" \
{,"$schemeInfraOnly"/share/texmf-var/tex/generic/config/}"$fname" \
| tee "$out/scheme-infraonly/$fname.patch"
done
'';
Expand All @@ -190,7 +190,7 @@
mkdir -p "$out"
diff --ignore-matching-lines='^# Generated by ' -u \
{"$kpathsea","$schemeFull"/share/texmf}/web2c/fmtutil.cnf \
{"$kpathsea","$schemeFull"/share/texmf-var}/web2c/fmtutil.cnf \
| tee "$out/fmtutil.cnf.patch"
'';
}
131 changes: 74 additions & 57 deletions pkgs/tools/typesetting/tex/texlive/combine.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,44 @@ let
mkUniqueOutPaths = pkgs: lib.unique
(map (p: p.outPath) (builtins.filter lib.isDerivation pkgs));

in (buildEnv {
name = "texlive-${extraName}-${bin.texliveYear}${extraVersion}";

extraPrefix = "/share/texmf";
texmf = (buildEnv {
name = "${name}-texmf";

paths = pkgList.nonbin;

nativeBuildInputs = [ perl bin.core.out ];

postBuild = # generate ls-R database
''
perl -I "${bin.core.out}/share/texmf-dist/scripts/texlive" \
-- "$out/scripts/texlive/mktexlsr.pl" --sort "$out"
'';
}).overrideAttrs (_: { allowSubstitutes = true; });

# expose info and man pages in usual /share/{info,man} location
doc = buildEnv {
name = "${name}-doc";

paths = [ (texmf.outPath + "/doc") ];
extraPrefix = "/share";

pathsToLink = [
"/info"
"/man"
];
};

in (buildEnv {

inherit name;

ignoreCollisions = false;
paths = pkgList.nonbin;
paths = pkgList.bin ++ [ doc ];
pathsToLink = [
"/"
"/tex/generic/config" # make it a real directory for scheme-infraonly
"/bin" # ensure these are writeable directories
];

nativeBuildInputs = [ makeWrapper libfaketime perl bin.texlinks ];
Expand All @@ -57,54 +85,40 @@ in (buildEnv {
passthru.packages = pkgList.all;

postBuild = ''
mkdir -p "$out"/bin
'' +
lib.concatMapStrings
(path: ''
for f in '${path}'/bin/*; do
if [[ -L "$f" ]]; then
cp -d "$f" "$out"/bin/
else
ln -s "$f" "$out"/bin/
fi
done
'')
pkgList.bin
+
''
export PATH="$out/bin:$out/share/texmf/scripts/texlive:$PATH"
export TEXMFCNF="$out/share/texmf/web2c"
TEXMFDIST="${texmf}"
export PATH="$out/bin:$PATH"
export PERL5LIB="$TEXMFDIST/scripts/texlive:${bin.core.out}/share/texmf-dist/scripts/texlive"
TEXMFSYSCONFIG="$out/share/texmf-config"
TEXMFSYSVAR="$out/share/texmf-var"
export PERL5LIB="$out/share/texmf/scripts/texlive:${bin.core.out}/share/texmf-dist/scripts/texlive"
export TEXMFCNF="$TEXMFSYSVAR/web2c"
'' +
# patch texmf-dist -> $out/share/texmf
# patch texmf-dist -> $TEXMFDIST
# patch texmf-local -> $out/share/texmf-local
# patch texmf.cnf -> $TEXMFSYSVAR/web2c/texmf.cnf
# TODO: perhaps do lua actions?
# tried inspiration from install-tl, sub do_texmf_cnf
''
if [ -e "$TEXMFCNF/texmfcnf.lua" ]; then
mkdir -p "$TEXMFCNF"
if [ -e "$TEXMFDIST/web2c/texmfcnf.lua" ]; then
sed \
-e 's,texmf-dist,texmf,g' \
-e "s,\(TEXMFDIST[ ]*=[ ]*\)[^\,]*,\1\"$TEXMFDIST\",g" \
-e "s,\(TEXMFLOCAL[ ]*=[ ]*\)[^\,]*,\1\"$out/share/texmf-local\",g" \
-e "s,\$SELFAUTOLOC,$out,g" \
-e "s,selfautodir:/,$out/share/,g" \
-e "s,selfautodir:,$out/share/,g" \
-e "s,selfautoparent:/,$out/share/,g" \
-e "s,selfautoparent:,$out/share/,g" \
-i "$TEXMFCNF/texmfcnf.lua"
"$TEXMFDIST/web2c/texmfcnf.lua" > "$TEXMFCNF/texmfcnf.lua"
fi
sed \
-e 's,texmf-dist,texmf,g' \
-e "s,\(TEXMFDIST[ ]*=[ ]*\)[^\,]*,\1$TEXMFDIST,g" \
-e "s,\$SELFAUTOLOC,$out,g" \
-e "s,\$SELFAUTODIR,$out/share,g" \
-e "s,\$SELFAUTOPARENT,$out/share,g" \
-e "s,\$SELFAUTOGRANDPARENT,$out/share,g" \
-e "/^mpost,/d" `# CVE-2016-10243` \
-i "$TEXMFCNF/texmf.cnf"
mkdir "$out/share/texmf-local"
"$TEXMFDIST/web2c/texmf.cnf" > "$TEXMFCNF/texmf.cnf"
'' +
# now filter hyphenation patterns and formats
(let
Expand Down Expand Up @@ -132,18 +146,31 @@ in (buildEnv {
+ lib.concatMapStrings (pname: section "^-- from ${pname}:$" "^}$|^-- from") hyphenPNames
+ "$p;\n"
);
# formats not being installed must be disabled by prepending #! (see man fmtutil)
# sed expression that enables the formats in /start/,/end/
enableFormats = pname: "/^# from ${pname}:$/,/^# from/{ s/^#! //; };\n";
fmtutilSed =
writeText "fmtutil.sed" (
"1{ s/^(# Generated by .*)$/\\1, modified by texlive.combine/; p; }\n"
+ "2,/^# from/{ /^# from/!p; };\n"
+ lib.concatMapStrings (pname: section "^# from ${pname}:$" "^# from") formatPNames
# document how file was generated
"1{ s/^(# Generated by .*)$/\\1, modified by texlive.combine/; }\n"
# disable all formats, even those already disabled
+ "s/^([^#]|#! )/#! \\1/;\n"
# enable the formats from the packages being installed
+ lib.concatMapStrings enableFormats formatPNames
# clean up formats that have been disabled twice
+ "s/^#! #! /#! /;\n"
);
in ''
for fname in "$out"/share/texmf/tex/generic/config/language.{dat,def}; do
[[ -e "$fname" ]] && sed -E -n -f '${script}' -i "$fname"
mkdir -p "$TEXMFSYSVAR/tex/generic/config"
for fname in tex/generic/config/language.{dat,def}; do
[[ -e "$TEXMFDIST/$fname" ]] && sed -E -n -f '${script}' "$TEXMFDIST/$fname" > "$TEXMFSYSVAR/$fname"
done
[[ -e "$out"/share/texmf/tex/generic/config/language.dat.lua ]] && sed -E -n -f '${scriptLua}' -i "$out"/share/texmf/tex/generic/config/language.dat.lua
[[ -e "$TEXMFCNF"/fmtutil.cnf ]] && sed -E -n -f '${fmtutilSed}' -i "$TEXMFCNF"/fmtutil.cnf
[[ -e "$TEXMFDIST"/tex/generic/config/language.dat.lua ]] && sed -E -n -f '${scriptLua}' \
"$TEXMFDIST"/tex/generic/config/language.dat.lua > "$TEXMFSYSVAR"/tex/generic/config/language.dat.lua
[[ -e "$TEXMFDIST"/web2c/fmtutil.cnf ]] && sed -E -f '${fmtutilSed}' "$TEXMFDIST"/web2c/fmtutil.cnf > "$TEXMFCNF"/fmtutil.cnf
# make new files visible to kpathsea
perl "$TEXMFDIST"/scripts/texlive/mktexlsr.pl --sort "$TEXMFSYSVAR"
'') +

# function to wrap created executables with required env vars
Expand Down Expand Up @@ -191,16 +218,15 @@ in (buildEnv {
'' +
# texlive post-install actions
''
ln -sf "$out"/share/texmf/scripts/texlive/updmap.pl "$out"/bin/updmap
ln -sf "$TEXMFDIST"/scripts/texlive/updmap.pl "$out"/bin/updmap
'' +
# now hack to preserve "$0" for mktexfmt
''
cp "$out"/share/texmf/scripts/texlive/fmtutil.pl "$out/bin/fmtutil"
cp "$TEXMFDIST"/scripts/texlive/fmtutil.pl "$out/bin/fmtutil"
patchShebangs "$out/bin/fmtutil"
sed "1s|$| -I $out/share/texmf/scripts/texlive|" -i "$out/bin/fmtutil"
sed "1s|$| -I $TEXMFDIST/scripts/texlive|" -i "$out/bin/fmtutil"
ln -sf fmtutil "$out/bin/mktexfmt"
perl "$out"/share/texmf/scripts/texlive/mktexlsr.pl --sort "$out"/share/texmf
texlinks "$out/bin" && wrapBin
FORCE_SOURCE_DATE=1 fmtutil --sys --all | grep '^fmtutil' # too verbose
#texlinks "$out/bin" && wrapBin # do we need to regenerate format links?
Expand All @@ -224,25 +250,26 @@ in (buildEnv {
# sort entries to improve reproducibility
[[ -f "$TEXMFSYSCONFIG"/web2c/updmap.cfg ]] && sort -o "$TEXMFSYSCONFIG"/web2c/updmap.cfg "$TEXMFSYSCONFIG"/web2c/updmap.cfg
perl "$out"/share/texmf/scripts/texlive/mktexlsr.pl --sort "$out"/share/texmf-* # to make sure
perl "$TEXMFDIST"/scripts/texlive/mktexlsr.pl --sort "$TEXMFSYSCONFIG" "$TEXMFSYSVAR" # to make sure
'' +
# install (wrappers for) scripts, based on a list from upstream texlive
''
source '${bin.core.out}/share/texmf-dist/scripts/texlive/scripts.lst'
for s in $texmf_scripts; do
[[ -x "$out/share/texmf/scripts/$s" ]] || continue
[[ -x "$TEXMFDIST/scripts/$s" ]] || continue
tName="$(basename $s | sed 's/\.[a-z]\+$//')" # remove extension
[[ ! -e "$out/bin/$tName" ]] || continue
ln -sv "$(realpath $out/share/texmf/scripts/$s)" "$out/bin/$tName" # wrapped below
ln -sv "$(realpath "$TEXMFDIST/scripts/$s")" "$out/bin/$tName" # wrapped below
done
'' +
# A hacky way to provide repstopdf
# * Copy is done to have a correct "$0" so that epstopdf enables the restricted mode
# * ./bin/repstopdf needs to be a symlink to be processed by wrapBin
''
if [[ -e "$out"/bin/epstopdf ]]; then
cp "$out"/bin/epstopdf "$out"/share/texmf/scripts/repstopdf
ln -s "$out"/share/texmf/scripts/repstopdf "$out"/bin/repstopdf
mkdir -p "$TEXMFSYSVAR/scripts"
cp "$out"/bin/epstopdf "$TEXMFSYSVAR"/scripts/repstopdf
ln -s "$TEXMFSYSVAR"/scripts/repstopdf "$out"/bin/repstopdf
fi
'' +
# finish up the wrappers
Expand All @@ -262,16 +289,6 @@ in (buildEnv {
# TODO: a context trigger https://www.preining.info/blog/2015/06/debian-tex-live-2015-the-new-layout/
# http://wiki.contextgarden.net/ConTeXt_Standalone#Unix-like_platforms_.28Linux.2FMacOS_X.2FFreeBSD.2FSolaris.29

# I would just create links from "$out"/share/{man,info},
# but buildenv has problems with merging symlinks with directories;
# note: it's possible we might need deepen the work-around to man/*.
''
for d in {man,info}; do
[[ -e "$out/share/texmf/doc/$d" ]] || continue;
mkdir -p "$out/share/$d"
ln -s -t "$out/share/$d" "$out/share/texmf/doc/$d"/*
done
'' +
# MkIV uses its own lookup mechanism and we need to initialize
# caches for it.
''
Expand All @@ -283,7 +300,7 @@ in (buildEnv {
# Get rid of all log files. They are not needed, but take up space
# and render the build unreproducible by their embedded timestamps.
''
find $TEXMFSYSVAR/web2c -name '*.log' -delete
find "$TEXMFSYSVAR"/web2c -name '*.log' -delete
''
;
}).overrideAttrs (_: { allowSubstitutes = true; })
Expand Down

0 comments on commit f6e0676

Please sign in to comment.