Skip to content

flatpak2AppImage proof-of-concept #297

Open

Description

@probonopd

@Anti-Ultimate wrote in flatpak/flatpak#408 (comment)

AppImageKit draws in useless libraries from apt the binary doesn't even need, just because Library Y is in Package X which contains 10 other libraries the application isn't linked to. Those just take up space and are completely useless.

I could copy the libaries into the AppDir manually like I used to do, but this has shown not to work well in the past with newer distros containing newer versions of libraries needed. And the libraries to compile can only be found on a specific distro (namely the one which has the libraries specified in the script).

AppImages compiled against the Flatpak runtime/SDK, now that's something I would like.

Activity

  1. probonopd commented on Nov 23, 2016

    @probonopd
    MemberAuthor

    AppImageKit draws in useless libraries from apt the binary doesn't even need

    That must be a misunderstanding, AppImageKit "draws in" nothing since AppImageKit just converts AppDirs into AppImages. How you put together your AppDir is none of AppImageKit's business...

    just because Library Y is in Package X which contains 10 other libraries the application isn't linked to. Those just take up space and are completely useless.

    You can delete them as part of the AppImage generation process. Just delete them.
    What is in which "package" is determined by the packages, not by AppImageKit.

    I could copy the libaries into the AppDir manually like I used to do, but this has shown not to work well in the past with newer distros containing newer versions of libraries needed.

    Please give a concrete example with as many details as possible.

    And the libraries to compile can only be found on a specific distro (namely the one which has the libraries specified in the script).

    I don't understand, can you please explain/give an example?

    AppImages compiled against the Flatpak runtime/SDK, now that's something I would like.

    Might be doable, but then your AppImage would not run "anywhere" but only on systems with a) Flatpak and b) the appropriate Flatpak runtimes installed.

  2. alexlarsson commented on Nov 25, 2016

    @alexlarsson

    AppImages compiled against the Flatpak runtime/SDK, now that's something I would like.

    Might be doable, but then your AppImage would not run "anywhere" but only on systems with a) Flatpak and b) the appropriate Flatpak runtimes installed.

    I think he meant extracting the binaries from the app + runtime into an appimage.

    I'm not sure that is going to work well though. First of all, the runtimes are explicitly not minimal, in that a runtime has things that your specific app may not need. Also, the runtime ships its own libc and dynamic linker, and I don't think you can do that in an AppImage, can you?

  3. probonopd commented on Nov 25, 2016

    @probonopd
    MemberAuthor

    I think he meant extracting the binaries from the app + runtime into an appimage.

    That should be possible (although I am not convinced that it would be worth the effort):

    1. Extract the contents of the Flatpak package and of the runtime
    2. Determine (e.g., using ldd, strace and similar tools) the set of files from the runtime that is needed to run the app; in this case, "everything" down to glibc
    3. Arrange everything as an AppDir
    4. Convert the AppDir into an AppImage using appimagetool

    I'm not sure that is going to work well though. First of all, the runtimes are explicitly not minimal, in that a runtime has things that your specific app may not need. Also, the runtime ships its own libc and dynamic linker, and I don't think you can do that in an AppImage, can you?

    You can ship anything you want inside an AppImage; it's just that we don't recommend to do that. One just needs to make sure that the libc and linker inside the AppImage does not get mixed with libc/linker components from the outside.

    What would be cool though would be a minimal GTK Flatpak runtime of the "oldest still-supported LTS release", e.g., debian oldstable, CentOS 6.x, Ubuntu LTS-3, etc. - in this case binaries compiled against such a runtime could be converted into an AppImage that could, without bundling the Flatpak runtime, libc, or linker into the AppImage, probably reasonably be expected to run on newer systems as well.

    General background information:

    Given that AppImage is really just a self-mounting filesystem image, the person putting together an AppImage is free to choose how to produce the binaries that go inside the AppImage.

    There are different ways to generate an AppImage of an application:

    1. Convert existing binary packages (so far, we have mainly been using debian packages for that but in theory it would also be possible to use Flatpak or Snap{py, craft} ingredients), or
    2. Bundle your Travis CI builds as AppImages, or
    3. Run linuxdeployqt on your Qt application, or
    4. Use tools like electron-builder, or
    5. Write your own build scripts

    See https://github.com/probonopd/AppImageKit/wiki/Creating-AppImages for more information and examples.

  4. alexlarsson commented on Nov 25, 2016

    @alexlarsson

    Some comments:

    • You don't necessarily need to extract the flatpak stuff. Just run the AppDir generation script inside the flatpak sandbox. i.e. flatpak run --command=./generate-appdir org.the.App

    • The runtime contains more than libraries, that you may also need. For instance there are runtime-loadable plugins, python files, icons, locales, etc. A simple ldd kind of script is bound to miss a lot of things.

    • I don't see how you can ship a custom libc in and AppImage, seeing as it is tied to the exact version of the dynamc linker in the runtime, and the path to the dynamic linker is hardcoded into the binaries (INTERP). You'd need to automatically patch the ELF headers or something, which seems a bit scary.

    • flatpak apps are typically not relocatable. The runtime stuff is hardcoded to look in /usr, and the app is built into the /app prefix. This would not be the setup thats used when running the AppImage, so, while you could get the binaries from flatpak you still need manual work to make your app work as an AppImage.

  5. probonopd commented on Nov 25, 2016

    @probonopd
    MemberAuthor

    Thanks @alexlarsson.

    Is there a way to access the contents of a flatpak file on a system that does not support the extended attributes (i.e., every Live system)?

    Yes, a simple ldd kind of script is bound to miss a lot of things; this is why converting debs into an AppImage might be easier than converting a flatpak package and some parts of its runtime into an AppImage.

    We're not scared of scary things ;-)

    True about the relocateability; in the order of preference a) upstreams could use something like binreloc b) we could LD_RRELOAD something like this (discussion), c) we can binary patch the absolute to relative paths (talk about scary!)

  6. Anti-Ultimate commented on Nov 26, 2016

    @Anti-Ultimate

    Should have gotten here earlier, didn't have time really

    I want a system like AppImage, but something that would install the libraries on the user's system instead of bundling them into the AppImage itself.

    Think of the following scenario:

    • A user downloads a AppImage from a website
    • He finds that the AppImage doesn't run on his system, because his distro is too new and the creator of the AppImage copied the libraries from his Ubuntu 16.04 installation, and at the time of his testing, it did work on most distros
    • Hundreds of forum threads ("AppImage not working HELP")
    • It becomes a mess to maintain, so they decide to use AppImageAssistant to automatically get libraries from apt/the .deb package instead.
    • The resulting AppImage works, but is now large enough to contain a barebones Ubuntu chroot.
    • Later on the user finds something broke in this dev release, and wants to download a older version. Has to download the same 200MB AppImage again.

    There should be something that works similiar to AppImage and Flatpak. Let's call it flap (Flatpak and AppImage)

    The usage would be very simple:

    1. User downloads .flap file. It contains information on what runtime it uses, and the libraries not included in the runtime. (As modules, like Flatpak)
    2. Executes it. Turns out the runtime required to run the application is missing, so a nice little popup appears telling the user it is required to use the application and if to install it per user or system-wide (A link on where to get it could be added to the .json/Metadata)
    3. Runs

    Optionally this would integrate with already existing Flatpak runtimes.
    From a packager point of view, it would follow the same style as Flatpak (flatpak-builder)

    The user wouldn't have to install the runtime again for further releases and the flap file would be vastly smaller in comparison to an AppImage. This is similiar to when on Windows, an application requires the .NET 4 Framework and it asks you if you want to install it.

  7. probonopd commented on Nov 26, 2016

    @probonopd
    MemberAuthor
    • He finds that the AppImage doesn't run on his system, because his distro is too new and the creator of the AppImage copied the libraries from his Ubuntu 16.04 installation, and at the time of his testing, it did work on most distros

    The problem alwas never is that the target system is too new, since newer base systems should never cease to run older applications (if they do, it's something that needs to be fixed!)

    • Hundreds of forum threads ("AppImage not working HELP")

    Is that a hypothetical question or are you aware of such an AppImage? Most likely the AppImage in question is made wrongly

    • It becomes a mess to maintain, so they decide to use AppImageAssistant to automatically get libraries from apt/the .deb package instead.

    AppImageAssistant is deprecated and should not be used anymore.

    • The resulting AppImage works, but is now large enough to contain a barebones Ubuntu chroot.

    That's not my experience with AppImage in practice.

    • Later on the user finds something broke in this dev release, and wants to download a older version. Has to download the same 200MB AppImage again.

    Why not just keep the older AppImages around? With package managers, installing a newer version removes the older version. With AppImage, you can keep both.

    1. User downloads .flap file. It contains information on what runtime it uses, and the libraries not included in the runtime. (As modules, like Flatpak)
    1. Executes it. Turns out the runtime required to run the application is missing, so a nice little popup appears telling the user it is required to use the application and if to install it per user or system-wide (A link on where to get it could be added to the .json/Metadata)
    2. Runs

    How would this be much different from .deb/.rpm packages?

    The user wouldn't have to install the runtime again for further releases and the flap file would be vastly smaller in comparison to an AppImage.

    Yes, and it would almost never run without downloading additional stuff. Hence you would need to be online all the time, and couldn't go to a Internet Cafe, download your app and trust that it will run without additional stuff.

  8. Anti-Ultimate commented on Nov 26, 2016

    @Anti-Ultimate

    How would this be much different from .deb/.rpm packages?

    It uses runtimes supplied by flatpak and not distro specific stuff. So it would work everywhere

    Yes, and it would almost never run without downloading additional stuff. Hence you would need to be online all the time, and couldn't go to a Internet Cafe, download your app and trust that it will run without additional stuff.

    That seems to be a misunderstanding. An application would be linked against the flatpak runtime. Libraries not in the runtime would be shipped inside the image (like in AppImage).

    Also, what kind of Internet cafe doesn't have Internet? This doesn't make sense. If you know there will be slow internet, no way to get the runtime installed in time etc., you can just use an AppImage.

    In 90% of use-cases, the user is sitting at home, using his personal device. There aren't many Flatpak runtimes anyways, most Flatpaks I've seen use the Gnome runtime, and there you should target the lowest verson available anyways.

    I agree that the entire point of AppImages is to have all dependencies inside of it and making sure it runs everywhere. But I don't see much point in bundling ALL libraries with it. I don't want to download a huge AppImage everytime I want to try a new development release, especially considering that I already downloaded a previous version which contains the same libraries. A shared runtime would take up less space at one point.

    AppImageAssistant is deprecated and should not be used anymore.
    I didn't know that. What's the recommended way now?

  9. probonopd commented on Nov 26, 2016

    @probonopd
    MemberAuthor

    I agree that the entire point of AppImages is to have all dependencies inside of it and making sure it runs everywhere. But I don't see much point in bundling ALL libraries with it.

    We don't recommend to bundle all libraries, only those which cannot be expected to be part of each target system in a recent enough version.

    I don't want to download a huge AppImage everytime I want to try a new development release, especially considering that I already downloaded a previous version which contains the same libraries.

    If you are concerned about download size, check out binary delta updates using AppImageUpdate. Imagine a 6 GB app or game, which provides a nightly AppImage. You only download the bytes that actually have changed from nightly to nightly.

    If you are concerned about storage space, then Flatpak may be better suited for you.

  10. alexlarsson commented on Nov 26, 2016

    @alexlarsson

    @probonopd at the end of the day flatpaks are just ostree branches, and you can explore/explode the using the ostree command line. As long as you don't use local repos of type bare-user it should work fine without xattrs.

    I don't agree with your reasoning about too new dependencies though, which is the fundamental difference between flatpak and AppImage. I've worked for a distro for over 15 years, and I know that things change in incompatible ways. Sometimes by accident, sometimes for "good" reasons. You can blame the author of the app that he depended on the wrong thing, or you can blame the thing that changed. Neither of these help the end user though, so I choose to blame the tools that make it so hard to package things in a robust fashion. This is the reason that when you run a flatpak app you run the exact same bits that the author tested.

  11. probonopd commented on Nov 26, 2016

    @probonopd
    MemberAuthor

    @alexlarsson

    at the end of the day flatpaks are just ostree branches, and you can explore/explode the using the ostree command line. As long as you don't use local repos of type bare-user it should work fine without xattrs.

    Last time I tried

    ostree init --repo=repo --mode=bare-user
    ostree static-delta apply-offline --repo=repo LibreOffice.flatpak
    ostree checkout --repo=repo -U $(basename $(echo repo/objects/*/*.commit | cut -d/ -f3- --output-delimiter= ) .commit) outdir
    

    Using an Ubuntu Live ISO, I ended up with Unable to set xattr: Operation not supported . Is there another way to extract an ostree branch?

    I've worked for a distro for over 15 years, and I know that things change in incompatible ways. Sometimes by accident, sometimes for "good" reasons. You can blame the author of the app that he depended on the wrong thing, or you can blame the thing that changed.

    If version 2 of the operating system ceases to run applications correctly that version 1 of the operating system was able to run properly, then I blame the operating system. This is what Windows and macOS users expect from an operating system, and if Linux-based desktop OSes want to be competitive, they need to deliver on this. An application also needs to be engineered with this in mind, and it requires thoughtfulness on the part of the developer. Mozilla Firefox seems to "get it".

    Imagine a Mac user who upgrades the OS, and afterwards an application does not run properly anymore. He will certainly view this as a bug. Why should we not care about this in Linux-based OSes? By the way, Linus himself dislikes "breaking the userspace" as much as I do.

  12. alexlarsson commented on Nov 26, 2016

    @alexlarsson

    ostree init --repo=repo --mode=bare-user

    This mode uses xattrs to store file ownership and permissions, so you can commit to it as a user (its optimized for user checkouts like checkout -U). You can also use --mode=bare which stores ownership and permission as-is (optimized for regular checkout), but then you need to run the command as root as flatpak normally uses uid 0 as owner. You can use --mode=archive-z2 though, which has zero requirements on the filesystem (its the format used for e.g. http repos).

    As for operating system compatibility, I completely agree with you, and if you pick the right OS (for instance RHEL/CentOS or an Ubuntu LTS) and stay within that, then its mostly true too. I think we do worse than windows, but better than macOS in this.

    However, my target for flatpak is not an OS in the traditional sense, but more of a project, i.e. the concept of anyone running a modern linux distro/desktop. In that universe there are zero guarantees about these kind of things as there are diverging opinions about everything and nobody in control. This is the reality, and wishing it to be otherwise is fine, but doesn't change reality. When your app breaks for a user because someone else did something stupid, then blaming the someone else does not help your users.

  13. probonopd commented on Nov 29, 2016

    @probonopd
    MemberAuthor
    # Install ostree
    wget https://ftp.fau.de/debian/pool/main/o/ostree/libostree-1-1_2016.13-1_amd64.deb https://ftp.fau.de/debian/pool/main/o/ostree/ostree_2016.13-1_amd64.deb
    sudo dpkg -i *.deb
    
    # Download the GIMP Flatpak from http://209.132.179.2/repo/
    # <I am lost here>
    
  14. alexlarsson commented on Nov 30, 2016

    @alexlarsson

    Hehe, i see what you mean, its not exactly obvious how to use it.

    Here is a sample to get started:

    $ ostree init --mode=archive-z2 --repo=repo
    $ ostree remote add --repo=repo --no-gpg-verify nightly http://209.132.179.2/repo/
    $ ostree pull --repo=repo nightly app/org.gimp.GimpDevel/x86_64/master
    $ ostree checkout --repo=repo -U app/org.gimp.GimpDevel/x86_64/master gimpdir
    $ ls -l gimpdir/files
    
  15. alexlarsson commented on Nov 30, 2016

    @alexlarsson

    In fact, once you've done that you can even run the app (if you have the right runtime installed) by doing: flatpak build -r gimpdir gimp-2.9

  16. probonopd commented on Nov 30, 2016

    @probonopd
    MemberAuthor

    Continuing from above, this converts the GIMP nightly flatpak to an AppImage:

    cd gimpdir/
    wget -c https://github.com/probonopd/AppImages/raw/master/functions.sh
    . ./functions.sh
    cd files/
    get_apprun
    mkdir -p usr/
    mv etc/ bin/ lib/ share/ usr/
    get_desktop
    patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 usr/bin/gimp-2.9
    cp /usr/lib/x86_64-linux-gnu/libjpeg.so.8 usr/lib/libjpeg.so.62
    find . -type f -exec sed -i -e 's|/app|././|g' {} \;
    copy_deps
    delete_blacklisted
    cp ./usr/share/app-info/icons/flatpak/128x128/org.gimp.GimpDevel.png .
    cd ..
    mv files/ GIMP.AppDir
    APP=GIMP generate_type2_appimage 
    

    Obviously it is a bit rough around the edges (e.g., doesn't find some paths) but it runs in principle - so nothing that couldn't be solved technically, as long as the runtime it was compiled for is not newer than the target systems for the AppImage.

  17. changed the title [-]"AppImageKit draws in useless libraries from apt"[/-] [+]flatpak2AppImage proof-of-concept[/+] on Nov 30, 2016
  18. probonopd commented on Dec 3, 2016

    @probonopd
    MemberAuthor

    @alexlarsson how would I extract https://github.com/gnumdk/lollypop-data/raw/master/org.gnome.Lollypop.flatpak? I am only getting files with cryptic names like ./objects/1c/3383ad809a2b148736d8b0958bc2c67d8e6898d18e50114848256764f6c120.filez.

    A command like ostree extract org.gnome.Lollypop.flatpak would really come handy.

    Newer AppImages have --appimage-extract for similar functionality.

  19. alexlarsson commented on Dec 3, 2016

    @alexlarsson

    @probonopd That is an ostree repo, kinda like the .git directory. You can list the branches (refs) in it with ostree --repo=DIR refs and then check one out (there should be only one if you created from a flatpak bundle) with ostree --repo=DIR checkout -U REF DESTDIR

  20. TheAssassin commented on Jun 5, 2017

    @TheAssassin
    Member

    Related to #166.

  21. sudo-give-me-coffee commented on Mar 17, 2020

    @sudo-give-me-coffee
  22. probonopd commented on Mar 18, 2020

    @probonopd
    MemberAuthor

    Trying to run it on Travis CI using https://github.com/probonopd/flatpak2appdir/blob/patch-2/.travis.yml, getting

    [ 7/7 ] Copying used files...
    + touch /tmp/tmp.mZUICFB36d/test
    + chroot /tmp/tmp.mZUICFB36d /AppRun gedit
    Python 3.7.4
    **
    GLib:ERROR:../glib/gspawn.c:1362:do_exec: assertion failed: (read_null != -1)
    Bail out! GLib:ERROR:../glib/gspawn.c:1362:do_exec: assertion failed: (read_null != -1)
    **
    GLib:ERROR:../glib/gspawn.c:1362:do_exec: assertion failed: (read_null != -1)
    Bail out! GLib:ERROR:../glib/gspawn.c:1362:do_exec: assertion failed: (read_null != -1)
    (gedit:5241): dconf-WARNING **: 00:49:52.481: failed to commit changes to dconf: Error spawning command line “dbus-launch --autolaunch= --binary-syntax --close-stderr”: Child process killed by signal 6
    (gedit:5241): dconf-WARNING **: 00:49:52.481: failed to commit changes to dconf: Error spawning command line “dbus-launch --autolaunch= --binary-syntax --close-stderr”: Child process killed by signal 6
    **
    GLib:ERROR:../glib/gspawn.c:1362:do_exec: assertion failed: (read_null != -1)
    Bail out! GLib:ERROR:../glib/gspawn.c:1362:do_exec: assertion failed: (read_null != -1)
    

    Do you have an idea what this means?

    Full log:
    https://travis-ci.com/github/probonopd/flatpak2appdir/builds/153835938

  23. probonopd commented on Mar 18, 2020

    @probonopd
    MemberAuthor

    Looks like I succeeded making an AppDir, however AppRun is missing:
    https://travis-ci.com/github/probonopd/flatpak2appdir/builds/153838734

    Do you have an idea why?

  24. sudo-give-me-coffee commented on Mar 18, 2020

    @sudo-give-me-coffee

    Do you have an idea what this means?

    Even with these errors, it works most of the time, I know how these errors occurred, but I have no idea how to fix, i need a Way to start a dbus section under chroot

    Do you have an idea why?

    Yes, is intentionally for while, this is only a PoC they not search for desktop file and other important things, start-app.sh does near to samething that AppRun

  25. probonopd commented on Mar 18, 2020

    @probonopd
    MemberAuthor
  26. probonopd commented on Mar 22, 2020

    @probonopd
    MemberAuthor

    In the meantime, I have been experimenting with a cleaner way to do this, possibly without the need for LD_PRELOAD.

    @alexlarsson

    First of all, the runtimes are explicitly not minimal, in that a runtime has things that your specific app may not need.

    "Almost" solved. Let's say, we can find a solution to that. Right now we have two different approaches that are working to some degree:

    @alexlarsson is correct though,

    A simple ldd kind of script is bound to miss a lot of things.

    So the list of files may need some manual per-app tweaking.

    @alexlarsson

    Also, the runtime ships its own libc and dynamic linker, and I don't think you can do that in an AppImage, can you?

    Yes, we can do that. This has always been possible with AppImage. After all, an AppImage is really just a filesystem image that executes whatever someone has put inside. It is perfectly fine to put a full runtime in there, including ld-linux and everything. (So far, we have simply recommended against doing so for space saving reasons - in reality, the overhead can be pretty low though.) Here are some experimental AppImages that contain what was inside a Flatpak /app, as well as a subset of the Flatpak runtime:

    https://github.com/probonopd/assembly-service/releases/tag/continuous

    This should address @alexlarsson's concern

    I don't agree with your reasoning about too new dependencies though, which is the fundamental difference between flatpak and AppImage. I've worked for a distro for over 15 years, and I know that things change in incompatible ways.

    Now, they seem to be broken in various subtle ways. I suspect this is because we are not running them trough bubblewrap or something like it.

    Which brings me to the questions:

    1. Given an /app and a /runtime directory, can one somehow execute bubblewrap so that it runs the main executable as if it was invoked through Flatpak?
    2. Can bubblewrap be made to work without the need for suid, e.g., if one entirely disregards the security aspect? Then we could put bubblewrap into the AppImage, execute it, and call it a day
    3. If not, can a replacement for bubblewrap be written e.g,. in the form of a patched ld-linux or LD_PRELOAD that, given an /app and a /runtime directory, could run the main executable?

    Why do I think running bubblewrap (or an unprivileged replacement of it) is needed:

    • Applications may have /app paths compiled in, as @alexlarsson said Flatpak doesn't require apps to be relocatable in the filesystem
    • Applications may launch other binaries (e.g., Peek is launching ffmpeg). This currently fails because Peek launches ffmpeg directly, without us having a chance to invoke it through our privately bundled ld-linux

    This is what @alexlarsson pointed out:

    the path to the dynamic linker is hardcoded into the binaries (INTERP). You'd need to automatically patch the ELF headers or something, which seems a bit scary.

    Hence the question, can we use bubblewrap to do the job.

    Any ideas/help appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions