A quick introduction to Flatpak

Releasing ISV applications on Linux is often hard. The ABI of all the libraries you need changes seemingly weekly. Hence you have the option of bundling the world, or building a thousand releases to cover a thousand distribution versions. As a case in point, when MonoDevelop started bundling a C Git library instead of using a C# git implementation, it gained dependencies on all sorts of fairly weak ABI libraries whose exact ABI mix was not consistent across any given pair of distro releases. This broke our policy of releasing “works on anything” .deb and .rpm packages. As a result, I pretty much gave up on packaging MonoDevelop upstream with version 5.10.

Around the 6.1 release window, I decided to take re-evaluate question. I took a closer look at some of the fancy-pants new distribution methods that get a lot of coverage in the Linux press: Snap, AppImage, and Flatpak.

I started with AppImage. It’s very good and appealing for its specialist areas (no external requirements for end users), but it’s kinda useless at solving some of our big areas (the ABI-vs-bundling problem, updating in general).

Next, I looked at Flatpak (once xdg-app). I liked the concept a whole lot. There’s a simple 3-tier dependency hierarchy: Applications, Runtimes, and Extensions. An application depends on exactly one runtime.  Runtimes are root-level images with no dependencies of their own. Extensions are optional add-ons for applications. Anything not provided in your target runtime, you bundle. And an integrated updates mechanism allows for multiple branches and multiple releases parallel-installed (e.g. alpha & stable, easily switched).

There’s also security-related sandboxing features, but my main concerns on a first examination were with the dependency and distribution questions. That said, some users might be happier running Microsoft software on their Linux desktop if that software is locked up inside a sandbox, so I’ve decided to embrace that functionality rather than seek to avoid it.

I basically stopped looking at this point (sorry Snap!). Flatpak provided me with all the functionality I wanted, with an extremely helpful and responsive upstream. I got to work on trying to package up MonoDevelop.

Flatpak (optionally!) uses a JSON manifest for building stuff. Because Mono is still largely stuck in a Gtk+2 world, I opted for the simplest runtime, org.freedesktop.Runtime, and bundled stuff like Gtk+ into the application itself.

Some gentle patching here & there resulted in this repository. Every time I came up with an exciting new edge case, upstream would suggest a workaround within hours – or failing that, added new features to Flatpak just to support my needs (e.g. allowing /dev/kvm to optionally pass through the sandbox).

The end result is, as of the upcoming 0.8.0 release of Flatpak, from a clean install of the flatpak package to having a working MonoDevelop is a single command: flatpak install --user --from https://download.mono-project.com/repo/monodevelop.flatpakref 

For the current 0.6.x versions of Flatpak, the user also needs to flatpak remote-add --user --from gnome https://sdk.gnome.org/gnome.flatpakrepo first – this step will be automated in 0.8.0. This will download org.freedesktop.Runtime, then com.xamarin.MonoDevelop; export icons ‘n’ stuff into your user environment so you can just click to start.

There’s some lingering experience issues due the sandbox which are on my radar. “Run on external console” doesn’t work, for example, or “open containing folder”. There are people working on that (a missing DBus# feature to allow breaking out of the sandbox). But overall, I’m pretty happy. I won’t be entirely satisfied until I have something approximating feature equivalence to the old .debs.  I don’t think that will ever quite be there, since there’s just no rational way to allow arbitrary /usr stuff into the sandbox, but it should provide a decent basis for a QA-able, supportable Linux MonoDevelop. And we can use this work as a starting point for any further fancy features on Linux.

Gtk# app development in Flatpak MonoDevelop

Editing MonoDevelop in MonoDevelop. *Inception noise*

6 Responses to “A quick introduction to Flatpak”

  1. So what would we need to do to develop gtksharp3 applications using a flatpak’d mono and monodevelop?


    directhex Reply:

    Good question.

    The ideal would be for there to be a Mono Runtime of some kind, which apps could build against – include stuff like Mono, Gtk#, etc, in there.

    Problem is, as long as MonoDevelop is bound to Gtk#2, MonoDevelop couldn’t use the Mono runtime, which is… well, pretty silly really.

    I’m open to some discussion on the topic, especially if we could get the current Gtk# maintainers involved. In a glorious future where Mono picks up again for Linux desktop app dev, I think a runtime is a great strategy, but today, I think it’d be a lot of work for little benefit, and easier for individual apps to just include their own certified version of Mono in their bundle.


  2. Wow, great job. It’s awesome to have the official releases packages for just about any linux distribution out there.

    One thing I’m noticing is that the desktop theming does not seem to be applied to MonoDevelop running in flatpak (cursors, colors, fonts). Is that something which needs to be addressed in flakpak or the MonoDevelop package?


    directhex Reply:

    A bit of both. Desktop theming can rely on theme engines, which can be in .so form, so in those cases trying to just pass through the theme could break stuff. Cursors should probably be passed through – I’ll file a bug with Flatpak, if I remember.

    Fonts… are complicated. There are two levels of problem – fonts from outside being available inside, and fontconfig’s fallthrough of missing fonts to similar ones being completely and entirely awful. I was gonna post a link to where I gave up & hardcoded Arial for the welcome screen in Flatpak MonoDevelop (to avoid it picking some silly ultra-slim font), but GitHub is down, so you’ll have to take my word for it.


  3. For what its worth, if I run the Monodevelop flatpak as the following:

    flatpak run –runtime=org.gnome.Platform/x86_64/3.22 com.xamarin.MonoDevelop

    then include the availble gtk-sharp3 3.22 package from nuget then I can actually develop GtkSharp3 applications without issues.

    That leads me to the question, why not use org.gnome.Platform instead of org.freedesktop.Sdk ?


    directhex Reply:

    Hm… Space concerns, I guess, and a lingering worry about incompatibility between Gtk2 and Gtk3 components. I could be wrong, of course!


Leave a Reply