Creating A Cloud Development Environment with code-server and nix shell
tl;dr: Install nix-shell in the code-server to have a nice development environment within the container. See Dockerfile below.
Sometimes when I’m traveling, I’d like to use some time and write a blog post or develop small things on my homelab.

The way I did it til now
Usually, when I don’t have my notebook with me I use my Chromebook to connect via Wireguard + SSH to my homelab and use a CLI editor to edit files etc.
But this is not so comfortable when using a phone or tablet. Navigation can get quite painful. And as I’m used to VSCode (or IntelliJ) I’d like to use them in such cases, too.
Using code-server
Luckily cloud development environments are spreading right now and there’s a way to host VSCode in the cloud. One of it is using code-server which can be executed as a container. So, whenever I don’t need it I can just stop or remove it.
One downside of it: Dependencies like hugo or node are not available in the container.
But some of my private projects use nix-shell to serve an easy replicable development environment.
So, it would be nice to use this in the development environment, too.
The Dockerfile
To achieve this I’ve created an overlay of the code-server. Check the Dockerfile below.
Keep the license in mind (= GPL-3.0).
FROM lscr.io/linuxserver/code-server:latest
# Install dependencies for curl
RUN apt-get update && \
apt-get install -y xz-utils && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Create directory for nix
RUN mkdir /nix
RUN curl -L https://nixos.org/nix/install | sh -s -- --daemon
# Run nix-daemon
CMD ["/nix/var/nix/profiles/default/bin/nix-daemon", "--daemon"]
# Set the environment variable to use nix
ENV NIX_PROFILES="/nix/var/nix/profiles/default /root/.nix-profile"
ENV NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs"
ENTRYPOINT ["/init"]
Usage
To use it you have to do the following:
- Save the
Dockerfile. - Build with
docker build -t code-server-nix . - Use the image (
code-server-nix) as the image for your code-server. See the documentation of code-server at Docker hub how to do it. When usingdocker composejust replace the image name withimage: code-server-nix.
Conclusion
The presented Dockerfile shows how to make nix-shell in the code-server container available.
Now, when you have a project with a shell.nix file you can execute nix-shell as you’re used to. This enables you to have a nice dependency-management across your machines without having to install everything everywhere natively.