From 33f6ae7e552e5c27a464fa610e28b0ef55115062 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Tue, 17 Nov 2020 15:51:09 +0100 Subject: [PATCH] Add bundled report example --- garlic/bundleReport.nix | 31 +++++++++++++++++++++++++++++++ garlic/report.nix | 18 ++++-------------- garlic/report/Makefile | 4 ++++ garlic/{ => report}/report.tex | 4 ++-- garlic/reportTar.nix | 28 ++++++++++++++++++++++++++++ garlic/sedReport.nix | 28 ++++++++++++++-------------- overlay.nix | 9 +++++++++ 7 files changed, 92 insertions(+), 30 deletions(-) create mode 100644 garlic/bundleReport.nix create mode 100644 garlic/report/Makefile rename garlic/{ => report}/report.tex (85%) create mode 100644 garlic/reportTar.nix diff --git a/garlic/bundleReport.nix b/garlic/bundleReport.nix new file mode 100644 index 0000000..fd84775 --- /dev/null +++ b/garlic/bundleReport.nix @@ -0,0 +1,31 @@ +{ + stdenv +, fig +}: + +stdenv.mkDerivation { + name = "report.tar.gz"; + src = ./report; + buildPhase = '' + pwd + ls -l + grep -o '@[^ @]*@' report.tex | sed 's/@//g' | sort -u > list + + echo "fig:" > fun.nix + echo "'''" >> fun.nix + for line in $(cat list); do + localPath=$(echo $line | tr '.' '/') + echo "mkdir -p $localPath" >> fun.nix + echo "cp -r \''${$line}/* $localPath" >> fun.nix + echo "sed -i 's;@$line@;$localPath;g' report.tex" >> fun.nix + done + echo "'''" >> fun.nix + + echo " ---------- this is the fun.nix -------------" + cat fun.nix + echo " --------------------------------------------" + ''; + installPhase = '' + cp fun.nix $out + ''; +} diff --git a/garlic/report.nix b/garlic/report.nix index fe580a9..6d7dc46 100644 --- a/garlic/report.nix +++ b/garlic/report.nix @@ -8,27 +8,17 @@ , sedReport }: let - # TODO: We can select only which elements we need from fig by using: - # echo [ $(grep -o '@[^ @]*@' garlic/report.tex | sed 's/@//g') ] - # and them importing as valid nix lang. - - # By now, we require all plots - figJSON = writeText "fig.json" (builtins.toJSON fig); sedCmd = (import sedReport) fig; in stdenv.mkDerivation { - name = "report"; - src = ./.; + name = "report.pdf"; + src = ./report; buildInputs = [ jq texlive.combined.scheme-basic ]; buildPhase = '' ${sedCmd} - cat report.tex - pdflatex report.tex -o report.pdf - # Run again to fix figure references - pdflatex report.tex -o report.pdf + make ''; installPhase = '' - mkdir $out - cp report.* $out + cp report.pdf $out ''; } diff --git a/garlic/report/Makefile b/garlic/report/Makefile new file mode 100644 index 0000000..81ae94d --- /dev/null +++ b/garlic/report/Makefile @@ -0,0 +1,4 @@ +all: report.tex + pdflatex report.tex -o report.pdf + # Run again to fix figure references + pdflatex report.tex -o report.pdf diff --git a/garlic/report.tex b/garlic/report/report.tex similarity index 85% rename from garlic/report.tex rename to garlic/report/report.tex index a24cedd..f56c1c9 100644 --- a/garlic/report.tex +++ b/garlic/report/report.tex @@ -14,8 +14,8 @@ time $t$ is measured, as shown in the figure \ref{fig:nbody.test}. % \begin{figure}[h] \centering - \includegraphics[width=0.45\textwidth]{@fig.nbody.baseline@/scatter.png} - \includegraphics[width=0.45\textwidth]{@fig.nbody.baseline@/box.png} + \includegraphics[width=0.45\textwidth]{@fig.nbody.small@/scatter.png} + \includegraphics[width=0.45\textwidth]{@fig.nbody.small@/box.png} \caption{Nbody times with varying block size} \label{fig:nbody.test} \end{figure} diff --git a/garlic/reportTar.nix b/garlic/reportTar.nix new file mode 100644 index 0000000..c2b274b --- /dev/null +++ b/garlic/reportTar.nix @@ -0,0 +1,28 @@ +{ + stdenv +, fig +, writeText +, busybox +, jq +, texlive +, bundleReport +}: +let + + genCmd = (import bundleReport) fig; +in + stdenv.mkDerivation { + name = "report.tar.gz"; + src = ./report; + buildInputs = [ jq texlive.combined.scheme-basic ]; + buildPhase = '' + ${genCmd} + ls -ltR + cat report.tex + make + ''; + installPhase = '' + cd .. + tar -czf $out report + ''; + } diff --git a/garlic/sedReport.nix b/garlic/sedReport.nix index 37dd1d9..b776681 100644 --- a/garlic/sedReport.nix +++ b/garlic/sedReport.nix @@ -2,18 +2,18 @@ stdenv , fig }: - stdenv.mkDerivation { - name = "report"; - src = ./.; - buildPhase = '' - grep -o '@[^ @]*@' report.tex | sed 's/@//g' | sort -u > list +stdenv.mkDerivation { + name = "sedReport"; + src = ./report; + buildPhase = '' + grep -o '@[^ @]*@' report.tex | sed 's/@//g' | sort -u > list - echo "fig:" > fun.nix - echo "'''" >> fun.nix - sed 's:\(^.*\)$:sed -i "s;@\1@;''${\1};g" report.tex:g' list >> fun.nix - echo "'''" >> fun.nix - ''; - installPhase = '' - cp fun.nix $out - ''; - } + echo "fig:" > fun.nix + echo "'''" >> fun.nix + sed 's:\(^.*\)$:sed -i "s;@\1@;''${\1};g" report.tex:g' list >> fun.nix + echo "'''" >> fun.nix + ''; + installPhase = '' + cp fun.nix $out + ''; +} diff --git a/overlay.nix b/overlay.nix index 1b79f74..289c661 100644 --- a/overlay.nix +++ b/overlay.nix @@ -186,10 +186,19 @@ let report = callPackage ./garlic/report.nix { fig = bsc.garlic.fig; }; + sedReport = callPackage ./garlic/sedReport.nix { fig = bsc.garlic.fig; }; + bundleReport = callPackage ./garlic/bundleReport.nix { + fig = bsc.garlic.fig; + }; + + reportTar = callPackage ./garlic/reportTar.nix { + fig = bsc.garlic.fig; + }; + # Use the configuration for the following target machine targetMachine = bsc.garlic.machines.mn4;