Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a flatpak manifest #610

Merged

Conversation

tchernobog
Copy link
Contributor

@tchernobog tchernobog commented May 18, 2020

This PR adds flatpak support for Hamster. Building the application is surprisingly easy, and making it available on flathub should contribute to Hamster's usage growth.

@mwilck
Copy link
Contributor

mwilck commented May 18, 2020

This is great! I've thought about doing this myself, thanks a lot.

Have you tried if this works with the GNOME shell extension? See hamster-shell-extension#328 for the issues we had with the snap package (permission problems with DBus service autostart). It'd be great news if flatpak didn't have these issues.

@tchernobog
Copy link
Contributor Author

@mwilck Yes, I am actually running it with the GNOME shell extension, and was pleasantly surprised to see it works out of the box!

src/hamster/lib/configuration.py Outdated Show resolved Hide resolved
@tchernobog tchernobog requested a review from mwilck May 18, 2020 09:22
@matthijskooijman
Copy link
Member

Just quickly read up on flatpack, sounds like an interesting way to distribute hamster directly to users (in addition to through distro packages), probably better than letting users run waf install directly, with all the potentially untracked mess on a system resulting from that.

I am wondering what the implications of adding this are. How would things work, what would needed be done when?

Some specific questions:

  • The flatpack manifest contains explicitly versioned dependencies. I guess we would need to manually bump those versions every now and then. Is there tooling to find the latest version, or would this mean manually updating version numbers and checksums?
  • It seems this PR only facilitates a local build of flatpack, which is a great start. But flatpack is intended to used with repositories and auto-updating, is that something we should think about in the longer term? Would that mean uploading to some central flatpack repo? Or would we need to host our own?
  • It seems useful to automatically build a flatpacks for each pull request (for easier testing) and maybe releases too. Does flatpack support packaging into a single downloadable file, or would that require going through a repository of sorts?
  • The additions to the README in this PR are a little concise. I would welcome some more additions, so a user that has never really worked with flatpack knows a bit better what they are doing (e.g that a flatpack repo is created, into which a flatpack application is built, which is later installed from the repo).
  • The manifest specifies the gnome 3.36 runtime. Does this support running on other gnome versions too? I suspect it does, since hamster itself does not depend on Gnome anymore, I think, it only needs GTK and some build tools and maybe icons (and I guess the gnome runtime is the easiest way to install all that?). Only the extension depends on gnome(-shell) more closely, but that is installed normally outside of flatpack, right?

@tchernobog
Copy link
Contributor Author

Some specific questions:

* The flatpack manifest contains explicitly versioned dependencies. I guess we would need to manually bump those versions every now and then. Is there tooling to find the latest version, or would this mean manually updating version numbers and checksums?

Usually it's done manually as part of the packaging effort. It would be possible to extract this somewhat automatically if Hamster were to use Pipenv and a Pipfile.lock, else I personally don't think it's worth the effort.

* It seems this PR only facilitates a local build of flatpack, which is a great start. But flatpack is intended to used with repositories and auto-updating, is that something we should think about in the longer term? Would that mean uploading to some central flatpack repo? Or would we need to host our own?

I wanted first to enable people to build a flatpak locally, which is great for testing. Publishing on flathub.org is easy enough, but then the manifest would need to be moved out of this repository and into flathub's. See https://github.com/flathub/flathub/wiki/App-Submission#how-to-submit-an-app

* It seems useful to automatically build a flatpacks for each pull request (for easier testing) and maybe releases too. Does flatpack support packaging into a single downloadable file, or would that require going through a repository of sorts?

That would be a single-file bundle: https://docs.flatpak.org/en/latest/single-file-bundles.html
It can be done as part of continuous integration.

* The additions to the README in this PR are a little concise. I would welcome some more additions, so a user that has never really worked with flatpack knows a bit better what they are doing (e.g that a flatpack repo is created, into which a flatpack application is built, which is later installed from the repo).

This PR is a bit more targeted at developers wanting to test it out (so one assumes a bit of knowledge of flatpak anyway), but sure, I can add that.

* The manifest specifies the gnome 3.36 runtime. Does this support running on other gnome versions too? I suspect it does, since hamster itself does not depend on Gnome anymore, I think, it only needs GTK and some build tools and maybe icons (and I guess the gnome runtime is the easiest way to install all that?). Only the extension depends on gnome(-shell) more closely, but that is installed normally outside of flatpack, right?

If Hamster is GNOME-agnostic, we can depend on the Freedesktop runtime. But the main idea is that flatpak forces you to decide which set of libraries (here, GNOME 3.36 libraries) to target, so that each system installing your app will have exactly the same set of code running. That means ease of debugging, a lot less unreproducible bugs, etc.

@tchernobog
Copy link
Contributor Author

tchernobog commented May 18, 2020

I addressed the comments by adding some more documentation in the README, and showing how to build a bundle instead of a repository.

I also tried to move away from the GNOME SDK and use the Freedesktop SDK directly, but some dependencies are not available (for instance, gobject-introspection support).

@mwilck
Copy link
Contributor

mwilck commented May 18, 2020

If Hamster is GNOME-agnostic, we can depend on the Freedesktop runtime.

I'm unaware of any GNOME version dependencies of hamster itself. The GNOME extension has more than enough though.

@matthijskooijman
Copy link
Member

I also tried to move away from the GNOME SDK and use the Freedesktop SDK directly, but some dependencies are not available (for instance, gobject-introspection support).

Yeah, we don't rely on Gnome itself (that is, you can run hamster on KDE just fine, I think), but we do need some gnome-related libraries for the UI (gtk/glib/gobject), so it is probably easier to just depend on (any version of) the gnome runtime than use the freedesktop runtime and install all the needed libraries on top of that.

This PR is a bit more targeted at developers wanting to test it out (so one assumes a bit of knowledge of flatpak anyway), but sure, I can add that.

Yeah, looks much better (though it also makes a lot of unrelated whitespace changes, could you revert those?). Going through a bundle instead of installing from a local repo is nice because:

  • The installation step is identical between self-building and building from a CI build (which makes instructions simpoler).
  • There is no longer any "one-time-setup" command for adding the repo
  • The repo is now just basically a temporary build directory.

The last point could maybe be made explicit in the README? Something like:

This creates a temporary flatpack repository in the flatpack/repo directory containing the built application, which is then exported to a .flatpack file. The .flatpack file can be installed as above, the flatpack/repo directory can be removed.

I also see a flatpack/build argument, is that actually "build" command being ran? Or is that a temporary build directory? If the latter, it should be included in the previous note as well, I think.

One worry I have is that if we merge this, we also need to make sure the manifest file stays working. Some ingredients to tackle that:

  • Building the flatpack bundle as a github action would at least ensure that it stays buildable, and makes it easy for anyone to test the flatpack build.
  • Some manual testing of the build before each release would be useful. This would work best by people that already run the flatpack build normally, I guess. @tchernobog, would you yourself in such a role?
  • More extensive automated testing (e.g. running the testsuite inside the flatpack build, or maybe just some tests that talk to the dbus interface) could also help, but I'm not sure where to begin with that.

@matthijskooijman
Copy link
Member

Hm, I just noticed #561, which also intends to add a flatpack manifest. @bochecha, you created #561, can I invite you to participate in this PR as well?

Overall, I'm inclined to work towards merging this PR over #561, since this PR adds some docs to the README. I also do not quite like the build-aux top level folder name (though I think I do like having some kind of top-level folder, to collect build-related stuff, rather than ending up with snap, flat and more directories like that, but maybe we should just separately review the folder structure later).

I also compared the flatpack manifests themselves a bit, and it seems they are mostly identical, but with some small differences. @tchernobog, @bochecha, since you are more familiar with flatpak, maybe you could compare both so we can pick the best from both?

One thing I did notice in the description of #561 is that flatpackbuilder apparently has a --install option, which I think builds and installs directly. If I got that correctly, then that might be even nicer to use as a "build yourself" command in the README?

@tchernobog
Copy link
Contributor Author

One worry I have is that if we merge this, we also need to make sure the manifest file stays working. Some ingredients to tackle that:

Building the flatpack bundle as a github action would at least ensure that it stays buildable, and makes it easy for anyone to test the flatpack build.

Yes, I agree.

Some manual testing of the build before each release would be useful. This would work best by people that already run the flatpack build normally, I guess. @tchernobog, would you yourself in such a role?

I can do that if there is a way for me to be notified a release is coming.

More extensive automated testing (e.g. running the testsuite inside the flatpack build, or maybe just some tests that talk to the dbus interface) could also help, but I'm not sure where to begin with that.

It is possible to get a shell inside the sandboxed build environment and run tests with:
flatpak-builder --run build/flatpak/tmp org.gnome.Hamster.json python3 -m unittest
after invoking flatpak-builder as per README.md.

I reviewed the awesome work of @bochecha, which for some reason I missed before (sorry!). There are not a lot of differences; mostly the owned D-Bus names, relying to an external git submodule for intltools (but I guess Hamster should move to plain gettext as intltool is deprecated, and it's not a lot of code), and removing the icon cache.

@bochecha Can you elaborate on the need to remove the icon cache? It's the only item I am unsure about. Thanks!

@tchernobog tchernobog force-pushed the features/flatpak-manifest branch 9 times, most recently from 9f9ebd9 to d345df8 Compare May 19, 2020 11:56
@matthijskooijman
Copy link
Member

(but I guess Hamster should move to plain gettext as intltool is deprecated, and it's not a lot of code)

I think that we're not actually using intltool itself anymore, just the intltool waf module to call gettext. Maybe some refactoring on the waf side could be done to drop that dependency, haven't looked at it more closely yet.

@tchernobog tchernobog force-pushed the features/flatpak-manifest branch 2 times, most recently from 2c956f9 to 8e4c891 Compare May 19, 2020 12:08
@tchernobog
Copy link
Contributor Author

I added a pipeline for building and testing the flatpak bundle.

Copy link
Contributor Author

@tchernobog tchernobog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I updated the changeset as per comments. The new patchset fixes the issue.

@tchernobog
Copy link
Contributor Author

@matthijskooijman, @mwilck: are there any other changes you would like? Is there still something you need before approval can be given?

Copy link
Member

@matthijskooijman matthijskooijman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, I think we're nearly there. I can't really comment on the contents of the flatpack manifest itself, bu

One new question I realized: How are datafiles handled (e.g. if you upgrade or remove the snap, where does the database go)? In the manifest I see --filesystem=xdg-documents, I suspect that means that e.g. ~/.local and ~/.config from the host system are made available inside the flatpack?

I added a pipeline for building and testing the flatpak bundle.

Cool! One useful addition would be to also make the resulting flatpack file available. I think adding an upload-artifact step would be enough for this.

I left two more inline comments about the README. In the same area, I previously asked the following, I think you did not respond to this yet:

One thing I did notice in the description of #561 is that flatpackbuilder apparently has a --install option, which I think builds and installs directly. If I got that correctly, then that might be even nicer to use as a "build yourself" command in the README?

I also still see some unrelated (whitespace) changes to the README. Those should at least be in a separate commit (which I think they are not right now), but probably just be dropped entirely, since they actually change formatting (trailing whitespace produces a newline in markdown, so it should just be removed).

As for the the PR itself, the history is a bit messy right now, we should probably squash some commits before merging. I think there should be 3 commits:

  • Introduce flatpack file and documentation
  • Add flatpack GH action
  • flake8: Fix indentation

If you're unsure how to approach this, I'm happy to do the restructuring (now, or directly before merging).

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@tchernobog
Copy link
Contributor Author

tchernobog commented Jul 6, 2020

One new question I realized: How are datafiles handled (e.g. if you upgrade or remove the snap, where does the database go)? In the manifest I see --filesystem=xdg-documents, I suspect that means that e.g. ~/.local and ~/.config from the host system are made available inside the flatpack?

Not a snap, it's a flatpak :-D. It creates its own sandboxed folder for the application. Data files are kept in $HOME/.var/org.gnome.Hamster/. These are persisted across upgrades or uninstall, just like a non-flatpak app.

--filesystem=xdg-documents allows access to the $HOME/Documents folder via the Gtk file dialog (useful to export or import files into Hamster).

As for the the PR itself, the history is a bit messy right now, we should probably squash some commits before merging.

I will do this myself as the last step, after a final review of the result from you.

@matthijskooijman
Copy link
Member

Data files are kept in $HOME/.var/org.gnome.Hamster/

Ah, so that means they are different from the datafiles used by a normal install. I wonder if it is possible to just use the same datafiles as a "normal" install (e.g. allow access to ~/.local and ~/.config I think)? And if it is, we should decide whether we want this. At first glance, it seems sensible, to get the cleanest upgrade path from / to the flatpack install.

@tchernobog @mwilck what would you think?

I will do this myself as the last step, after a final review of the result from you.

Ok, great.

@tchernobog
Copy link
Contributor Author

that means they are different from the datafiles used by a normal install.

@tchernobog @mwilck what would you think?

I personally would prefer to avoid this. It would break the concept of sandboxing. Also, the user might want to keep installed a different system version of Hamster (via package manager) and the new one might be incompatible. If you use flatpak, it's normally accepted that applications have restricted access to your $HOME (including previous settings).

@matthijskooijman
Copy link
Member

I personally would prefer to avoid this. It would break the concept of sandboxing. Also, the user might want to keep installed a different system version of Hamster (via package manager) and the new one might be incompatible.

Yeah, that's a good point. Might be good to document this, then, and maybe offer some advice on what files need to be copied to migrate data into and out of flatpack. I guess that migrating configuration might be more tricky (since that lives in dconf I think), but that's probably ok, I guess moving data is more relevant anyway.

@tchernobog
Copy link
Contributor Author

I guess that migrating configuration might be more tricky (since that lives in dconf I think), but that's probably ok, I guess moving data is more relevant anyway.

I added a section on migrating the database. For DConf, supposedly there would be a way to trigger a migration of config: https://docs.flatpak.org/en/latest/sandbox-permissions.html#dconf-access

However, I tried it and it seems it breaks running the unit tests for some reason, so I did not include it as of this time.

@tchernobog
Copy link
Contributor Author

@matthijskooijman are there any pending changes you would like me to perform before merging?

@matthijskooijman
Copy link
Member

@tchernobog not off-hand, I still want to do a review of the whole and your new additions, but no time right now (finishing up some other things before my vacation, so I'll probably won't get around to this until after my vacation, so early august).

Also, would be good if one of the other maintainers could do a full review as well. Maybe @mwilck? You have looked at this early on already?

@tchernobog
Copy link
Contributor Author

@mwilck would it be possible to merge this?

Copy link
Contributor

@mwilck mwilck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have deep experience with flatpak building, but this looks very good to me. The documentation changes are excellent, everything looks clean and well thought-out. @tchernobog has addressed all comments.
I see no risk of regressions. If any issues with the flatpak itself will show up, I trust that @tchernobog will help us fix them. @matthijskooijman, please merge this if you agree.

@mwilck
Copy link
Contributor

mwilck commented Aug 3, 2020

@matthijskooijman, AFAICS the change you'd requested previously has been addressed.

@magicmyth
Copy link

Just a fly by comment. I just installed the new hamster via this flatpak and it worked fine on my KDE Neon 18.04 machine. I followed the instructions in the README.md and copied over my existing database (from 2.91 Ubuntu package) and was able to get right back to work. I'm no expert but I've made a few flatpak builder recipies and tchernobog's work looks perfectly fine to me.

One sugestion I have is to maybe add to the docs about needing to run cli commands as flatpak run org.gnome.Hamster [CMD] instead of just hamster [CMD[. Might be worth giving instructions on how to alias that for convenience E.g alias hamster='flatpak run org.gnome.Hamster'.

@mwilck
Copy link
Contributor

mwilck commented Aug 4, 2020

One sugestion I have is to maybe add to the docs about needing to run cli commands as flatpak run org.gnome.Hamster [CMD] instead of just hamster [CMD[. Might be worth giving instructions on how to alias that for convenience E.g alias hamster='flatpak run org.gnome.Hamster'.

Thanks. @tchernobog, could you add that?

Matteo Settenvini added 2 commits August 7, 2020 00:08
This commit adds a manifest so that Hamster can be built as a
sandboxed flatpak application.

This has the benefit of always offering a stable environment,
where upstream has full control on the versions of all
dependencies. See https://flatpak.org/ for more information.
Adds CI actions to build Hamster as a flatpak application.
@tchernobog
Copy link
Contributor Author

One sugestion I have is to maybe add to the docs about needing to run cli commands as flatpak run org.gnome.Hamster [CMD]

Thanks. @tchernobog, could you add that?

Done, I would prefer to proceed with a merge however now before performing further changes. Making it perfect can be left to subsequent commits.

@mwilck
Copy link
Contributor

mwilck commented Aug 6, 2020

@tchernobog, thanks a lot.

I would prefer to proceed with a merge

Sure. As you can see, @matthijskooijman's review is still pending. I trust that as soon as he gets to it, he'll see my positive review and proceed with the merge.

Copy link
Member

@matthijskooijman matthijskooijman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had another look over this PR, looks good to merge for me.

I also tried installing the flatpack version (hadn't done that before, nice that it is built for PRs!), and I like the nice and interactive installation process :-)

I did have some additional questions and remarks, which I left as inline comments. I do not think these are severe enough to hold back the merge, I agree that it is more than usable now and we can perfect things later. So I'll go ahead and merge this, but responses (and maybe a followup PR) to my comments are still appreciated.

@tchernobog, Thanks for your extensive contribution, constructive discussing and long breath :-)

@@ -125,6 +152,20 @@ as discussed [here](https://github.com/projecthamster/hamster/pull/421#issuecomm

Now restart your panels/docks and you should be able to add Hamster!

##### Flatpak

Alternatively, you can also build a sandboxed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggests it just builds the flatpack, but I think it also installs it. Might be good to clarify.

you can do so with:

```bash
flatpak run org.gnome.Hamster [args...]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would there be any easy way to make this shorter? Maybe flatpack can automically put a symlink in ~/bin or /usr/local/bin? Or otherwise register a short name so you can at least use flatpack run hamster (i.e. using the same base command as a normal install)?

Also, it might be good to clarify that (IIUC) the flatpack-hamster will be autostarted through dbus (e.g. when the shell extension tries to access it). That does make me wonder: What does flatpack do when the dbus name is already registered (i.e. when hamster is normally installed as well)? From a quick test it seems to (silently) not claim the name, that is, when I start the flatpack, the flatpack GUI connects to the non-flatpack dbus service, and when I kill the non-flatpack services, it still spawns the non-flatpack ones, rather than the flatpack ones.

For most users, I guess this is not so much an issue (they would typically only install the flatpack version), but it would be at least to document these caveats somewhat. Also, one usecase I see for flatpack is that it would help with testing nightly builds or pullrequests, and then it would be convenient of someone could install the flatpack version next to the regular version and have them completely isolated.

Copy link
Contributor

@mwilck mwilck Aug 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does make me wonder: What does flatpack do when the dbus name is already registered (i.e. when hamster is normally installed as well)? From a quick test it seems to (silently) not claim the name, that is, when I start the flatpack, the flatpack GUI connects to the non-flatpack dbus service, and when I kill the non-flatpack services, it still spawns the non-flatpack ones, rather than the flatpack ones.

I don't think it's possible to hijack a well-known dbus address. I guess it shouldn't be. At best, hamster itself should log a meaningful message when it fails to acquire the address. But that's independent of packaging. It applies also to a situation with installed hamster and local (developer) instance, for example.

It's a general problem that I have with all applications that can be installed either "regularly" or as flatpak/snap/appimage (you name it): It's highly intransparent to the user which package she is activating. DBus makes it even more intransparent, of course.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible to hijack a well-known dbus address. I guess it shouldn't be. At best, hamster itself should log a meaningful message when it fails to acquire the address. But that's independent of packaging. It applies also to a situation with installed hamster and local (developer) instance, for example.

Well, there's two parts to this: One is the claiming of a dbus name at runtime, which is something hamster should report. The other, which I was thinking of, is installing a file in /usr/share/somewhere that declares that a dbus interface exists and what binary to autostart if the name is requested but not on the bus yet (at least that's how I gather it works). This is something that flatpack install should handle, but maybe flatpack handles this differently? Also, it seems that the dbus name should match the flatpak name, not sure if our WindowServer postfix is then supported (the primary service does match).

```bash
gio copy -b \
~/.local/share/hamster/hamster.db \
~/.var/app/org.gnome.Hamster/data/hamster/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use gio copy here? Looks like these are two regular paths that can just use normal cp?

@matthijskooijman matthijskooijman merged commit ceedcd8 into projecthamster:master Aug 7, 2020
@salim-b
Copy link
Contributor

salim-b commented Aug 8, 2020

Just a follow-up question.

The README now says:

If you downloaded the file with the Hamster bundle (ending in .flatpak), you can directly install it with:

flatpak install --reinstall Hamster.flatpak

But it doesn't say where you can download the Flatpak. I guess you are referring to the corresponding GitHub Actions artifact[1]?

Any plans on distributing the Flatpak via Flathub?

[1]: I've succesfully tested this in conjunction with the GNOME-3.36 version of hamster-shell-extension on Ubuntu 20.04, works like a charm. 👍

@tchernobog tchernobog deleted the features/flatpak-manifest branch August 15, 2020 11:55
@tchernobog
Copy link
Contributor Author

But it doesn't say where you can download the Flatpak. I guess you are referring to the corresponding GitHub Actions artifact[1]?

You can get it from there for now. I would assume the GNOME Hamster maintainers could promote the built .flatpak file to a release artifact for next release.

Any plans on distributing the Flatpak via Flathub?

That would require to get the manifest merged to a different repo, see: https://github.com/flathub/flathub/wiki/App-Submission
I could do so if there are enough requests, but first I would like to get the green light from the app maintainers, as they should own the new repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants