Skip to content

Instantly share code, notes, and snippets.

@genotrance
Last active November 8, 2024 16:27
Show Gist options
  • Save genotrance/ae4781da3899828d874a2c62420ccf00 to your computer and use it in GitHub Desktop.
Save genotrance/ae4781da3899828d874a2c62420ccf00 to your computer and use it in GitHub Desktop.
nvim + Lazyvim + Docker
FROM ubuntu
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y git
RUN apt-get install -y python3 python3-venv python3-pip
RUN apt-get install -y gcc make gzip unzip curl wget
RUN apt-get install -y ripgrep fd-find
RUN apt-get install -y lua5.1
RUN LAZYGIT="$(git ls-remote --tags --sort='v:refname' https://github.com/jesseduffield/lazygit | tail --lines=1 | cut --delimiter='v' --fields=2)" && \
mkdir /opt/lazygit && \
wget "https://github.com/jesseduffield/lazygit/releases/download/v${LAZYGIT}/lazygit_${LAZYGIT}_Linux_x86_64.tar.gz" -O lazygit.tar.gz && \
tar xvzf lazygit.tar.gz -C /opt/lazygit && \
rm lazygit.tar.gz
RUN NEOVIM="$(git ls-remote --tags --sort='v:refname' https://github.com/neovim/neovim | tail --lines=1 | cut --delimiter='v' --fields=2 | cut --delimiter='^' --fields=1)" && \
wget "https://github.com/neovim/neovim/releases/download/v${NEOVIM}/nvim-linux64.tar.gz" && \
tar xvzf nvim-linux64.tar.gz -C /opt && \
rm nvim-linux64.tar.gz
RUN wget "http://luarocks.github.io/luarocks/releases/luarocks-3.11.1-linux-x86_64.zip" -O luarocks.zip && \
unzip luarocks.zip -d /opt && \
rm luarocks.zip
ENV PATH="/opt/nvim-linux64/bin:/opt/lazygit:/opt/luarocks-3.11.1-linux-x86_64:/opt/venv/bin:$PATH"
RUN python3 -m venv /opt/venv
RUN pip install --no-cache-dir neovim
RUN NVM_DIR="/opt/nvm" && \
git clone --depth=1 https://github.com/nvm-sh/nvm.git "$NVM_DIR" && \
. "$NVM_DIR/nvm.sh" && \
nvm install node && \
npm install -g neovim
WORKDIR /home
CMD ["bash", "-c", ". /opt/nvm/nvm.sh && nvim"]
#! /bin/bash
TZ=America/Chicago
MOUNTS="$HOME /mnt"
REALPATH=$(realpath "$0")
SCRIPTDIR=$(dirname "$REALPATH")
DATA=$HOME/.nvim
if [[ "$1" == "--build" ]]; then
docker rmi nvim -f
docker build -t nvim -f "$SCRIPTDIR/Dockerfile" .
elif [[ "$1" == "--setup" ]]; then
mkdir -p $DATA
rm -rf $DATA/*
git clone https://github.com/LazyVim/starter $DATA/config/nvim
mkdir -p $DATA/share $DATA/state $DATA/cache
cp core.lua $DATA/config/lua/plugins/.
else
VOLUMES=""
for mount in $MOUNTS; do
VOLUMES+=" -v $mount:$mount"
done
docker run -it --rm \
$VOLUMES \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-v $DATA/config:$HOME/.config/nvim \
-v $DATA/cache:$HOME/.cache/nvim \
-v $DATA/share:$HOME/.local/share/nvim \
-v $DATA/state:$HOME/.local/state/nvim \
-e HOME=$HOME -e LANG=C.UTF-8 -e LC_ALL=C.UTF-8 -e TZ=$TZ \
--user "$(id -u):$(id -g)" \
-w "$PWD" \
nvim bash -c ". /opt/nvm/nvm.sh && nvim $@"
fi
@genotrance
Copy link
Author

Run nvim with Lazyvim setup in a Docker container with data stored in $HOME per usual. Does not require any changes to main system.

# Build the container that includes nvim, python, node, luarocks, lazygit
./nvim.sh --build 

# Setup lazyvim in $HOME - customizations in core.lua will be copied over
./nvim.sh --setup

# Setup an alias
alias nvim=/path/to/nvim.sh
alias vi=nvim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment