Using emacsclient inside of an Arch chroot
2019-11-18
Introduction
I just figured out how to get emacsclient working in an arch linux chroot. I use an arch chroot on alpine linux anytime there is some program that needs glibc, like the Android SDK tools or the buildroot environment I use to develop custom software for the norns and the LDK. Being able to edit files from the chroot using emacs makes things very convenient.
This hack has a special kind of cleverness to it that makes it particularly awful, so I just had to share.
Install arch chroot
This starts with having a configure arch chroot.
This needs to have emacsclient installed via pacman
. I
also had added an account with matching user name.
All the chroot stuff is held in a folder /home/paul/arch
,
with the chroot dir in /home/paul/arch/chroot64
.
Starting emacs server
I start up the emacs server inside of emacs using
M-x server-start
. Emacs is started on Alpine linux,
the host computer.
Making the socket visible to chroot environment
I was able to figure out via netstat -lp
that emacs server
socket was stored in /tmp/emacs1000
.
So, making the socket visible to chroot environment was a
matter of linking that folder via mount. Not entirely sure
what -o bind
does exactly, but I saw it used elsewhere
in the chroot tutorial linked above.
cd chroot64
mkdir -p tmp/emacs1000
mount -o bind /tmp/emacs1000 tmp/emacs1000
Making it save to the right filepath (the hack)
Using emacsclient on arch linux should open up the file in
emacs. Hooray! But, emacs does not understand the chroot
file path. So, when I open the file /home/paul/foo.txt
from within the chroot environment, it will save it as
/home/paul/foo.txt
in my host environment, and not
/home/paul/arch/chroot64/home/paul/foo.txt
. Oops.
My solution to this? Abuse file links to make the paths match.
Luckily, my guest + host user names + home directories are the same, so that's a good first start.
On my alpine host, I make a symbolic link to my chroot arch linux home directory with
ln -s chroot/home/paul paul
So now I have a link /home/paul/arch/paul
.
Inside the arch chroot environment, I make a folder called arch, and create the equivalent symlink in there.
# inside the chroot
cd ~
mkdir arch
cd arch
ln -s ~ paul
Bam! Now the path /home/paul/arch/paul
is equivalent on
both my host and guest computers, and emacs will
be able to save in the correct place.
Pretty terrible, right?