From a73239d2cff6746b75150c199603f740e05d55c5 Mon Sep 17 00:00:00 2001 From: Alejandro Angulo Date: Sun, 12 Feb 2023 11:05:57 -0800 Subject: [PATCH] Moved build script out into its own file Now I can run shellcheck on the bash :) --- build.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 61 +++++++----------------------------------------------- 2 files changed, 69 insertions(+), 54 deletions(-) create mode 100644 build.sh diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..53189bd --- /dev/null +++ b/build.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +# Following variables are set via sed in the buildPhase step +PREFIX="" +# Intentionally overriding PATH so supressing shellcheck +# shellcheck disable=SC2123 +PATH="" +NERDFONTS="" + +DEBUG=false +DIR=$(mktemp -d) +RES=$(pwd)/alejandro_resume.pdf +LOG=$(pwd)/alejandro_resume.log + +function usage { +echo "Usage: $(basename "$0") [-h] [-d] [-e EMAIL] [-p PHONENUMBER]" +echo ' -h Prints this usage message.' +echo "" +echo ' -d Saves latexmk log file (will be named alejandro_resume.log)' +echo "" +echo ' -e EMAIL Sets email address used when building document.' +echo ' Can also be set with EMAIL environment variable.' +echo "" +echo ' -p PHONENUMBER Sets phone number used when building the document.' +echo ' Can also be set with PHONENUMBER environment variable.' +} + +while getopts ':de:p:h' flag; do +case $flag in + 'd') DEBUG=true;; + # Overrides EMAIL and PHONENUMBER envvars if set + 'e') EMAIL="$OPTARG";; + 'p') PHONENUMBER="$OPTARG";; + 'h') usage && exit;; + ?) usage && exit 1;; +esac +done + +cd "$PREFIX"/share || exit 1 +mkdir -p "$DIR/.texcache/texmf-var" + +export EMAIL +export PHONENUMBER + +# Set via sed in buildPhase (needs to be set after we have input values (e.g. +# EMAIL and PHONENUMBER) +TEXVARS="" + +env TEXFMHOME="$DIR/.texcache" TEXMFVAR="$DIR/.texcache/texmf-var" \ + OSFONTDIR="$NERDFONTS"/share/fonts \ +latexmk -interaction=nonstopmode -pdf -lualatex \ +-output-directory="$DIR" \ +-pretex="$TEXVARS" \ +-usepretex alejandro_resume.tex + +mv "$DIR/alejandro_resume.pdf" "$RES" + +if $DEBUG; then +mv "$DIR/alejandro_resume.log" "$LOG" +fi + +rm -rf "$DIR" diff --git a/flake.nix b/flake.nix index ced72ff..d7b1e3f 100644 --- a/flake.nix +++ b/flake.nix @@ -25,7 +25,7 @@ # Create definitions like \def\email{$EMAIL} # Each \email command in the tex document will be populated by an EMAIL # variable (can be set as an environment variable) - texvars = toString (lib.concatMapStrings (x: ''\def\${x}{${"$" + lib.toUpper x}}'') vars); + texvars = toString (lib.concatMapStrings (x: ''\\def\\${x}{${"$" + lib.toUpper x}}'') vars); in { packages.${system} = { # inherit system; @@ -34,60 +34,12 @@ src = self; propogatedBuildInputs = [pkgs.coreutils nerdfonts-hack tex]; phases = ["unpackPhase" "buildPhase" "installPhase"]; - SCRIPT = '' - #!/usr/bin/env bash - - prefix=${builtins.placeholder "out"} - export PATH="${lib.makeBinPath propogatedBuildInputs}"; - DEBUG=false - DIR=$(mktemp -d) - RES=$(pwd)/alejandro_resume.pdf - LOG=$(pwd)/alejandro_resume.log - - function usage { - echo "Usage: $(basename $0) [-h] [-d] [-e EMAIL] [-p PHONENUMBER]" - echo ' -h Prints this usage message.' - echo "" - echo ' -d Saves latexmk log file (will be named alejandro_resume.log)' - echo "" - echo ' -e EMAIL Sets email address used when building document.' - echo ' Can also be set with EMAIL environment variable.' - echo "" - echo ' -p PHONENUMBER Sets phone number used when building the document.' - echo ' Can also be set with PHONENUMBER environment variable.' - } - - while getopts ':de:p:h' flag; do - case $flag in - 'd') DEBUG=true;; - # Overrides EMAIL and PHONENUMBER envvars if set - 'e') EMAIL="$OPTARG";; - 'p') PHONENUMBER="$OPTARG";; - 'h') usage && exit;; - ?) usage && exit 1;; - esac - done - - cd $prefix/share - mkdir -p "$DIR/.texcache/texmf-var" - - env TEXFMHOME="$DIR/.texcache" TEXMFVAR="$DIR/.texcache/texmf-var" \ - OSFONTDIR=${nerdfonts-hack}/share/fonts \ - latexmk -interaction=nonstopmode -pdf -lualatex \ - -output-directory="$DIR" \ - -pretex="${texvars}"\ - -usepretex alejandro_resume.tex - - mv "$DIR/alejandro_resume.pdf" "$RES" - - if $DEBUG; then - mv "$DIR/alejandro_resume.log" "$LOG" - fi - - rm -rf $DIR - ''; buildPhase = '' - printenv SCRIPT > alejandro-resume + cp build.sh alejandro-resume + sed -i 's!PREFIX=""!PREFIX="${builtins.placeholder "out"}"!g' alejandro-resume + sed -i 's!PATH=""!PATH="${lib.makeBinPath propogatedBuildInputs}"!g' alejandro-resume + sed -i 's!TEXVARS=""!TEXVARS="${texvars}"!g' alejandro-resume + sed -i 's!NERDFONTS=""!NERDFONTS="${nerdfonts-hack}"!g' alejandro-resume ''; installPhase = '' mkdir -p $out/{bin,share} @@ -109,6 +61,7 @@ pre-commit tex #TODO: Is this necessary? zathura # PDF Viewer + shellcheck ]; shellHook = ''