ARG FROM_IMG=docker.io/library/haskell
ARG FROM_TAG=8.10.4

FROM ${FROM_IMG}:${FROM_TAG}

ENV LANG=de_DE.UTF-8

# compile-time dependencies
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get -y update && apt-get install -y libpq-dev libsodium-dev
# RUN apt-get -y update && apt-get -y install llvm
# RUN apt-get -y update && apt-get -y install g++ libghc-zlib-dev libpq-dev libsodium-dev pkg-config
# RUN apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get -y update && apt-get install -y --no-install-recommends locales locales-all

# run-time dependencies for uniworx binary
# RUN apt-get -y update && apt-get -y install pdftk
# RUN apt-get -y update && apt-get -y install \
# texlive texlive-latex-recommended texlive-luatex texlive-plain-generic texlive-lang-german texlive-lang-english
RUN apt-get -y update && apt-get -y install \
    wget \
    perl \
    xz-utils \
    fonts-roboto \
    texlive \
    texlive-luatex \
    texlive-latex-extra \
    texlive-fonts-recommended \
    texlive-fonts-extra \
    && apt-get clean
# RUN ls /usr/local/texlive
# RUN chown -hR root /usr/local/texlive/2018
ENV PATH="/usr/local/texlive/2018/bin/x86_64-linux:${PATH}"
ENV TEXLIVE_VERSION=2018
RUN tlmgr init-usertree
RUN tlmgr option repository ftp://tug.org/historic/systems/texlive/2018/tlnet-final
RUN tlmgr update --self --all
RUN tlmgr install \
      babel \
      babel-english \
      babel-german \
      booktabs \
      textpos \
      enumitem \
      # luatex lualatex luatexbase lualatex-math eurosym \
      # above line requires tlmgr to run in -sys mode (~root?! apparently -privileged is missing)
      koma-script \
      unicode-math \
      selnolig



ARG PROJECT_DIR=/fradrive
ENV PROJECT_DIR=${PROJECT_DIR}
# RUN mkdir -p "${PROJECT_DIR}"; chmod -R 777 "${PROJECT_DIR}"
WORKDIR ${PROJECT_DIR}
ENV HOME=${PROJECT_DIR}
ENV STACK_ROOT="${PROJECT_DIR}/.stack"