# Docker file for base Neovim image.
# Debian image as base (unstable for newest software).
FROM debian:unstable

RUN apt-get update && apt-get install -y locales

# Set image locale.
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
ENV TZ=America/New_York
ENV TERM=xterm-256color

# Create a non-root user with UID 1000
RUN useradd -m -u 1000 -s /usr/bin/fish shaun

# Install required software
RUN apt-get update && apt-get -y install \
  curl fzf ripgrep tree git xclip python3 python3-pip python3-venv nodejs npm \
  tzdata ninja-build gettext libtool libtool-bin autoconf automake cmake g++ \
  pkg-config zip unzip fish tmux

# Cooperate Neovim with Python 3.
RUN python3 -m pip install --break-system-packages --root-user-action ignore pynvim

# Cooperate NodeJS with Neovim.
RUN npm i -g neovim

# Install Neovim from source.
RUN mkdir -p /tmp/neovim-src && \
  git clone --depth 1 --branch stable https://github.com/neovim/neovim /tmp/neovim-src && \
  cd /tmp/neovim-src && make -j$(nproc) && make install && \
  rm -rf /tmp/neovim-src

# Clone configuration files.
USER shaun
WORKDIR /home/shaun

RUN git clone https://gitea.setlock.net/shaun/dotfiles.git /home/shaun/dotfiles

# Create directories.
RUN mkdir -p /home/shaun/.config /home/shaun/.ssh

# Softlink configuration files.
RUN ln -s /home/shaun/dotfiles/nvim /home/shaun/.config
RUN ln -s /home/shaun/dotfiles/fish /home/shaun/.config
RUN ln -s /home/shaun/dotfiles/tmux /home/shaun/.config

# Install tmux plugin manager.
RUN git clone https://github.com/tmux-plugins/tpm /home/shaun/.config/tmux/plugins/tpm && \
  /home/shaun/.config/tmux/plugins/tpm/scripts/install_plugins.sh

# Get oh-my-fish and bob-the-fish installed.
RUN curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install > install
RUN fish install --noninteractive
RUN fish -c "omf install bobthefish"

# Install Neovim plugins
RUN nvim --headless "+Lazy! sync" +qa

# Set default shell for shaun
USER root
RUN usermod --shell /usr/bin/fish shaun

# Set workspace directory
RUN mkdir -p /workspace
RUN chown -R shaun:shaun /workspace

# Switch to non-root user
USER shaun
WORKDIR /workspace

# Avoid container exit.
CMD ["tail", "-f", "/dev/null"]
