FROM ubuntu:22.04


#
# General boiler plate
#


# Ready image for installation

ARG DEBIAN_FRONTEND=noninteractive

RUN apt update -y && apt upgrade -y

# Install generic dependencies

RUN apt install git python3 python3-pip sudo -y

# Set up user

ARG UNAME=dev
ARG UID=1000
ARG GID=1000
RUN groupadd -g $GID -o $UNAME
RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME
RUN adduser $UNAME sudo
RUN echo "%sudo ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers.d/nopassword


#
# Install neovim 
#


# Install neovim

WORKDIR /tmp
RUN git clone https://github.com/neovim/neovim.git
WORKDIR /tmp/neovim
RUN git checkout stable
RUN apt install ninja-build gettext cmake unzip curl -y
RUN make CMAKE_BUILD_TYPE=Release -j `nproc` && make install
WORKDIR /

# Install package dependencies

RUN python3 -m pip install pynvim                                                              # python3 provider
RUN python3 -m pip install jupytext                                                            # jupytext requirements
RUN apt install fd-find ripgrep -y                                                             # Telescope requirements
RUN apt install fonts-powerline -y                                                             # vim-airline requirements
RUN python3 -m pip install neovim-remote                                                       # vimtex requirements
RUN apt install curl -y                                                                        # vim-doge requirements
RUN apt install npm python3-venv luarocks -y                                                   # mason build requirements
RUN python3 -m pip install cairosvg pnglatex plotly kaleido pyperclip jupyter-client ipykernel # molten requirements

# Configure

RUN mkdir -p "/home/${UNAME}/.config/nvim"
COPY . "/home/${UNAME}/.config/nvim"
RUN chown -R $UNAME:$UNAME "/home/${UNAME}/.config"
USER $UNAME
RUN nvim --headless "+Lazy! sync" +qa
RUN nvim --headless "+MasonInstall clangd pyright cmake-language-server bash-language-server texlab clang-format latexindent mdformat autopep8" +qa
RUN nvim --headless "+TSInstallSync markdown" +qa  # For some reason, without this markdown installation fails the first time
USER root


#
# Install other tools
#


# Install firefox
# (Taken from https://askubuntu.com/a/1404401)

RUN apt install software-properties-common -y
RUN add-apt-repository ppa:mozillateam/ppa
RUN echo '\n\
Package: *\n\
Pin: release o=LP-PPA-mozillateam\n\
Pin-Priority: 1001\n\n\
Package: firefox\n\
Pin: version 1:1snap1-0ubuntu2\n\
Pin-Priority: -1\n\
' | tee /etc/apt/preferences.d/mozilla-firefox
RUN apt install firefox -y
RUN echo 'Unattended-Upgrade::Allowed-Origins:: "LP-PPA-mozillateam:${distro_codename}";' | tee /etc/apt/apt.conf.d/51unattended-upgrades-firefox

# Other stuff

RUN apt install fzf xclip -y

USER $UNAME
WORKDIR /home/$UNAME
CMD /bin/bash

