about summary refs log tree commit diff
path: root/pkgs/tools/typesetting/tex/texlive/combine.nix
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2023-03-17 12:01:17 +0000
committerGitHub <noreply@github.com>2023-03-17 12:01:17 +0000
commit23949862041c26b37f9927920ce43e20739b716f (patch)
tree219c7adbba001e5e933abc7956639f6211ad8c8d /pkgs/tools/typesetting/tex/texlive/combine.nix
parentf5629a45189a88cd0c362b5c694f74d5c700967d (diff)
parent9b0777ffb3ab046e329af80a177d663387bf8f0f (diff)
downloadnixlib-23949862041c26b37f9927920ce43e20739b716f.tar
nixlib-23949862041c26b37f9927920ce43e20739b716f.tar.gz
nixlib-23949862041c26b37f9927920ce43e20739b716f.tar.bz2
nixlib-23949862041c26b37f9927920ce43e20739b716f.tar.lz
nixlib-23949862041c26b37f9927920ce43e20739b716f.tar.xz
nixlib-23949862041c26b37f9927920ce43e20739b716f.tar.zst
nixlib-23949862041c26b37f9927920ce43e20739b716f.zip
Merge master into staging-next
Diffstat (limited to 'pkgs/tools/typesetting/tex/texlive/combine.nix')
-rw-r--r--pkgs/tools/typesetting/tex/texlive/combine.nix131
1 files changed, 74 insertions, 57 deletions
diff --git a/pkgs/tools/typesetting/tex/texlive/combine.nix b/pkgs/tools/typesetting/tex/texlive/combine.nix
index 5caebace7cbd..5681d2cd454e 100644
--- a/pkgs/tools/typesetting/tex/texlive/combine.nix
+++ b/pkgs/tools/typesetting/tex/texlive/combine.nix
@@ -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 ];
@@ -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
@@ -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
@@ -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?
@@ -224,16 +250,16 @@ 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
@@ -241,8 +267,9 @@ in (buildEnv {
     #  * ./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
@@ -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.
   ''
@@ -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; })