Flatpak Distribution on Linux

The idea of packaging Mailspring with Flatpak has been floated before. As the Flatpak ecosystem becomes more mature and widespread, I believe this is worth taking a second look at.

  • Flatpak is preferred over Snap by many distros, and is presently more widely adopted than Snapcraft across the Linux ecosystem.
  • Flatpak has a smaller “payload” due to its ability to share dependencies, instead of bringing everything itself.
  • Flatpak has better integration with system theming and icons.

The related GitHub discussion is here:


One of the major Snapcraft issues that underscore the need to move to Flatpak:

1 Like

Very happy to see this revisited. Flatpak is quickly becoming the package of choice for most Linux distros and has a good update model for pushing new features etc without tracking down an RPM or DEB.

3 Likes

Has there been any movement on this? I’m happy to contribute if it’s warranted. I have atmoic OSes and would love to pay for mail spring and use the app.

If you want to help package it, we’d sure appreciate it!

electron-builder now supports flatpak natively…

btw… having to create an account on mailspring’s forum to update a bug is a bit annoying.

2 Likes

Thanks for the heads up.

btw… having to create an account on mailspring’s forum to update a bug is a bit annoying.

Sorry for the inconvenience. GitHub Issues simply was not maintainable for this project, and we’ve been in need of a proper community space for some time besides.

I would also like to mention that Flatpak is more universal, but the primary reason I want to avoid snap is its inability to update software nicely.

Once an update for a snap container is released and its installed, the container loses its filesystem and usually starts misbehaving massively, this has already caused me data loss with multiple snap containers and snap developers do not prioritize fixing that issue by-default. Some ugly half-workarounds exist, but I don’t do those. That is an unacceptable risk for me and I want to use Flatpak that doesn’t have caveats like this.

1 Like

I’ve started working on a flatpak of mailspring in my free time. Is there a way to override the Mailsync downloads in postinstall.js?

I can only upvote the effort of releasing Mailspring as flatpak. I’m looking for some modern mail client on Linux and having Mailspring as flatpak would be pretty amazing (I’ve tested snaps before but from end user perspective they seem inferior for the reasons outlined above and I don’t see a point in having both on my system).

I was able to unpack the .deb file for the 1.9.1 release and create a flatpak YAML file which installs it using Flatpak. It may not be the prettiest thing, but it works. :smiley: I’m not a Mailspring user (yet), but I really like the Mailspring UI and wanted to try it out by installing it in a sandbox, so I took a few hours to try getting it to work with Flatpak. I actually have no idea what I’m doing with Flatpak, I started using it less than a week ago and this is my first attempt to package something with it.

These are the steps I took:

  1. mkdir flatpak; cd flatpak
  2. Copy the Flatpak YAML file contents below into a file called com.getmailspring.Mailspring.yml.
  3. mkdir deb; mv mailspring-1.9.1-amd64.deb deb; cd deb
  4. ar x mailspring-1.9.1-amd64.deb to unpack the deb.
  5. tar xvf data.tar.xz . to unpack the data.
  6. cd ..
  7. git init - This is needed for the next step to get libraries to be packaged alongside the app.
  8. git submodule add https://github.com/flathub/shared-modules.git - This gives us a way to package libsecret which Mailspring depends on.
  9. Install the base the flatpak will run on: flatpak install flathub org.electronjs.Electron2.BaseApp//20.08
  10. Install NodeJS for Electron to run (not sure this is necessary): flatpak install flathub org.freedesktop.Sdk.Extension.node14//20.08
  11. flatpak-builder --user --force-clean --install dist com.getmailspring.Mailspring.yml to build and install Mailspring locally with Flatpak.
  12. Voila! Mailspring is installed with Flatpak. Use flatpak run com.getmailspring.Mailspring to run it.

Known Issues

  • After quitting Mailspring, the sync process sticks around for just a minute while syncing. You can see it with ps aux | grep mailspring. It quits after a bit, so maybe this is the normal behavior for syncing.
  • I’m not sure if I stripped down the flatpak yml file enough, or if other libraries need to be added. For me, I can see the system tray icon and sync my email account just fine, I just don’t know if anything is missing feature-wise.
  • I haven’t taken much time to see how to get or generate a .desktop file so I can launch the app outside of the terminal. I may get it working at some point, but I hope others can fill the gap here.

Contents of com.getmailspring.Mailspring.yml

app-id: com.getmailspring.Mailspring
runtime: org.freedesktop.Platform
sdk: org.freedesktop.Sdk
runtime-version: '20.08'
base: org.electronjs.Electron2.BaseApp
base-version: '20.08'
sdk-extensions:
  - org.freedesktop.Sdk.Extension.node14
separate-locales: false
command: run.sh
finish-args:
  - --share=ipc
  - --socket=x11
  - --socket=pulseaudio
  - --share=network
  - --talk-name=org.freedesktop.secrets
  - --talk-name=org.freedesktop.Notifications
  - --talk-name=org.freedesktop.Flatpak
  - --system-talk-name=org.freedesktop.login1
  # System Tray Icon
  - --talk-name=org.kde.StatusNotifierWatcher
  # probably not necessary for system tray icon, at least in GNOME.
  #- --own-name=org.kde.StatusNotifierItem-3-2
build-options:
  append-path: /usr/lib/sdk/node14/bin
  cflags: -O2 -g
  cxxflags: -O2 -g
  env:
    NPM_CONFIG_LOGLEVEL: info
modules:
  - shared-modules/libsecret/libsecret.json
  - name: mailspring
    buildsystem: simple
    sources:
      - type: dir
        path: deb/usr/share
      # Wrapper to launch the app
      - type: script
        dest-filename: run.sh
        commands:
          - zypak-wrapper.sh /app/share/mailspring/mailspring "$@"
    build-commands:
      - mkdir -p /app/share/mailspring
      - cp -r mailspring /app/share/
      - install -Dm755 -t /app/bin/ run.sh

Following the Slack Flatpak manifest as an example, I think I’ve gotten to a pretty good place with this. I copied the Mailspring .desktop, appdata.xml, and icon png files to the root flatpak directory I made, then changed the Flatpak yml file to look like this:

app-id: com.getmailspring.Mailspring
runtime: org.freedesktop.Platform
sdk: org.freedesktop.Sdk
runtime-version: '20.08'
base: org.electronjs.Electron2.BaseApp
base-version: '20.08'
sdk-extensions:
  - org.freedesktop.Sdk.Extension.node14
separate-locales: false
command: mailspring
finish-args:
  - --share=ipc
  - --socket=x11
  - --socket=pulseaudio
  - --share=network
  - --talk-name=org.freedesktop.secrets
  - --talk-name=org.freedesktop.Notifications
  - --talk-name=org.freedesktop.Flatpak
  - --system-talk-name=org.freedesktop.login1
  - --talk-name=org.kde.StatusNotifierWatcher
  - --talk-name=com.canonical.AppMenu.Registrar
  # probably not necessary for system tray icon, at least in GNOME.
  #- --own-name=org.kde.StatusNotifierItem-3-2
build-options:
  append-path: /usr/lib/sdk/node14/bin
  cflags: -O2 -g
  cxxflags: -O2 -g
  env:
    NPM_CONFIG_LOGLEVEL: info
modules:
  - shared-modules/libsecret/libsecret.json
  - name: mailspring
    buildsystem: simple
    sources:
      - type: extra-data
        filename: mailspring.deb
        only-arches:
          - "x86_64"
        url: https://github.com/Foundry376/Mailspring/releases/download/1.9.1/mailspring-1.9.1-amd64.deb
        sha256: 99fa700d84691542c3f5387cb48e72a9be516166491daadb598a5f292dd0ea61
        size: 87784166
      - type: script
        dest-filename: apply_extra
        commands:
          - ar x mailspring.deb
          - rm -f mailspring.deb
          - tar xf data.tar.xz
          - rm -f control.tar.gz data.tar.xz debian-binary
          - mv usr/* .
          - chmod -R a-s,go+rX,go-w .
          - rmdir usr
      - type: file
        path: mailspring-16x16.png
      - type: file
        path: mailspring-32x32.png
      - type: file
        path: mailspring-64x64.png
      - type: file
        path: mailspring-128x128.png
      - type: file
        path: mailspring-256x256.png
      - type: file
        path: mailspring.appdata.xml
      - type: file
        path: mailspring.desktop
      # Wrapper to launch the app
      - type: script
        dest-filename: mailspring.sh
        commands:
          - exec env TMPDIR=$XDG_CACHE_HOME zypak-wrapper /app/extra/share/mailspring/mailspring -s $EXTRA_ARGS \"$@\"
    build-commands:
      - install apply_extra ${FLATPAK_DEST}/bin
      - install mailspring.sh ${FLATPAK_DEST}/bin/mailspring
      - install -Dm644 mailspring.appdata.xml ${FLATPAK_DEST}/share/appdata/${FLATPAK_ID}.appdata.xml
      - install -Dm644 mailspring-16x16.png ${FLATPAK_DEST}/share/icons/hicolor/16x16/apps/${FLATPAK_ID}.png
      - install -Dm644 mailspring-32x32.png ${FLATPAK_DEST}/share/icons/hicolor/32x32/apps/${FLATPAK_ID}.png
      - install -Dm644 mailspring-64x64.png ${FLATPAK_DEST}/share/icons/hicolor/64x64/apps/${FLATPAK_ID}.png
      - install -Dm644 mailspring-128x128.png ${FLATPAK_DEST}/share/icons/hicolor/128x128/apps/${FLATPAK_ID}.png
      - install -Dm644 mailspring-256x256.png ${FLATPAK_DEST}/share/icons/hicolor/256x256/apps/${FLATPAK_ID}.png
      - install -Dm644 mailspring.desktop ${FLATPAK_DEST}/share/applications/${FLATPAK_ID}.desktop
      - desktop-file-edit --set-key="Icon" --set-value="com.getmailspring.Mailspring" ${FLATPAK_DEST}/share/applications/${FLATPAK_ID}.desktop
      - desktop-file-edit --set-key="Exec" --set-value="mailspring %U" ${FLATPAK_DEST}/share/applications/${FLATPAK_ID}.desktop
      - desktop-file-edit --set-key="StartupWMClass" --set-value="Mailspring" ${FLATPAK_DEST}/share/applications/${FLATPAK_ID}.desktop
      - desktop-file-edit --set-key="X-Flatpak-RenamedFrom" --set-value="mailspring.desktop;" ${FLATPAK_DEST}/share/applications/${FLATPAK_ID}.desktop
      - install -Dm755 /usr/bin/ar -t ${FLATPAK_DEST}/bin
      - install -Dm755 /usr/lib/$(gcc -print-multiarch)/libbfd-*.so -t ${FLATPAK_DEST}/lib

Now my Linux distro picks up the .desktop file and icons (including the tray icon) automatically. :tada:

I’m actually working on a source build of mailspring for flatpaks, this would in theory allow us to support arches like armv8. There was actually already an attempt to submit a flatpak using the deb to flathub that was turned down due to the fact there is nothing preventing a source build. Could the team bump the cld version to 2.7? 2.6 can’t be built since its missing some #include <exception> in certain files.

could someone help me with building mailspring offline? I’ve gotten to past installing deps. Attempting to build the Mailspring it makes network requests which doesn’t work

Mayb we can check-in here with likes and comments to get help from flatpak “guru”?

BINGO!
It’s on flathub today!
https://flathub.org/apps/details/com.getmailspring.Mailspring
Test it!

P.S. Ok. Failed to start on Wayland. Try it on X11.

The Flatpak version complains about missing libsecret for me. The Snap version works.

Not working on Fedora 35
❯ flatpak run com.getmailspring.Mailspring
[2 preload-host-spawn-strategy] Running: /app/bin/zypak-helper child - /app/share/mailspring/mailspring --type=zygote
The futex facility returned an unexpected error code.
Failed to generate minidump.%

It’s working for me on Fedora 35.

1 Like

Should set X11 socket (not Wayland) for flatpak bundle permissions. Use Flatseal.
I use it on Fedora 35.