Run AppImages in NixOS without extracting them before

As you may know, appimage-run extracts the AppImage contents to some directory before running the entrypoint script. I found a way to run them without it.

An AppImage is, very simplistically, a Linux executable with a SquashFS image appended at the end. The first problem is that you can’t mount an AppImage directly because it’s an executable.

To solve that you must find the offset of that file that the SquashFS part starts. If you run the AppImage inside an FHS environment with the flag --appimage-offset, it will output a number and exit. That number you pass as the offset option when mounting and then the mount will be successful.

To mount without root privileges one can use the command udisksctl instead of mount. Both work basically the same, but for udisksctl you must create a loop device before. A convenient thing about udisksctl is that you don’t need to create an empty folder somewhere, it creates for you, but you will have to do some grep/sed wizardry to parse the paths to use later.

After mounting, you can run the file AppRun inside that mounted folder into the FHS environment and enjoy.

My implementation, so far, is not dealing nicely with cleanup, so I have to unmount and delete the loop device after using but the rest works very nice and fast.

My implementation at the current state is at [1]. I tested with an AppImage packaged windows game and it worked nicely.

EDIT1: It now deals with automatic unmount when the program doesn’t need the mount point anymore. Now I am working on a way to setup MIME stuff to make it work by just double-clicking the file.

[1] https://github.com/lucasew/nixcfg/blob/fde9b21763b428c1feb60d6bf79cd5cc6e4db548/packages/appimage-wrap.nix

3 Likes