Newbie question about running AppImage

How to run “AppImage” extensions easily?

For example, this: LM Studio Beta Releases

When we download it and try to execute we receive the error:

bash: ./LM_Studio-0.2.14-beta-1.AppImage: cannot execute: required file not found

I had the same issue with the SQLiteStudio, for example, and I solved that with a very weird .nix file:

{ pkgs ? import <nixpkgs> { } }:

let
  qt = pkgs.qt515;
  sqliteStudioPath = "/home/xxx/app/SQLiteStudio";  
in
pkgs.mkShell {
  # Just for some extra debug-useful visibility
  QT_DEBUG_PLUGINS = 1;

  LD_LIBRARY_PATH = with pkgs; pkgs.lib.makeLibraryPath [
    qt5.full
    zlib
    krb5
    glib
    patchelf
    readline
    stdenv.cc.cc
    libGL
    zlib
    glib # libgthread-2.0.so
    xorg.libX11 # libX11-xcb.so
    xorg.libxcb # libxcb-shm.so
    xorg.xcbutilwm # libxcb-icccm.so
    xorg.xcbutil # libxcb-util.so
    xorg.xcbutilimage # libxcb-image.so
    xorg.xcbutilkeysyms # libxcb-keysyms.so
    xorg.xcbutilrenderutil # libxcb-renderutil.so
    xorg.xcbutilrenderutil # libxcb-renderutil.so
    dbus # libdbus-1.so
    libxkbcommon # libxkbcommon-x11.so
    fontconfig
    freetype
  ];

  shellHook = ''
    export LD_LIBRARY_PATH=${sqliteStudioPath}/lib:${pkgs.libGL.out}/lib:${pkgs.zlib.out}/lib:${pkgs.glib.out}/lib:${pkgs.qt5.full.out}/lib:${pkgs.xorg.libX11.out}/lib:${pkgs.xorg.libxcb.out}/lib:${pkgs.xorg.xcbutilwm.out}/lib:${pkgs.xorg.xcbutil.out}/lib:${pkgs.xorg.xcbutilimage.out}/lib:${pkgs.xorg.xcbutilkeysyms.out}/lib:${pkgs.xorg.xcbutilrenderutil.out}/lib:${pkgs.dbus.out}/lib:${pkgs.libxkbcommon.out}/lib:${pkgs.fontconfig.out}/lib:${pkgs.freetype.out}/lib:$LD_LIBRARY_PATH
    patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" ./sqlitestudio
    patchelf --set-rpath "${pkgs.libGL.out}/lib:${pkgs.zlib.out}/lib:${pkgs.glib.out}/lib:${pkgs.qt5.full.out}/lib:${pkgs.xorg.libX11.out}/lib:${pkgs.xorg.libxcb.out}/lib:${pkgs.xorg.xcbutilwm.out}/lib:${pkgs.xorg.xcbutil.out}/lib:${pkgs.xorg.xcbutilimage.out}/lib:${pkgs.xorg.xcbutilkeysyms.out}/lib:${pkgs.xorg.xcbutilrenderutil.out}/lib:${pkgs.dbus.out}/lib:${pkgs.libxkbcommon.out}/lib:${pkgs.fontconfig.out}/lib:${pkgs.freetype.out}/lib" ./sqlitestudio
    export QT_PLUGIN_PATH="${pkgs.qt5.qtbase.bin}/lib/qt-${pkgs.qt5.qtbase.version}/plugins/platforms"
  '';
}

But to do that I made a lot of trial and error + Google + ChatGPT.

There is an easy way to run an AppImage without creating a bizarre nix file?

There is an old topic here: Can’t run an AppImage app but I think it’s too old (2020). The solution is the same yet? Using pkgs.appimageTools ?

Thank you.

OK. Replying myself:

Just install the package “appimage-run” and:

appimage-run <whatever>.AppImage

4 Likes

It doesn’t work :frowning:

It says that the appimage is installed

[user@nixos:~/Downloads]$ appimage-run Snipaste 
Snipaste installed in /home/user/.cache/appimage-run/549bf0dccd4e85f8e2fcfa08c67e2073d29c165e87d704585b93db7f5a79ae5

But when trying to actually launch the app, it doesn’t

[user@nixos:~/Downloads]$ cd /home/user/.cache/appimage-run/549bf0dccd4e85f8e2fcfa08c67e2073d29c165e87d704585b93db7f5a79ae58

[user@nixos:~/.cache/appimage-run/549bf0dccd4e85f8e2fcfa08c67e2073d29c165e87d704585b93db7f5a79ae58]$ ls -lah
total 24K
drwxr-xr-x 3 user users 4.0K Apr 27 14:35 .
drwxr-xr-x 3 user users 4.0K Apr 29 00:03 ..
lrwxrwxrwx 1 user users   16 Apr 27 14:33 AppRun -> usr/bin/Snipaste
-rw-r--r-- 1 user users 1.5K Dec 27 03:37 .DirIcon
-rw-r--r-- 1 user users  392 Apr 27 14:35 Snipaste.desktop
-rw-r--r-- 1 user users 1.4K Apr 27 14:33 Snipaste.png
drwxrwxr-x 6 user users 4.0K Apr 27 14:34 usr

[user@nixos:~/.cache/appimage-run/549bf0dccd4e85f8e2fcfa08c67e2073d29c165e87d704585b93db7f5a79ae58]$ ./AppRun 
bash: ./AppRun: cannot execute: required file not found

[user@nixos:~/.cache/appimage-run/549bf0dccd4e85f8e2fcfa08c67e2073d29c165e87d704585b93db7f5a79ae58]$ appimage-run AppRun 
Not an AppImage file

[user@nixos:~/.cache/appimage-run/549bf0dccd4e85f8e2fcfa08c67e2073d29c165e87d704585b93db7f5a79ae58]$ ./usr/bin/Snipaste 
bash: ./usr/bin/Snipaste: cannot execute: required file not found

[user@nixos:~/.cache/appimage-run/549bf0dccd4e85f8e2fcfa08c67e2073d29c165e87d704585b93db7f5a79ae58]$ 

Maybe you should try deleting the cache directory and opening the AppImage again.

Also, as a tip, if you want to open AppImages normally, you can follow the instructions in the Register AppImage files as a binary type to binfmt_misc section of the NixOS wiki.

1 Like

Thank you for the reply! I’ve followed your instructions:

  1. Deleted the cache
[user@nixos:~]$ rm -rf ~/.cache/appimage-run/
  1. Registered Appimage files as binary type
[user@nixos:~]$ cat /etc/nixos/configuration.nix
{
...
  boot.binfmt.registrations.appimage = {
    wrapInterpreterInShell = false;
    interpreter = "${pkgs.appimage-run}/bin/appimage-run";
    recognitionType = "magic";
    offset = 0;
    mask = ''\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff'';
    magicOrExtension = ''\x7fELF....AI\x02'';
  };
...
}


[user@nixos:~]$ sudo nixos-rebuild switch
building Nix...
building the system configuration...
activating the configuration...
setting up /etc...
reloading user units for user...
setting up tmpfiles

  1. Run the Appimage normally
[user@nixos:~/Downloads]$ appimage-run Snipaste 
Uncompress Snipaste of type 02 @ offset 189632
[======================================================================================================================================|] 929/929 100%
Snipaste is now installed in /home/user/.cache/appimage-run/549bf0dccd4e85f8e2fcfa08c67e2073d29c165e87d704585b93db7f5a79ae58

[user@nixos:~/Downloads]$ cd /home/user/.cache/appimage-run/549bf0dccd4e85f8e2fcfa08c67e2073d29c165e87d704585b93db7f5a79ae58

[user@nixos:~/.cache/appimage-run/549bf0dccd4e85f8e2fcfa08c67e2073d29c165e87d704585b93db7f5a79ae58]$ ./AppRun 
bash: ./AppRun: cannot execute: required file not found

But it still treated appimage like an archive, and still the “binaries” don’t work. I just started using NixOS and probably I’m missing something crucial, can you please help me?

Try running it directly without appimage-run. You should be able to since you’ve registered it as a binary type. If that doesn’t work, it’s likely an issue with the appimage expecting a dependency not included in appimage-run. You can also try using steam-run ./{appimage}

