diff --git a/pkgs/misc/tex/nix/default.nix b/pkgs/misc/tex/nix/default.nix index 0f0c798a2e2..8918ab00d62 100644 --- a/pkgs/misc/tex/nix/default.nix +++ b/pkgs/misc/tex/nix/default.nix @@ -76,6 +76,29 @@ rec { }; + findLhs2TeXIncludes = + { rootFile + }: + + builtins.genericClosure { + startSet = [{key = rootFile;}]; + + operator = + {key, ...}: + + let + + trace = x: builtins.trace x x; + + deps = import (pkgs.runCommand "lhs2tex-includes" + { src = trace key; } + "${pkgs.stdenv.bash}/bin/bash ${./find-lhs2tex-includes.sh}"); + + in pkgs.lib.concatMap (x : if builtins.pathExists x then [{key = x;}] + else builtins.trace ("not found: ${toString x}") []) + (map (x : trace "${dirOf key}/${x}") deps); + }; + dot2pdf = { dotGraph }: @@ -103,6 +126,17 @@ rec { ]; }; + lhs2tex = + { source, flags ? null } : + pkgs.stdenv.mkDerivation { + name = "tex"; + builder = ./lhs2tex.sh; + inherit source flags; + buildInputs = [ pkgs.lhs2tex pkgs.perl ]; + copyIncludes = ./copy-includes.pl; + includes = map (x: [x.key (baseNameOf (toString x.key))]) + (findLhs2TeXIncludes {rootFile = source;}); + }; animateDot = dotGraph: nrFrames: pkgs.stdenv.mkDerivation { name = "dot-frames"; diff --git a/pkgs/misc/tex/nix/find-includes.pl b/pkgs/misc/tex/nix/find-includes.pl index 99204b46750..6441f18855b 100644 --- a/pkgs/misc/tex/nix/find-includes.pl +++ b/pkgs/misc/tex/nix/find-includes.pl @@ -20,6 +20,14 @@ while () { my $fn2 = $1; die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/"; addName "tex", "$fn2"; + } elsif (/\\input (.*)$/) { + my $fn2 = $1; + die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/"; + addName "tex", "$fn2"; + } elsif (/\\RequirePackage(\[.*\])?\{(.*)\}/) { + my $fn2 = $2; + die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/"; + addName "misc", "$fn2.sty"; } elsif (/\\usepackage(\[.*\])?\{(.*)\}/) { my $fn2 = $2; die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/"; diff --git a/pkgs/misc/tex/nix/find-lhs2tex-includes.sh b/pkgs/misc/tex/nix/find-lhs2tex-includes.sh new file mode 100644 index 00000000000..2dc12aa517a --- /dev/null +++ b/pkgs/misc/tex/nix/find-lhs2tex-includes.sh @@ -0,0 +1,3 @@ +echo '[' > $out +grep '^%include ' $src | cut -d ' ' -f 2 | sed 's/^\(.*\)$/"\1"/' >> $out +echo ']' >> $out diff --git a/pkgs/misc/tex/nix/lhs2tex.sh b/pkgs/misc/tex/nix/lhs2tex.sh new file mode 100644 index 00000000000..6edca4baf8a --- /dev/null +++ b/pkgs/misc/tex/nix/lhs2tex.sh @@ -0,0 +1,19 @@ +source $stdenv/setup + +ensureDir $out + +mkdir root +cd root + +startDir=$(perl $copyIncludes $includes) +cd $startDir + +lhstex() { + sourceFile=$1 + targetName=$out/$(basename $(stripHash $sourceFile; echo $strippedName) .lhs).tex + echo "converting $sourceFile to $targetName..." + lhs2TeX -o "$targetName" $flags "$sourceFile" +} + +lhstex $source + diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c43c88c0016..c4413557b14 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -7871,6 +7871,7 @@ let texFunctions = import ../misc/tex/nix { inherit stdenv perl tetex graphviz ghostscript makeFontsConf imagemagick runCommand lib; + inherit (haskellPackages) lhs2tex; }; texLive = builderDefsPackage (import ../misc/tex/texlive) {