Merge pull request #206708 from xworld21/texlive-cleanup

texlive.combine: no-effect clean up of script
This commit is contained in:
Dmitry Kalinkin 2022-12-20 17:46:28 -05:00 committed by GitHub
commit e557010c6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -50,34 +50,32 @@ in (buildEnv {
"/tex/generic/config" # make it a real directory for scheme-infraonly "/tex/generic/config" # make it a real directory for scheme-infraonly
]; ];
nativeBuildInputs = [ makeWrapper libfaketime ]; nativeBuildInputs = [ makeWrapper libfaketime perl bin.texlinks ];
buildInputs = pkgList.extraInputs; buildInputs = pkgList.extraInputs;
# This is set primarily to help find-tarballs.nix to do its job # This is set primarily to help find-tarballs.nix to do its job
passthru.packages = pkgList.all; passthru.packages = pkgList.all;
postBuild = '' postBuild = ''
cd "$out" mkdir -p "$out"/bin
mkdir -p ./bin
'' + '' +
lib.concatMapStrings lib.concatMapStrings
(path: '' (path: ''
for f in '${path}'/bin/*; do for f in '${path}'/bin/*; do
if [[ -L "$f" ]]; then if [[ -L "$f" ]]; then
cp -d "$f" ./bin/ cp -d "$f" "$out"/bin/
else else
ln -s "$f" ./bin/ ln -s "$f" "$out"/bin/
fi fi
done done
'') '')
pkgList.bin pkgList.bin
+ +
'' ''
export PATH="$out/bin:$out/share/texmf/scripts/texlive:${perl}/bin:$PATH" export PATH="$out/bin:$out/share/texmf/scripts/texlive:$PATH"
export TEXMFCNF="$out/share/texmf/web2c" export TEXMFCNF="$out/share/texmf/web2c"
export TEXMFDIST="$out/share/texmf" TEXMFSYSCONFIG="$out/share/texmf-config"
export TEXMFSYSCONFIG="$out/share/texmf-config" TEXMFSYSVAR="$out/share/texmf-var"
export TEXMFSYSVAR="$out/share/texmf-var"
export PERL5LIB="$out/share/texmf/scripts/texlive:${bin.core.out}/share/texmf-dist/scripts/texlive" export PERL5LIB="$out/share/texmf/scripts/texlive:${bin.core.out}/share/texmf-dist/scripts/texlive"
'' + '' +
# patch texmf-dist -> $out/share/texmf # patch texmf-dist -> $out/share/texmf
@ -85,41 +83,28 @@ in (buildEnv {
# TODO: perhaps do lua actions? # TODO: perhaps do lua actions?
# tried inspiration from install-tl, sub do_texmf_cnf # tried inspiration from install-tl, sub do_texmf_cnf
'' ''
patchCnfLua() { if [ -e "$TEXMFCNF/texmfcnf.lua" ]; then
local cnfLua="$1"
if [ -e "$cnfLua" ]; then
local cnfLuaOrig="$(realpath "$cnfLua")"
rm ./texmfcnf.lua
sed \
-e 's,texmf-dist,texmf,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" \
"$cnfLuaOrig" > "$cnfLua"
fi
}
(
cd ./share/texmf/web2c/
local cnfOrig="$(realpath ./texmf.cnf)"
rm ./texmf.cnf
sed \ sed \
-e 's,texmf-dist,texmf,g' \ -e 's,texmf-dist,texmf,g' \
-e "s,\(TEXMFLOCAL[ ]*=[ ]*\)[^\,]*,\1\"$out/share/texmf-local\",g" \
-e "s,\$SELFAUTOLOC,$out,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,selfautodir:,$out/share/,g" \
-e "s,\$SELFAUTOGRANDPARENT,$out/share,g" \ -e "s,selfautoparent:/,$out/share/,g" \
-e "/^mpost,/d" `# CVE-2016-10243` \ -e "s,selfautoparent:,$out/share/,g" \
"$cnfOrig" > ./texmf.cnf -i "$TEXMFCNF/texmfcnf.lua"
fi
patchCnfLua "./texmfcnf.lua" sed \
-e 's,texmf-dist,texmf,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 mkdir "$out/share/texmf-local"
)
'' + '' +
# now filter hyphenation patterns and formats # now filter hyphenation patterns and formats
(let (let
@ -154,23 +139,17 @@ in (buildEnv {
+ lib.concatMapStrings (pname: section "^# from ${pname}:$" "^# from") formatPNames + lib.concatMapStrings (pname: section "^# from ${pname}:$" "^# from") formatPNames
); );
in '' in ''
( for fname in "$out"/share/texmf/tex/generic/config/language.{dat,def}; do
cd ./share/texmf/tex/generic/config/ [[ -e "$fname" ]] && sed -E -n -f '${script}' -i "$fname"
for fname in language.{dat,def}; do done
[[ -e "$fname" ]] && sed -E -n -f '${script}' -i "$fname" [[ -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
done [[ -e "$TEXMFCNF"/fmtutil.cnf ]] && sed -E -n -f '${fmtutilSed}' -i "$TEXMFCNF"/fmtutil.cnf
[[ -e language.dat.lua ]] && sed -E -n -f '${scriptLua}' -i language.dat.lua
)
(
cd ./share/texmf/web2c/
[[ -e fmtutil.cnf ]] && sed -E -n -f '${fmtutilSed}' -i fmtutil.cnf
)
'') + '') +
# function to wrap created executables with required env vars # function to wrap created executables with required env vars
'' ''
wrapBin() { wrapBin() {
for link in ./bin/*; do for link in "$out"/bin/*; do
[ -L "$link" -a -x "$link" ] || continue # if not link, assume OK [ -L "$link" -a -x "$link" ] || continue # if not link, assume OK
local target=$(readlink "$link") local target=$(readlink "$link")
@ -212,9 +191,7 @@ in (buildEnv {
'' + '' +
# texlive post-install actions # texlive post-install actions
'' ''
for tool in updmap; do ln -sf "$out"/share/texmf/scripts/texlive/updmap.pl "$out"/bin/updmap
ln -sf "$out/share/texmf/scripts/texlive/$tool."* "$out/bin/$tool"
done
'' + '' +
# now hack to preserve "$0" for mktexfmt # now hack to preserve "$0" for mktexfmt
'' ''
@ -223,56 +200,49 @@ in (buildEnv {
sed "1s|$| -I $out/share/texmf/scripts/texlive|" -i "$out/bin/fmtutil" sed "1s|$| -I $out/share/texmf/scripts/texlive|" -i "$out/bin/fmtutil"
ln -sf fmtutil "$out/bin/mktexfmt" ln -sf fmtutil "$out/bin/mktexfmt"
perl `type -P mktexlsr.pl` --sort ./share/texmf perl "$out"/share/texmf/scripts/texlive/mktexlsr.pl --sort "$out"/share/texmf
${bin.texlinks}/bin/texlinks "$out/bin" && wrapBin texlinks "$out/bin" && wrapBin
FORCE_SOURCE_DATE=1 perl `type -P fmtutil.pl` --sys --all | grep '^fmtutil' # too verbose FORCE_SOURCE_DATE=1 fmtutil --sys --all | grep '^fmtutil' # too verbose
#${bin.texlinks}/bin/texlinks "$out/bin" && wrapBin # do we need to regenerate format links? #texlinks "$out/bin" && wrapBin # do we need to regenerate format links?
# tex intentionally ignores SOURCE_DATE_EPOCH even when FORCE_SOURCE_DATE=1 # tex intentionally ignores SOURCE_DATE_EPOCH even when FORCE_SOURCE_DATE=1
# https://salsa.debian.org/live-team/live-build/-/blob/master/examples/hooks/reproducible/0139-reproducible-texlive-binaries-fmt-files.hook.chroot#L52 # https://salsa.debian.org/live-team/live-build/-/blob/master/examples/hooks/reproducible/0139-reproducible-texlive-binaries-fmt-files.hook.chroot#L52
if [[ -d share/texmf-var/web2c/tex ]] if [[ -f "$TEXMFSYSVAR"/web2c/tex/tex.fmt ]]
then then
cd share/texmf-var/web2c/tex faketime $(date --utc -d@$SOURCE_DATE_EPOCH --iso-8601=seconds) tex -output-directory "$TEXMFSYSVAR"/web2c/tex -ini -jobname=tex -progname=tex tex.ini
faketime $(date --utc -d@$SOURCE_DATE_EPOCH --iso-8601=seconds) tex -ini -jobname=tex -progname=tex tex.ini
cd -
fi fi
if [[ -f share/texmf-var/web2c/luahbtex/lualatex.fmt ]] if [[ -f "$TEXMFSYSVAR"/web2c/luahbtex/lualatex.fmt ]]
then then
cd share/texmf-var/web2c/luahbtex faketime $(date --utc -d@$SOURCE_DATE_EPOCH --iso-8601=seconds) luahbtex --output-directory="$TEXMFSYSVAR"/web2c/luahbtex -ini -jobname=lualatex -progname=lualatex lualatex.ini
faketime $(date --utc -d@$SOURCE_DATE_EPOCH --iso-8601=seconds) luahbtex -ini -jobname=lualatex -progname=lualatex lualatex.ini
cd -
fi fi
# Disable unavailable map files # Disable unavailable map files
echo y | perl `type -P updmap.pl` --sys --syncwithtrees --force echo y | updmap --sys --syncwithtrees --force
# Regenerate the map files (this is optional) # Regenerate the map files (this is optional)
perl `type -P updmap.pl` --sys --force updmap --sys --force
# sort entries to improve reproducibility # sort entries to improve reproducibility
[[ -f "$TEXMFSYSCONFIG"/web2c/updmap.cfg ]] && sort -o "$TEXMFSYSCONFIG"/web2c/updmap.cfg "$TEXMFSYSCONFIG"/web2c/updmap.cfg [[ -f "$TEXMFSYSCONFIG"/web2c/updmap.cfg ]] && sort -o "$TEXMFSYSCONFIG"/web2c/updmap.cfg "$TEXMFSYSCONFIG"/web2c/updmap.cfg
perl `type -P mktexlsr.pl` --sort ./share/texmf-* # to make sure perl "$out"/share/texmf/scripts/texlive/mktexlsr.pl --sort "$out"/share/texmf-* # to make sure
'' + '' +
# install (wrappers for) scripts, based on a list from upstream texlive # install (wrappers for) scripts, based on a list from upstream texlive
'' ''
( source '${bin.core.out}/share/texmf-dist/scripts/texlive/scripts.lst'
cd "$out/share/texmf/scripts" for s in $texmf_scripts; do
source '${bin.core.out}/share/texmf-dist/scripts/texlive/scripts.lst' [[ -x "$out/share/texmf/scripts/$s" ]] || continue
for s in $texmf_scripts; do tName="$(basename $s | sed 's/\.[a-z]\+$//')" # remove extension
[[ -x "./$s" ]] || continue [[ ! -e "$out/bin/$tName" ]] || continue
tName="$(basename $s | sed 's/\.[a-z]\+$//')" # remove extension ln -sv "$(realpath $out/share/texmf/scripts/$s)" "$out/bin/$tName" # wrapped below
[[ ! -e "$out/bin/$tName" ]] || continue done
ln -sv "$(realpath $s)" "$out/bin/$tName" # wrapped below
done
)
'' + '' +
# A hacky way to provide repstopdf # A hacky way to provide repstopdf
# * Copy is done to have a correct "$0" so that epstopdf enables the restricted mode # * 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 # * ./bin/repstopdf needs to be a symlink to be processed by wrapBin
'' ''
if [[ -e ./bin/epstopdf ]]; then if [[ -e "$out"/bin/epstopdf ]]; then
cp $(realpath ./bin/epstopdf) ./share/texmf/scripts/repstopdf cp "$out"/bin/epstopdf "$out"/share/texmf/scripts/repstopdf
ln -s "$out"/share/texmf/scripts/repstopdf ./bin/repstopdf ln -s "$out"/share/texmf/scripts/repstopdf "$out"/bin/repstopdf
fi fi
'' + '' +
# finish up the wrappers # finish up the wrappers
@ -283,7 +253,7 @@ in (buildEnv {
# Perform a small test to verify that the restricted mode get enabled when # Perform a small test to verify that the restricted mode get enabled when
# needed (detected by checking if it disallows --gscmd) # needed (detected by checking if it disallows --gscmd)
'' ''
if [[ -e ./bin/epstopdf ]]; then if [[ -e "$out"/bin/epstopdf ]]; then
echo "Testing restricted mode for {,r}epstopdf" echo "Testing restricted mode for {,r}epstopdf"
! (epstopdf --gscmd echo /dev/null 2>&1 || true) | grep forbidden ! (epstopdf --gscmd echo /dev/null 2>&1 || true) | grep forbidden
(repstopdf --gscmd echo /dev/null 2>&1 || true) | grep forbidden (repstopdf --gscmd echo /dev/null 2>&1 || true) | grep forbidden
@ -297,24 +267,16 @@ in (buildEnv {
# note: it's possible we might need deepen the work-around to man/*. # note: it's possible we might need deepen the work-around to man/*.
'' ''
for d in {man,info}; do for d in {man,info}; do
[[ -e "./share/texmf/doc/$d" ]] || continue; [[ -e "$out/share/texmf/doc/$d" ]] || continue;
( mkdir -p "$out/share/$d"
mkdir -p "./share/$d" && cd "./share/$d" ln -s -t "$out/share/$d" "$out/share/texmf/doc/$d"/*
ln -s -t . ../texmf/doc/"$d"/*
)
done done
'' + '' +
# MkIV uses its own lookup mechanism and we need to initialize # MkIV uses its own lookup mechanism and we need to initialize
# caches for it. Unsetting TEXMFCNF is needed to let mtxrun # caches for it.
# determine it from kpathsea so that the config path is given with
# "selfautodir:" as it will be in runtime. This is important because
# the cache is identified by a hash of this path.
'' ''
if [[ -e "$out/bin/mtxrun" ]]; then if [[ -e "$out/bin/mtxrun" ]]; then
( mtxrun --generate
unset TEXMFCNF
mtxrun --generate
)
fi fi
'' ''
+ bin.cleanBrokenLinks + + bin.cleanBrokenLinks +