Let's start from the middle.
Alpine isn't supposed to run Sublime Text at all, it's not compiled against musl therefore it won't run. Simple as that.
To be fair, Sublime Text 3 is available via Flatpak by a third-party (not officially recognized). You'll have a hard time making it work with your tools of choice since Flatpak's sandbox doesn't speak as good as promised with host machine.
Even with Flatseal installed you'll have to meddle with various environment variables, xdg-stuff, freedesktop.gnome.* flatpak installs and configs, even drop from time to time to flatpak's shell. Generally you have to hack it to make use of it. Way too much work for setting up you development environment. Boring waste of time.
But, since my aim here is to have Sublime Text 4 working on musl linux dream, all the hustle doesn't outshadow the goal. You only had to read the whole document on about how to try doing it.
I tried all the options available, but one. Here are the results:
-
gcompat
Doesn't work in my case (Sublime Text 4, MongoDB Compass GUI and few other apps).
-
GlibMus-HQ
Looked promissing, doesn't work.
-
Flatpak
As I said earlier, Sublime Text 3 works and thats it. It also looks abandoned by it's flatak author and requires flatseal to make it work normally.
-
Chroot
Works with arch chroot (doesn't work with debain or requires steps I didn't want waste time on), but it requires you to set up a non-root user environment which has it's own learning curve.
-
Docker
Not in this case, way to much isolation.
-
Distrobox + Podman
This is the one I didn't try, if you did - please leave a comment and share your experience.
-
chroot + bubblewrap
This one works pretty good, so you can customize it and have a good time.
chroot + bubblewrap
After the few first steps, taken from Alpine's own wiki about the subject:
# doas apk add bubblewrap debootstrap
# doas mkdir -p ~/chroots/debian
# doas debootstrap --arch amd64 stable ~/chroots/debian/ https://deb.debian.org/debian
(*I changed the original directory from /var/chroots/debian to ~/chroots/debian to keep it in home directory)
you'll end up with a debian chroot ready to install everything that doesn't belong to Alpine. To do it correctly, with the separation of concerns in practice, I've created two environments, one plain chroot for installing packets and dependencies I need, and the other ran by bwrap that does the actual job.
To do that I added following functions to my .zshrc:
function to start chroot
bubble_root() {
doas mount --bind /dev ~/chroots/debian/dev
doas mount --bind /dev/pts ~/chroots/debian/dev/pts
doas mount --bind /proc ~/chroots/debian/proc
doas chroot ~/chroots/debian /bin/bash
trap 'umount_bubble_root' EXIT SIGINT SIGTERM
}
function activated at trap EXIT, SIGINT or SIGTERM signals that will unmount chroot mounts
umount_bubble_root() {
echo "umounting bwrap filesystems"
doas umount ~/chroots/debian/dev/pts
doas umount ~/chroots/debian/proc
doas umount -flR ~/chroots/debian/dev
}
function that activated bubblewrap chroot
bubble() {
if ! xhost | grep -qi "local:"; then
xhost +local:
echo "added local: to xhost"
else
echo "local: is already present in xhost"
fi
echo "running command inside chroot with arguments: $@"
LANG=en_US.UTF-8 bwrap \
--bind ~/chroots/debian / \
--dev-bind /dev /dev \
--dev-bind /dev/urandom /dev/urandom \
--proc /proc \
--bind /sys /sys \
--bind /run /run \
--bind /home /home \
--ro-bind /etc/resolv.conf /etc/resolv.conf \
--ro-bind /etc/passwd /etc/passwd \
--ro-bind /etc/group /etc/group \
--bind /tmp/.X11-unix /tmp/.X11-unix \
--bind /tmp/.X11-unix/X0 /tmp/.X11-unix/X0 \
--setenv DISPLAY :0 \
/bin/bash -c 'killall gnome-keyring-daemon; eval "$(dbus-launch)"; "$@"' bash "$@"
}
After you finished adding these to your .zshrc (or .bashrc), you can source .zshrc for changes to take effect. Now you have bubble_root command that will drop to you your chroot environment (as root) and you can install packages you need using debian's package manager. In my case I followed the instruction on how to install Sublime Text 4 directly from their site.As we have set up in our script for bubble_root, exiting it will be cought by trap EXIT, SIGINT and SIGTERM signal, and unmount chroot mounts for you, so you don't have to do it yourself.
Apart from that you have bubble command that you can use with arguments. For example bubble subl will start Sublime Text 4 using bwrap+chroot.
Some explaining about bubble() function
First you should add xhost on your host machine, if you plan to use anything X related, the script will execute xhost +local: to enable connection to X from local machine. Otherwise you'll have to set .Xauthority inside bwrap's ~/ and register the client using methods I'm to lazy to write about. Just install xhost (doas apk add xhost).
Now bwrap will mount all relevant mounts to enable seamless integration of it's environment with the host, including you home directory, so you don't have to customize it separately. Everything will look and feel the same as if you are doing it on native OS.
Finally, brwap will execute /bin/bash with some additional commands:
/bin/bash -c 'killall gnome-keyring-daemon; eval "$(dbus-launch)"; "$@"' bash "$@"
Killing gnome-keyring-daemon will allow programs run from bwrap chroot to ask for password to establish keyring every time you start them. Along with eval "$(dbus-launch)" that will provide environment variable DBUS_SESSION_BUS_ADDRESS=... that will be shared between host and chroot, enabling some programs to use local keyring for their own purposes (credential store in the case of MongoDB Compass).
Integrating this setup with xfce
Before creating xfce desktop entry, I created a script /usr/bin/subl (maybe not the best place to place a script), that goes like this:
#!/bin/zsh
source ~/.zshrc
bubble subl "$@"
and did doas chmod +x /usr/bin/subl to make it run.
After that, creating a simple SublimeText.desktop file in .local/share/applications will do all the magic, so here it is:
[Desktop Entry]
Version=4.0
Name=Sublime Text
Comment=Sublime Text Editor
Exec=/usr/bin/subl
Icon=sublime-text
Terminal=false
Type=Application
Categories=Development
And you get it right here in it's category:
That's it, now you have your Sublime Text 4 fully integrated in your xfce.
Conclusion
with some shortcommings
Yes, you can run Sublime Text 4, and pretty much big deal of glibc apps this way. Happily for me, most of the apps I need already work in Alpine Linux so I don't have to do this often.
I migrated to Alpine Linux because I got bored with systemd-related distros and the vast amount of complexity one init system imposed. I embraced simplicity not only of Alpine but various other distros and BSDs. But since some apps I need live outside this little harmony, one has to do some extra steps to reach at what a true plurality means - compatibility.
Preach
If you have similar experiences to this, critiques, hate, love or questions please leave a comment, share