I do not know if it is worth encouraging this approach, but my personal approach has been to use Nix-LD for this, as I recently mentioned in another thread. I hope it’s not a problem to keep linking to my own personal configuration, but my configuration for this can be found here.

It currently looks like this, omitting comments and unrelated bits:

{ pkgs, ... }:
{
  config = {
    programs.nix-ld = {
      enable = true;
      libraries = with pkgs; [
        fuse
        desktop-file-utils
        xorg.libXcomposite
        xorg.libXtst
        xorg.libXrandr
        xorg.libXext
        xorg.libX11
        xorg.libXfixes
        libGL

        gst_all_1.gstreamer
        gst_all_1.gst-plugins-ugly
        gst_all_1.gst-plugins-base
        libdrm
        xorg.xkeyboardconfig
        xorg.libpciaccess

        glib
        gtk2
        bzip2
        zlib
        gdk-pixbuf

        xorg.libXinerama
        xorg.libXdamage
        xorg.libXcursor
        xorg.libXrender
        xorg.libXScrnSaver
        xorg.libXxf86vm
        xorg.libXi
        xorg.libSM
        xorg.libICE
        freetype
        curlWithGnuTls
        nspr
        nss
        fontconfig
        cairo
        pango
        expat
        dbus
        cups
        libcap
        SDL2
        libusb1
        udev
        dbus-glib
        atk
        at-spi2-atk
        libudev0-shim

        xorg.libXt
        xorg.libXmu
        xorg.libxcb
        xorg.xcbutil
        xorg.xcbutilwm
        xorg.xcbutilimage
        xorg.xcbutilkeysyms
        xorg.xcbutilrenderutil
        libGLU
        libuuid
        libogg
        libvorbis
        SDL
        SDL2_image
        glew110
        openssl
        libidn
        tbb
        wayland
        mesa
        libxkbcommon
        vulkan-loader

        flac
        freeglut
        libjpeg
        libpng12
        libpulseaudio
        libsamplerate
        libmikmod
        libtheora
        libtiff
        pixman
        speex
        SDL_image
        SDL_ttf
        SDL_mixer
        SDL2_ttf
        SDL2_mixer
        libappindicator-gtk2
        libcaca
        libcanberra
        libgcrypt
        libvpx
        librsvg
        xorg.libXft
        libvdpau
        alsa-lib

        harfbuzz
        e2fsprogs
        libgpg-error
        keyutils.lib
        libjack2
        fribidi
        p11-kit

        gmp

        libtool.lib
        xorg.libxshmfence
        at-spi2-core
        gtk3
        stdenv.cc.cc.lib
      ];
    };
  };
}

This has the benefit of making a lot of standalone Linux binaries “just work” as long as they don’t make too many assumptions about FHS, it doesn’t interfere with the operation of patched binaries in the Nix store. and it isn’t broken by LD_LIBRARY_PATH getting changed somewhere between the wrapper and the actual executables. I also use this configuration to make sure /bin/bash exists:

{
  system.activationScripts.binbash = ''
    mkdir -m 0755 -p /bin
    ln -sfn "${pkgs.bash.out}/bin/bash" "/bin/.bash.tmp"
    mv "/bin/.bash.tmp" "/bin/bash"
  '';
}

I’m not sure if it is considered an idiomatic solution but I find it to be incredibly effective.

1 Like

For deemix-gui I was able to make a simple a derivation like so:

# deemix-gui.nix
{ lib
, stdenv
, appimageTools
, fetchurl
}:

appimageTools.wrapType1 rec {
  name = "deemix-gui";
  src = fetchurl {
      url = "https://archive.org/download/deemix/gui/linux-x64-latest.AppImage";
      sha256 = "10sd50kwqb64zzwmig0bhqgd14lkra33vj4m0vi6kk00ddxdwsbv";
  };
  extraPkgs = pkgs: with pkgs; [];
}

and run it with callPackage ./deemix-gui.nix {} in a default.nix and this gives a working app in ./result.

The wrapType you need is discussed here in the manual. Hopefully this works for you :slight_smile: