summary refs log tree commit diff
path: root/pkgs/tools/typesetting/tex/texlive/aggregate.nix
blob: 550870b0a6a99e4dac8143950da136212b9ea77e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
args @ {poppler, perl, makeWrapper, ... }: with args;
rec {
  name = "TeXLive-linkdir";

  buildInputs = lib.closePropagation paths
    ++ [perl]
    ++ stdenv.lib.optional stdenv.isDarwin makeWrapper;

  phaseNames = [ "doAggregate" ];

  doAggregate = fullDepEntry (''
    set +o pipefail

    mkdir -p $out/bin
    for currentPath in ${lib.concatStringsSep " " buildInputs}; do
        echo Symlinking "$currentPath"
        find $currentPath/share/info $currentPath/share/man $(echo $currentPath/texmf*/) -type d | while read; do
            REPLY="''${REPLY#$currentPath}"
            mkdir -p $out/"$REPLY"
        done
        find $currentPath/share/info $currentPath/share/man $(echo $currentPath/texmf*/) ! -type d | while read; do
            REPLY="''${REPLY#$currentPath}"
            ln -fs $currentPath/"$REPLY" $out/"$REPLY"
            echo
        done | while read; do head -n 999 >/dev/null; echo -n .; done

        for i in "$currentPath/bin/"* :; do
            test "$i" != : || continue
            echo -ne "#! $SHELL\\nexec $i \"\$@\"" > "$out/bin/$(basename "$i")" && \
            chmod a+x "$out/bin/$(basename "$i")"
        done

        echo

        cp -Trfp $currentPath/libexec $out/libexec || true
    done

    ln -s $out/texmf* $out/share/

    rm -rf $out/texmf-config
    find $out/texmf*/ -type d | while read; do
      REPLY="''${REPLY#$out/texmf}"
      mkdir -p $out/texmf-config/"$REPLY"
    done

    for i in $out/libexec/*/* :; do
        test "$i" = : && continue;
        test -f "$i" && \
        test -x "$i" && \
        echo -ne "#! $SHELL\\nexec $i \"\$@\"" >$out/bin/$(basename $i) && \
        chmod a+x $out/bin/$(basename $i)
    done

    rm -f $out/texmf*/ls-R
    for i in web2c texconfig fonts/map; do
        mkdir -p $out/texmf-config/$i
        cp -Lr $out/texmf*/$i/* $out/texmf-config/$i || true
    done
    chmod -R u+w $out/texmf-config

    yes | TEXMFCONFIG=$out/texmf-config HOME=$PWD PATH=$PATH:$out/bin updmap --syncwithtrees
    yes | PATH=$PATH:$out/bin mktexlsr $out/texmf*
    yes | TEXMFCONFIG=$out/texmf-config HOME=$PWD PATH=$PATH:$out/bin updmap --syncwithtrees
    yes | PATH=$PATH:$out/bin mktexlsr $out/texmf*
  '' + stdenv.lib.optionalString stdenv.isDarwin ''
    # did the same thing in texLive, but couldn't get it to carry to the
    # binaries installed by texLiveFull
    for prog in $out/bin/*; do
      wrapProgram "$prog" --prefix DYLD_LIBRARY_PATH : "${poppler.out}/lib"
    done
  '' ) [ "minInit" "defEnsureDir" "addInputs" ];

  preferLocalBuild = true;

  meta = {
    description = "TeX distribution directory";
    longDescription = ''
      Here all the files from different TeX-related
      packages are collected in one directory. Of
      course, mktexlsr is called. Later placed
      directories take precedence. It is supposed that
      share and libexec are symlinked, and bin is
      recreated with wrappers for libexec-located
      linked binaries.
    '';
  };
}