When trying to run Spotify on Alpine, most answers on the internet pointed to [Flatpak](https://flatpak.org/).
And don't get me wrong - Flatpak is great and allows for running glibc-based apps
with minimal setup, but... I'd really like to get Spotify to run natively, mostly because containers a bit heavier in terms of disk space and interoperability is .
Let's start by downloading Spotify's deb package from [the official repository](https://repository-origin.spotify.com/pool/non-free/s/spotify-client/) and unpacking it into downloads.
Most of the files are in `usr/share/spotify`, so we'll try to just go there and run it.
Error relocating ./libcef.so: __libc_realloc: symbol not found
Error relocating ./libcef.so: __libc_free: symbol not found
Error relocating ./libcef.so: __fdelt_chk: symbol not found
Error relocating ./libcef.so: __fprintf_chk: symbol not found
Error relocating ./libcef.so: __sprintf_chk: symbol not found
Error relocating ./libcef.so: initstate_r: symbol not found
Error relocating ./libcef.so: random_r: symbol not found
Error relocating ./libcef.so: gnu_get_libc_version: symbol not found
Error relocating ./libcef.so: __register_atfork: symbol not found
Error relocating ./libcef.so: __longjmp_chk: symbol not found
Error relocating ./libcef.so: __libc_stack_end: symbol not found
Error relocating ./spotify: strtoll_l: symbol not found
Error relocating ./spotify: strtoull_l: symbol not found
Error relocating ./spotify: __isnanf: symbol not found
Error relocating ./spotify: __isinff: symbol not found
Error relocating ./spotify: __isnan: symbol not found
Error relocating ./spotify: __isinf: symbol not found
Error relocating ./spotify: __cxa_thread_atexit_impl: symbol not found
```
It seems that it uses a lot of glibc-specific stuff, but we can use Adelie Linux's [gcompat](https://git.adelielinux.org/adelie/gcompat) to make it work.
Error relocating ./libcef.so: __mbrlen: symbol not found
Error relocating ./libcef.so: __close: symbol not found
Error relocating ./libcef.so: initstate_r: symbol not found
Error relocating ./libcef.so: random_r: symbol not found
```
That's much better, but there are still a few things missing. `random_r` was added
[a few months ago](https://git.adelielinux.org/adelie/gcompat/-/commit/59e99e9e6db4fd4d33786fbe3ffd3fabf4a49dd7),
but `__mbrlen` and `__close` were still missing, so I cloned gcompat and [added them in](https://github.com/ptrcnull/gcompat).
Note: gcompat seems to be temporarily no longer maintained as A. Wilcox has [retired](https://catfox.life/2020/10/21/leaving-the-linux-distribution-community/),
so I pushed my changed to a fork on GitHub instead of creating a merge request to the original repo.
After recompiling gcompat and trying to run Spotify again, it still complains about missing glibc:
and `readlink` [uses the syscall](https://github.com/bminor/musl/blob/cfdfd5ea3ce14c6abf7fb22a531f3d99518b5a1b/src/unistd/readlink.c#L5), right?
Nope, gcompat [replaces](https://git.adelielinux.org/adelie/gcompat/-/blob/current/libgcompat/readlink.c) readlink with its own function to intercept `/proc/self/exe` (ugh),
but as we don't use the loader, we can remove it from the Makefile and build again.
Another recompile of gcompat later, maybe now it would launch?
After running `gdb spotify core`, it looks like it [segfaults](https://git.adelielinux.org/adelie/gcompat/-/issues/344) in `savestate_r () from /lib/libgcompat.so.0`.
We could try to fix this _or_ we can replace it with a [fair dice roll](https://xkcd.com/221/):
Thanks to an email I got from [Filip](https://github.com/filipkania), I was finally able to make it work!
It turned out that the missing piece of the puzzle was `--single-process` - it somehow forces CEF into submission
and while it's not perfect (segfault after closing the window), it launches successfully and even plays music (tested on PulseAudio and PipeWire).
![Spotify window, with song "Oh No!" by "Marina" shown paused, partially obscured by terminal window with command "./spotify --single-process"](/posts/spotify-on-musl/working.png)