Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add Flatpak support#8

Open
ximion wants to merge 2 commits into
fiji:mainfrom
ximion:main
Open

Add Flatpak support#8
ximion wants to merge 2 commits into
fiji:mainfrom
ximion:main

Conversation

@ximion

@ximion ximion commented Mar 14, 2022

Copy link
Copy Markdown

Hi!
I saw your request for a Debian packager on https://imagej.net/software/fiji/downloads - since I am one, I decided to give this a go, but then ultimately ended up creating a Flatpak bundle for Fiji instead, which I think users may be a bit happier with :-)
Flatpak is a widely supported bundling system on Linux, which makes it possible to "freeze" and app with its dependencies, to deploy it easily to pretty much any Linux distribution.
It's a pretty convenient and widely available way to make software available on Linux nowadays.

I created this recipe so we could use Fiji easily on our more powerful shared servers where people connect to from remote locations (and where having every user download Fiji manually is pretty inconvenient, compared to just selecting it from the menu and it just working).

There is one huge issue with Fiji in a Flatpak currently though: Flatpak apps are run from a read-only filesystem by design, while ImageJ/Fiji was written to modify its own files at runtime with its own updater. Originally I just intended to remove the updater and use Flatpak's own very efficient update mechanism to automatically keep Fiji up-to-date.
Unfortunately, removing the updater also cuts off any way for users to easily install ImageJ plugins, which is not an acceptable compromise.
So, what this bundle will do instead is copy the entire Fiji distribution into the user's writable data location and then run it from there. It still runs in the isolated Flatpak environment, but Fiji can modify itself now. Of course this is bad design, as it duplicates data for every user who runs Fiji on the machine, is less secure, and if the home directory is on a filesystem that prevents executables, it won't work either.
Ideally, ImageJ/Fiji would be modified to allow loading modules from separate writable paths and to split the externally-managed plugins from the ones Fiji ships with, so one half can be on a read-only filesystem, while users can still add their own plugin sources. But that would require quite a few changes on the existing codebase, so for now the Flatpak bundle uses the copy-everything compromise.

Another pretty evil thing is that network access is enabled during build, but the advantage of that is that the Flatpak bundle can be created very easily using the same process as all the other binary distributions are using.

If you just want a Fiji Flatpak build that you can use on your machine, download a test-build from here: https://github.com/ximion/fiji-builds/releases/tag/x-test

So, how can you create the build yourself?

1. Install Flatpak

sudo apt install flatpak flatpak-builder
sudo systemctl reboot # restarts the computer

2. Configure Flatpak to use Flathub for SDKs/Runtimes

sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

3. Build the bundle

cd flatpak/
./autobuild-bundle.sh

4. Install the application!

You can open the resulting Fiji.flatpak in KDE Discover or GNOME Software for a GUI to install it, or install it via the command-line:

flatpak install ./Fiji.flatpak

You can then just launch Fiji by clicking its icon on the menu!

I included changes to the GitHub action with this PR, which makes it build the Flatpak bundle in a separate job and uploads it as an artifact, so you can fetch it from there for testing purposes.
I deliberately didn't touch the code that uploads directly to the Fiji download site.
This PR will address Fiji issue fiji/fiji#287
Thanks for considering! :-)
Cheers,
Matthias

@ximion

ximion commented Mar 14, 2022

Copy link
Copy Markdown
Author

Rebased on the current main branch. I threw the Flatpak Action into the "enabled" GitHub Action for now, as that makes testing easier (later those two files should obviously be merged and be enabled or disabled together, not separately)

@ctrueden

Copy link
Copy Markdown
Member

Wow @ximion, thank you so much for working on this! I will go over this with @hinerm this week.

@ctrueden ctrueden force-pushed the main branch 7 times, most recently from 878a09d to b4bdabf Compare March 30, 2022 21:36
@ctrueden ctrueden self-assigned this Apr 5, 2022
@ctrueden

ctrueden commented Apr 5, 2022

Copy link
Copy Markdown
Member

Sorry I haven't had time to review this yet. It's on my list for tomorrow April 13th. In the meantime, with imagej/imagej.github.io@8bf2e5b I have updated the Fiji Downloads page page to mention this work, since I agree that containerized solutions like Flatpak and Snap are a better fit for Fiji these days.

@LunarEclipse363

Copy link
Copy Markdown

I'm just gonna say that I tested this by following the above instructions on Ubuntu 20.04 and it seems to work perfectly so far.

@ximion

ximion commented Apr 27, 2022

Copy link
Copy Markdown
Author

Sorry I haven't had time to review this yet. It's on my list for tomorrow April 13th. In the meantime, with imagej/imagej.github.io@8bf2e5b I have updated the Fiji Downloads page page to mention this work, since I agree that containerized solutions like Flatpak and Snap are a better fit for Fiji these days.

Awesome, thank you! I could also submit this to Flathub, however I am not sure whether this particular package would be welcomed, because we not only not properly build all code from scratch (Maven is downloading a lot of prebuilt components) but also don't have any separation between parts of Fiji and plugins, so the Flatpak has to copy all executable files to a mutable volume in the user's home directory because any one of them might be modified by new plugins or updated by Fiji's updater. That's pretty problematic. At the same time though, a thing like Steam is allowed, and the Steam Flatpak is handling this only slightly better, so Fiji might actually be fine if I polish the code a little ;-)

@ctrueden

ctrueden commented May 10, 2022

Copy link
Copy Markdown
Member

Sorry again for the slow review and merge on this. Had crunch time for the I2K conference, and now at another conference, so my normal PR reviewing schedule was thrown off. But I just wanted to say again that I'm enthusiastic. I will shoot to review this during my next PR day on Wednesday, May 18.

we not only not properly build all code from scratch (Maven is downloading a lot of prebuilt components)

And I can't resist the opportunity to rant here about packaging systems that want to rebuild Java code. The entire point of Java is "write ONCE" so downloading prebuilt binaries is exactly fine and correct, unlike with native code... 😞

@ximion

ximion commented May 19, 2022

Copy link
Copy Markdown
Author

And I can't resist the opportunity to rant here about packaging systems that want to rebuild Java code. The entire point of Java is "write ONCE" so downloading prebuilt binaries is exactly fine and correct, unlike with native code... disappointed

You often do want to verify though that the shipped code you have yields exactly the binaries you want, and that the code to generate said binaries is fully available in the first place (in case you want to modify it). The best way to ensure that is to build things from scratch.
You may also want to build it against newer Java versions, different JVM or do who-knows-what for a custom build.
Personally I'd like a toggle to enable or disable downloading of binary components, but in any case for this packaging effort here it doesn't really matter all that much - Flatpak just runs the result, no matter how it was built. :-)

@ctrueden

ctrueden commented Jun 8, 2022

Copy link
Copy Markdown
Member

I started looking at this today! But got distracted by the ImageJ Launcher patch. The good news is, that PR imagej/imagej-launcher#85 is now merged; the bad news is, the CI never got fully migrated to GitHub Actions after Travis stopped working, so I still need to complete that migration. But I'll punt on it for the moment in favor of testing and merging this PR here, since the patch is also applied manually when building the Flatpak package. I have some conflicts though for the rest of the day, so probably won't finish the review today. Will keep y'all updated.

@ximion

ximion commented Dec 23, 2022

Copy link
Copy Markdown
Author

Since this is linked on the Fiji download page, and since the patch needs rebasing and probably an update as well now, I created a pre-built bundle for people who navigate here and just want to give the easy Fiji installation a try.
For most users it should just require downloading the Flatpak file from https://github.com/ximion/fiji-builds/releases/tag/x-test and installing it with their graphical software center.

@aldakheelarwa

This comment was marked as off-topic.

@ximion

ximion commented Mar 1, 2026

Copy link
Copy Markdown
Author

@ctrueden Would it be okay with you and others if I made an attempt to submit this to Flathub so Linux users can easily install the app? This will be a bit of a challenge, because in order to work well, Fiji/ImageJ will basically require maximum permissions (nearly no sandboxing, so plugins continue to work) and Fiji currently cannot be built from scratch - Maven just downloads a whole bunch of binary stuff at "build" time.

So, by attempting this, Fiji will become super easy to install after being available on Flathub, but I will need to submit a few patches to add some metadata and we may actually need versioned release tarballs that the Flatpak bundle will just use as "source" instead of building from scratch, as I currently see no way to build Fiji without network access (which is a requirement for Flathub).

I could do the work and talk to the Flathub admins, but I would need blessing from the Fiji authors to make this official, and would definitely like it if one of you would co-maintain the result (or at least have access to the resulting page on Flathub / Flathub GitHub to make changes if needed).

@ctrueden

ctrueden commented Mar 5, 2026

Copy link
Copy Markdown
Member

@ximion Yes, I definitely want to help make this happen! Thank you for the ping, and I apologize for my continual deferral of it as a priority for years. 😞 I am willing to maintain it going forward once it is in place. I just pushed an update modernizing the recipe to current standards—but I leaned on Claude quite a lot, so please let me know (or fix) if anything looks suboptimal.

Edit: I also rebased over the latest main branch to resolve the conflicts.

we may actually need versioned release tarballs that the Flatpak bundle will just use as "source" instead of building from scratch

Can we use the timestamps from https://downloads.imagej.net/fiji/archive/latest/ ?

What else needs to happen to move this forward?

ximion and others added 2 commits March 5, 2026 11:19
* Bump runtime to 23.08: the previous 21.08 runtime is end-of-life and
  would be rejected by Flathub. 23.08 is the oldest currently-supported
  freedesktop Platform release that still carries the openjdk8 SDK
  extension Fiji requires.

* Rename launch-imagej.sh to launch-fiji.sh: this is a Fiji-specific
  Flatpak package, not a generic ImageJ one. The launcher script is
  Fiji's entry point and should reflect that.

* Remove DEBUG=1 from fiji-update build step: this was left on
  inadvertently. Build output is captured by flatpak-builder regardless;
  setting DEBUG=1 is not intentional here.

* Add explanatory comment to fiji-update: the network build-arg is
  intentional because Fiji's updater must fetch plugins and the Java-8
  JRE from the official update sites at build time. This is a known
  deviation from reproducible-build best practice and warrants a note.

* Pin fiji-make to branch main explicitly, with a TODO to pin a commit:
  the previous source block had no branch or tag, making it implicit and
  non-obvious. A specific commit hash should be chosen once the desired
  Fiji release is identified.

* Add <releases> to AppStream metainfo: Flathub validation requires at
  least one <release> entry. Added 2.14.0 as the baseline; update to
  match the actual bundled version as needed.

* Use debian:bookworm in Dockerfile: debian:testing is a rolling target
  that can change package versions unexpectedly between builds. Bookworm
  is the current Debian stable release and gives a reproducible build
  environment.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@ximion

ximion commented Mar 5, 2026

Copy link
Copy Markdown
Author

We would need to decide whether we want to distribute this via Flathub or roll our own.

If we go via Flathub, it would reach the widest user audience, be simple to install, and have automatic updates (although we copy Fiji to the user's home directory anyway and use the local updater, since this is the only way that updates work...).

The problems we will run into with Flathub is that some arguing is needed to get it in, because we will have to disable basically all sandboxing features to make this work, which always raises concern. In addition to that, no network-enabled builds are permitted, so we would likely need to fetch a tarball from somewhere.

Flatpak builds on Flathub need to be reproducible, so we can't just fetch a "latest" tarball, but we need one with a defined version number. So, Fiji would need to provide versioned tarballs.
We will also have to make Fiji ship an AppStream MetaInfo file (trivial to do, but to keep it up-to-date with the latest Fiji version, some work may be needed).

Fiji still requires Java 8, right? We can not make it use any newer JDK? We'll also have to justify that, most likely.

Plus, once the application is accepted, verification for the app would need to be set up via the Fiji website, have a look at https://docs.flathub.org/docs/for-app-authors/verification for details.

All of these items I can help with because I have now done them many times and know the Flathub devs (and have annoyed them with sandbox-less scientific apps many times by now).

The alternative is just shipping a Flatpak file or setting up our own repo, which comes with its own drawbacks, but tbh, I'd make an attempt at Flathub before going that route.

@ximion

ximion commented Mar 5, 2026

Copy link
Copy Markdown
Author

Can we use the timestamps from https://downloads.imagej.net/fiji/archive/latest/ ?

That could work, but only if we have the automation also generate a MetaInfo file with the right version number. We need to attach a version number to Fiji, and ideally make that part of the tarball name (but not required, as long as it's in the path and the MetaInfo file has it). So, e.g. we could version the release from 20260302 as 26.0302, that would be sufficient (we only will never be able to decrease that version number once it's set, it needs to be increasing).

@ximion

ximion commented Mar 5, 2026

Copy link
Copy Markdown
Author

Oh, and I almost forgot: We also need a good screenshot of Fiji hosted somewhere on the web, although that most certainly won't be an issue ^^

For reference, I just recently submitted a tiny app to Flathub, this is how the resulting page looks like: https://flathub.org/en/apps/io.github.bothlab.omerewriter

And this is how the review process for Flathub looked like: flathub/flathub#7960

I can take care of most of the work (since the heavy lifting is done), but you would need to version Fiji first, and we would have to add a MetaInfo file with a proper screenshot and description first. I can have a look if that can be automated somehow, then making the Flatpak becomes easy.

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

4 participants