systemd-nspawn based dev environment

Over the last week, I decided to move my dev environment from OSX to my own Archlinux box. Now I didn’t want to pollute my machine with various libraries/tools needed for work so I decided to run things in a container. I had played with systemd-nspawn in the past so it was the clear first choice (and last in this case). Overall I am very happy with it as it was a piece of cake to setup and only one or two hiccups along the way.

I followed the excellent guide on Archlinux Wiki and that took me 95% of the way. Firefox tweaks page took me 99% there. What follows are some tips for the last mile.

Running GUI programs

Following makes available the paths needed to talk and authenticate with X Window:

systemd-nspawn -b -M name -D /sys-root-path \
  --bind-ro=/home/host-user/.Xauthority:/home/guest-user/.Xauthority \
  --bind=/tmp/.X11-unix

You need to set some environment variables in the guest as well. To have them available every time you login, you could put them at the top of your ~/.bashrc for instance:

export DISPLAY=:0
export XAUTHORITY=~/.Xauthority

If you happen to have set /etc/hostname in your guest set to a different name than your host, you won’t be able to run X programs with No protocol specified as the most likely error. You can get around this by whitelisting all non-network local connections to X:

xhost +local: