declarative-flatpak icon indicating copy to clipboard operation
declarative-flatpak copied to clipboard

Handle out-of-repo .flatpak installs and remotes

Open bayazidbh opened this issue 2 years ago • 12 comments

I noticed an app I temporarily install wasn't uninstalled, and was curious as to what the issue is:

❯ systemctl --user restart manage-user-flatpaks.service
❯ systemctl --user status manage-user-flatpaks.service
× manage-user-flatpaks.service
     Loaded: loaded (/home/fenglengshun/.config/systemd/user/manage-user-flatpaks.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2023-08-01 22:58:30 WIB; 5s ago
    Process: 118369 ExecStart=/nix/store/igqyjnd268k1b81rlf3jp8ww3jxipqw2-setup-flatpaks (code=exited, status=1/FAILURE)
   Main PID: 118369 (code=exited, status=1/FAILURE)
        CPU: 231ms

Aug 01 22:58:28 neon-laptop systemd[1344]: Started manage-user-flatpaks.service.
Aug 01 22:58:28 neon-laptop igqyjnd268k1b81rlf3jp8ww3jxipqw2-setup-flatpaks[118369]: No remotes have been found. Adding them now.
Aug 01 22:58:28 neon-laptop igqyjnd268k1b81rlf3jp8ww3jxipqw2-setup-flatpaks[118369]: Adding remote flathub with URL https://dl.flathub.org/repo/flathub.flatpakrepo
Aug 01 22:58:29 neon-laptop igqyjnd268k1b81rlf3jp8ww3jxipqw2-setup-flatpaks[118369]: Adding remote launcher-moe with URL https://gol.launcher.moe/gol.launcher.moe.flatpakrepo
Aug 01 22:58:30 neon-laptop igqyjnd268k1b81rlf3jp8ww3jxipqw2-setup-flatpaks[118435]: error: Unable to load summary from remote rustdesk-origin: Can't fetch summary from disabled remote ‘rustdesk-origin’
Aug 01 22:58:30 neon-laptop systemd[1344]: manage-user-flatpaks.service: Main process exited, code=exited, status=1/FAILURE
Aug 01 22:58:30 neon-laptop systemd[1344]: manage-user-flatpaks.service: Failed with result 'exit-code'.
❯ flatpak remotes
Name         Options
flathub      user
launcher-moe user
launcher.moe user
❯ flatpak list | grep -i rustdesk
RustDesk        com.rustdesk.RustDesk           master  rustdesk-origin user
❯ flatpak list | grep -i xwayland
Xwayland Video Bridge   org.kde.xwaylandvideobridge             master  xwaylandvideobridge-origin      user

So on the roadmap, having a sub-module to handle out-of-repo installs would be great, but for now a an auto-skip in the case of a 'remote' not being listed on the flatpak remotes would be good enough.

bayazidbh avatar Aug 01 '23 16:08 bayazidbh

Oh that's a very interesting edge-case you found!

When my module tries to dereference the installed flatpak it uses the remote to get the full ref. Since the remote doesn't seem to "exist" anymore it fails to get the full ref, and thus fails to uninstall the package...

in-a-dil-emma avatar Aug 01 '23 16:08 in-a-dil-emma

Is there a way for them to be whitelisted somehow?

Ideally, a sub-module where you can provide a link to the flatpak that would, say, automatically download the file to /tmp (since remote .flatpak installation doesn't work yet) and install it would be great.

But in the meanwhile, a whitelist or just skipping manually installed out-of-repo .flatpak apps would be great since, while I'm fine with grabbing rustdesk another way, not all distro have xwaylandvideobridge yet and that's a very useful app that makes wayland more useable for certain people.

bayazidbh avatar Aug 02 '23 03:08 bayazidbh

Unfortunately, installing out-of-tree is not possible right now.

I'm currently working on improving the way flatpak installations are handled.

You can try using the postInitCommand hook.

in-a-dil-emma avatar Aug 02 '23 08:08 in-a-dil-emma

I implemented out-of-tree ref support.

If you want to take advantage of it, switch to the "dev" branch.

in-a-dil-emma avatar Aug 02 '23 10:08 in-a-dil-emma

Testing. Did I made a mistake or is there something wrong with the repo name reading?

$ systemctl --user status manage-user-flatpaks.service
× manage-user-flatpaks.service
     Loaded: loaded (/home/fenglengshun/.config/systemd/user/manage-user-flatpaks.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2023-08-04 09:49:09 WIB; 49s ago
    Process: 89980 ExecStart=/nix/store/7r8b5a9lnhj3lzhykglqpgrlp2ypwd57-setup-flatpaks (code=exited, status=1/FAILURE)
   Main PID: 89980 (code=exited, status=1/FAILURE)
        CPU: 305ms

Aug 04 09:48:58 neon-laptop 7r8b5a9lnhj3lzhykglqpgrlp2ypwd57-setup-flatpaks[89980]: No remotes have been found. Adding them now.
Aug 04 09:48:58 neon-laptop 7r8b5a9lnhj3lzhykglqpgrlp2ypwd57-setup-flatpaks[89980]: Adding remote flathub with URL https://dl.flathub.org/repo/flathub.flatpakrepo
Aug 04 09:48:58 neon-laptop flatpak[90014]: user: Added remote flathub to https://dl.flathub.org/repo/
Aug 04 09:49:03 neon-laptop 7r8b5a9lnhj3lzhykglqpgrlp2ypwd57-setup-flatpaks[89980]: Adding remote launcher-moe with URL https://gol.launcher.moe/gol.launcher.moe.flatpakrepo
Aug 04 09:49:05 neon-laptop flatpak[90084]: user: Added remote launcher-moe to https://gol.launcher.moe/repo/
Aug 04 09:49:07 neon-laptop 7r8b5a9lnhj3lzhykglqpgrlp2ypwd57-setup-flatpaks[90135]: F: An error was encountered searching remote ‘flathub’ for ‘flathub:’: 'flathub:' is not a valid name: Name can't contain :
Aug 04 09:49:09 neon-laptop 7r8b5a9lnhj3lzhykglqpgrlp2ypwd57-setup-flatpaks[90135]: F: An error was encountered searching remote ‘launcher-moe’ for ‘flathub:’: 'flathub:' is not a valid name: Name can't contain :
Aug 04 09:49:09 neon-laptop 7r8b5a9lnhj3lzhykglqpgrlp2ypwd57-setup-flatpaks[90135]: error: No remote refs found for ‘flathub:’
Aug 04 09:49:09 neon-laptop systemd[1401]: manage-user-flatpaks.service: Main process exited, code=exited, status=1/FAILURE
Aug 04 09:49:09 neon-laptop systemd[1401]: manage-user-flatpaks.service: Failed with result 'exit-code'.

flatpak.nix

{ config, pkgs, ... }:
{
  services.flatpak = {
    remotes = {
      "flathub" = "https://dl.flathub.org/repo/flathub.flatpakrepo";
      "launcher-moe" = "https://gol.launcher.moe/gol.launcher.moe.flatpakrepo";
    };
    packages = [
     "flathub:app/com.github.tchx84.Flatseal/x86_64/stable"
     "flathub:app/com.steamgriddb.SGDBoop/x86_64/stable"
     "flathub:app/com.stremio.Stremio/x86_64/stable"
     "flathub:app/com.usebottles.bottles/x86_64/stable"
     "flathub:app/com.wps.Office/x86_64/stable"
     "flathub:app/io.github.Foldex.AdwSteamGtk/x86_64/stable"
     "flathub:app/io.github.aandrew_me.ytdn/x86_64/stable"
     "flathub:app/io.wavebox.Wavebox/x86_64/stable"
     "flathub:app/net.codeindustry.MasterPDFEditor/x86_64/stable"
     "flathub:app/net.cozic.joplin_desktop/x86_64/stable"
     "flathub:app/org.upscayl.Upscayl/x86_64/stable"
     "flathub:app/org.videolan.VLC/x86_64/stable"
     "launcher-moe:app/moe.launcher.the-honkers-railway-launcher/x86_64/master"
     "launcher-moe:app/moe.launcher.an-anime-borb-launcher/x86_64/master"
     "launcher-moe:app/moe.launcher.an-anime-game-launcher/x86_64/master"
     "launcher-moe:app/moe.launcher.honkers-launcher/x86_64/master"
     "flathub:runtime/org.freedesktop.Platform.VulkanLayer.gamescope/x86_64/22.08"
     "flathub:runtime/org.freedesktop.Platform.VulkanLayer.MangoHud/x86_64/22.08"
     ":${./xwaylandvideobridge.flatpak}"
    ];
  };
}

bayazidbh avatar Aug 04 '23 02:08 bayazidbh

I pushed an update, try again

in-a-dil-emma avatar Aug 04 '23 12:08 in-a-dil-emma

Seems to work fine now, from my testing. Out of curiosity, does it work with a direct link to the .flatpak file? Would be useful with rustdesk-nightly. Also, what if we have an out-of-tree flatpak installed, and then activated the service? Not touching this anymore for today since I had a scare with HM yesterday and I have a presentation tomorrow...

bayazidbh avatar Aug 06 '23 05:08 bayazidbh

Hi, can you confirm that this update works on your end?

in-a-dil-emma avatar Aug 08 '23 15:08 in-a-dil-emma

I don't think there's been a new update in the dev branch? For the one from 5 days ago, as stated above, I've tested it and it seems fine.

Though I've been too busy to test beyond the same exact configuration as you have (.flatpak file in the same folder as the flatpak.nix config). Haven't tested flakes building from the git remote delete, and haven't tested hotlinking to the .flatpak file download directly as well.

bayazidbh avatar Aug 09 '23 01:08 bayazidbh

Hi again.

I will close this issue (for now) to tidy up the issue tracker.

Feel free to reopen this issue when something goes wrong.

Cheers.

in-a-dil-emma avatar Aug 10 '23 07:08 in-a-dil-emma

I just read this bit in the docs:

# out-of-tree flatpaks can be installed like this (note: they can't be a URL because flatpak doesn't like that)
[ ":${./foobar.flatpak}" "flathub:/root/testflatpak.flatpakref" ]

My plan for this is to preInitCommand to download the flatpak file with wget -P ${config.xdg.cacheHome}/flatpak/ -O .... Will have to test it, but I think it could be defined a sub-options like how override is now a sub-options of its own (another one which I had planned to just do through preInit/postInit sub-options).

bayazidbh avatar Aug 16 '23 02:08 bayazidbh

My plan for this is to preInitCommand to download the flatpak file with wget -P ${config.xdg.cacheHome}/flatpak/ -O ...

This should work.

I don't really like the idea of creating another option just for out-of-repo packages, maybe I will implement automatic downloading.

in-a-dil-emma avatar Aug 16 '23 11:08 in-a-dil-emma