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

ref: fix remote origin management #93

Merged
merged 3 commits into from
Nov 15, 2024
Merged

ref: fix remote origin management #93

merged 3 commits into from
Nov 15, 2024

Conversation

gmodena
Copy link
Owner

@gmodena gmodena commented Nov 7, 2024

When a flatpakref file does not provide a SuggestRemoteName key, create an origin from the Name field.

This change implements the algorithm found in flatpak's create_origin_remote_config() function.

Remove the option of setting an origin label in packageOption. This option was poorly documented, and its default behavior ( labeling as "flathub" if no origin was set) would break system activation.

Fixes #90

When a flatpakref file does not provide a SuggestRemoteName key,
create an origin from the Name field.

This change implements the algorithm found in flatpak's
create_origin_remote_config() function.

Remove the option of setting an origin label in packageOption.
This option was poorly documented, and its default behavior
- labeling as "flathub" if no origin was set -
would break system activation.
@gmodena gmodena self-assigned this Nov 7, 2024
@gmodena gmodena marked this pull request as draft November 7, 2024 22:06
Renaming for consistency.
@SpiderUnderUrBed
Copy link

I tried this branch and I still get the same issue:

× flatpak-managed-install.service
     Loaded: loaded (/etc/systemd/system/flatpak-managed-install.service; enabled; preset: ignored)
     Active: failed (Result: exit-code) since Sun 2024-11-10 17:58:46 NZDT; 1s ago
 Invocation: 1b07764a2d7d4367bb95ceabc6b732ea
    Process: 530810 ExecStart=/nix/store/m7mi2zaxlbcj78kbd81gg1lqbslzl8vd-flatpak-managed-install (code=exited, status=1/FAILURE)
   Main PID: 530810 (code=exited, status=1/FAILURE)
         IP: 93.6K in, 16.4K out
         IO: 15.3M read, 164K written
   Mem peak: 43.6M
        CPU: 2.276s

Nov 10 17:58:37 daspidercave systemd[1]: Starting flatpak-managed-install.service...
Nov 10 17:58:41 daspidercave m7mi2zaxlbcj78kbd81gg1lqbslzl8vd-flatpak-managed-install[530866]: Skipping: moe.launcher.the-honkers-railway-launcher/x86_64/master is already installed
Nov 10 17:58:43 daspidercave m7mi2zaxlbcj78kbd81gg1lqbslzl8vd-flatpak-managed-install[530873]: Skipping: moe.launcher.an-anime-game-launcher/x86_64/master is already installed
Nov 10 17:58:46 daspidercave m7mi2zaxlbcj78kbd81gg1lqbslzl8vd-flatpak-managed-install[530885]: error: No remote refs found for ‘org.vinegarhq.Sober’
Nov 10 17:58:46 daspidercave systemd[1]: flatpak-managed-install.service: Main process exited, code=exited, status=1/FAILURE
Nov 10 17:58:46 daspidercave systemd[1]: flatpak-managed-install.service: Failed with result 'exit-code'.
Nov 10 17:58:46 daspidercave systemd[1]: Failed to start flatpak-managed-install.service.
Nov 10 17:58:46 daspidercave systemd[1]: flatpak-managed-install.service: Consumed 2.276s CPU time, 43.6M memory peak, 15.3M read from disk, 164K written to disk, 93.1K incoming IP traffic, 16.4K outgoing IP traffic.

I will try the steps you suggested in the issue but the cause might not be what you made a fix for.

Test if the remote exists before deleting it. This guards against two potential issues:
1. A Flatpakref might install non-enumerable remotes that are automatically deleted
   when the application is uninstalled, so attempting to delete them without checking
   could cause errors.
2. Users might manually delete apps/remotes, which could impact nix-flatpak state;
   checking prevents errors if the remote has already been removed.
@gmodena
Copy link
Owner Author

gmodena commented Nov 11, 2024

Hey,

error: No remote refs found for ‘org.vinegarhq.Sober’

This suggests that the Flatpak .flatpakref installation code path has not been triggered. Could you try cleaning up the local Flatpak installation as described in this issue comment?"

@SpiderUnderUrBed
Copy link

SpiderUnderUrBed commented Nov 11, 2024

If you saw the message I just deleted, ignore that, the issue has unfortunately manifested again, surprisingly, it was still there after full system re-install so I would be surprised if this issue would be difficult to reproduce on your end.

[spiderunderurbed@daspidercave:~/home-manager]$ flatpak uninstall org.vinegarhq.Sober
        ID                         Branch       Op
 1. [-] org.vinegarhq.Sober        master       r

Uninstall complete.

[spiderunderurbed@daspidercave:~/home-manager]$ flatpak remotes 
Name         Options
flathub      system
flathub-beta system
gol          system
flathub      user

[spiderunderurbed@daspidercave:~/home-manager]$ sudo rm /nix/var/nix/gcroots/flatpak-state.json
[sudo] password for spiderunderurbed: 

Something to note, when I do all of these steps, the issue is not present on the next activation, but the activation after that (and all following activations), I cant imagine how I got a "No remote refs for .." error for any rebuild after one where sober was not installed in any form. Also given the fact I tried this on a freshly installed system the issue should definitely be reproducable and related to nix-flatpak.

@gmodena
Copy link
Owner Author

gmodena commented Nov 11, 2024

Also given the fact I tried this on a freshly installed system the issue should definitely be reproducable and related to nix-flatpak.

I'm really at a loss here. Let me walk you through what I did to test this PR.

Note: the snippets below are from a VM, but the same behavior occurs on my daily driver, which has a much more complex configuration. Can you help me pinpoint what might be different on my end, compared to what you are doing?

Setup

I'm loading nix flatpak as a nixos module. The flake input is set to:

flatpaks.url = "github:gmodena/nix-flatpak?ref=fix-flatpakref-install";

Flatpakref in a freshly built VM

I spin up a freshly built vm (build atop the config in testing-base). This is what the initial flatpak config looks like:

# flatpak.nix
{ lib, ... }: {

  services.flatpak.remotes = lib.mkOptionDefault [{
    name = "flathub-beta";
    location = "https://flathub.org/beta-repo/flathub-beta.flatpakrepo";
  }];

  services.flatpak.update.auto.enable = true;
  services.flatpak.uninstallUnmanaged = true;
  services.flatpak.packages = [
    { 
      flatpakref="https://sober.vinegarhq.org/sober.flatpakref";
      sha256="1pj8y1xhiwgbnhrr3yr3ybpfis9slrl73i0b1lc9q89vhip6ym2l";
    }
  ];
}

At boot, Sober and its remote are installed:

[root@nixos:~]# flatpak remotes
Name         Options
flathub      system
flathub-beta system
sober        system

[root@nixos:~]# flatpak list --app
Name        Application ID            Version             Branch       Installation
Sober       org.vinegarhq.Sober       0.0.0-78a4e30       master       system

[root@nixos:~]# cat /nix/var/nix/gcroots/flatpak-state.json 
{"overrides":{},"packages":["org.vinegarhq.Sober"],"remotes":["flathub","flathub-beta","sober"]}

I build the first generation with:

[root@nixos:~/config]# nixos-rebuild switch --flake '.'

Which is

[root@nixos:~/config]# nixos-rebuild list-generations
Generation  Build-date           NixOS version           Kernel  Configuration Revision  Specialisation
1 current   2024-11-11 22:17:47  23.11.20240709.205fd42  6.1.96                          *

Sober's remote and flatpak-state are the same as the build. Now I'll run nixos-rebuild switch --flake '.' a couple more times.

I tried adding new Flatpaks at activations 3 (im.riot.Riot) and 4 (com.logseq.Logseq), and removed them at 5 and 6 to see if that would trigger any unusual code paths. Every activation succeeded.

[root@nixos:~/config]# nixos-rebuild list-generations
Generation  Build-date           NixOS version           Kernel  Configuration Revision  Specialisation
7 current   2024-11-11 22:36:16  23.11.20240709.205fd42  6.1.96                          *
6           2024-11-11 22:35:38  23.11.20240709.205fd42  6.1.96                          *
5           2024-11-11 22:27:49  23.11.20240709.205fd42  6.1.96                          *
4           2024-11-11 22:23:14  23.11.20240709.205fd42  6.1.96                          *
3           2024-11-11 22:22:18  23.11.20240709.205fd42  6.1.96                          *
2           2024-11-11 22:20:26  23.11.20240709.205fd42  6.1.96                          *
1           2024-11-11 22:17:47  23.11.20240709.205fd42  6.1.96                          *

By generation 7, I only have Sober.

[root@nixos:~/config]# flatpak remotes
Name         Options
flathub      system
flathub-beta system
sober        system

[root@nixos:~/config]# flatpak list --app
Name        Application ID            Version             Branch       Installation
Sober       org.vinegarhq.Sober       0.0.0-78a4e30       master       system

Let's check the service status:

○ flatpak-managed-install.service
     Loaded: loaded (/etc/systemd/system/flatpak-managed-install.service; enabled; preset: enabled)
     Active: inactive (dead) since Mon 2024-11-11 22:36:19 UTC; 1min 22s ago
TriggeredBy: ● flatpak-managed-install.timer
    Process: 11137 ExecStart=/nix/store/1cazmcxv9nb97il5fxai0mixp5xk1gng-flatpak-managed-install (code=exited, status=0/SUCCESS)
   Main PID: 11137 (code=exited, status=0/SUCCESS)
         IP: 1.4M in, 15.2K out
        CPU: 691ms

Nov 11 22:36:17 nixos systemd[1]: Starting flatpak-managed-install.service...
Nov 11 22:36:18 nixos 1cazmcxv9nb97il5fxai0mixp5xk1gng-flatpak-managed-install[11247]:  1.                   com.logseq.Logseq        stable        r
Nov 11 22:36:18 nixos 1cazmcxv9nb97il5fxai0mixp5xk1gng-flatpak-managed-install[11247]: Uninstalling…
Nov 11 22:36:18 nixos flatpak[11247]: system: Uninstalled app/com.logseq.Logseq/x86_64/stable
Nov 11 22:36:18 nixos 1cazmcxv9nb97il5fxai0mixp5xk1gng-flatpak-managed-install[11247]: Uninstall complete.
Nov 11 22:36:19 nixos systemd[1]: flatpak-managed-install.service: Deactivated successfully.
Nov 11 22:36:19 nixos systemd[1]: Finished flatpak-managed-install.service.
Nov 11 22:36:19 nixos systemd[1]: flatpak-managed-install.service: Consumed 691ms CPU time, received 1.4M IP traffic, sent 15.2K IP traffic.

Remove and then re-install a flatpakref

As a further test, I removed sober (by commenting out the flatpakref config) and then re-installed it.

  services.flatpak.packages = [
  #  { 
  #    flatpakref="https://sober.vinegarhq.org/sober.flatpakref";
  #    sha256="1pj8y1xhiwgbnhrr3yr3ybpfis9slrl73i0b1lc9q89vhip6ym2l";
  #  }
  ];
[root@nixos:~/config]# nixos-rebuild switch --flake '.'

Generation  Build-date           NixOS version           Kernel  Configuration Revision  Specialisation
8 current   2024-11-11 22:42:45  23.11.20240709.205fd42  6.1.96                          *
7           2024-11-11 22:36:16  23.11.20240709.205fd42  6.1.96                          *
6           2024-11-11 22:35:38  23.11.20240709.205fd42  6.1.96                          *
5           2024-11-11 22:27:49  23.11.20240709.205fd42  6.1.96                          *
4           2024-11-11 22:23:14  23.11.20240709.205fd42  6.1.96                          *
3           2024-11-11 22:22:18  23.11.20240709.205fd42  6.1.96                          *
2           2024-11-11 22:20:26  23.11.20240709.205fd42  6.1.96                          *
1           2024-11-11 22:17:47  23.11.20240709.205fd42  6.1.96                          *

By generation 8 there is no Sober installed:

[root@nixos:~/config]# flatpak remotes
Name         Options
flathub      system
flathub-beta system

[root@nixos:~/config]# flatpak list --app


[root@nixos:~/config]# cat /nix/var/nix/gcroots/flatpak-state.json 
{"overrides":{},"packages":[],"remotes":["flathub","flathub-beta"]}

Let's check the service status:

[root@nixos:~/config]# systemctl status flatpak-managed-install
○ flatpak-managed-install.service
     Loaded: loaded (/etc/systemd/system/flatpak-managed-install.service; enabled; preset: enabled)
     Active: inactive (dead) since Mon 2024-11-11 22:42:47 UTC; 2min 14s ago
TriggeredBy: ● flatpak-managed-install.timer
    Process: 11796 ExecStart=/nix/store/kn9q9kgxfimyb40pl99bmmabanh9fspp-flatpak-managed-install (code=exited, status=0/SUCCESS)
   Main PID: 11796 (code=exited, status=0/SUCCESS)
         IP: 21.4K in, 3.8K out
        CPU: 367ms

Nov 11 22:42:46 nixos systemd[1]: Starting flatpak-managed-install.service...
Nov 11 22:42:46 nixos kn9q9kgxfimyb40pl99bmmabanh9fspp-flatpak-managed-install[11906]:  1.                   org.vinegarhq.Sober        master        r
Nov 11 22:42:46 nixos kn9q9kgxfimyb40pl99bmmabanh9fspp-flatpak-managed-install[11906]: Uninstalling…
Nov 11 22:42:46 nixos flatpak[11906]: system: Uninstalled app/org.vinegarhq.Sober/x86_64/master
Nov 11 22:42:47 nixos kn9q9kgxfimyb40pl99bmmabanh9fspp-flatpak-managed-install[11906]: Uninstall complete.
Nov 11 22:42:47 nixos flatpak[11931]: system: Removed remote sober
Nov 11 22:42:47 nixos systemd[1]: flatpak-managed-install.service: Deactivated successfully.
Nov 11 22:42:47 nixos systemd[1]: Finished flatpak-managed-install.service.
Nov 11 22:42:47 nixos systemd[1]: flatpak-managed-install.service: Consumed 367ms CPU time, received 21.4K IP traffic, sent 3.8K IP traffic.

Now let's re-install Sober:

  services.flatpak.packages = [
    { 
      flatpakref="https://sober.vinegarhq.org/sober.flatpakref";
      sha256="1pj8y1xhiwgbnhrr3yr3ybpfis9slrl73i0b1lc9q89vhip6ym2l";
    }
  ];

After activation:

Generation  Build-date           NixOS version           Kernel  Configuration Revision  Specialisation
9 current   2024-11-11 22:45:45  23.11.20240709.205fd42  6.1.96                          *
8           2024-11-11 22:42:45  23.11.20240709.205fd42  6.1.96                          *
7           2024-11-11 22:36:16  23.11.20240709.205fd42  6.1.96                          *
6           2024-11-11 22:35:38  23.11.20240709.205fd42  6.1.96                          *
5           2024-11-11 22:27:49  23.11.20240709.205fd42  6.1.96                          *
4           2024-11-11 22:23:14  23.11.20240709.205fd42  6.1.96                          *
3           2024-11-11 22:22:18  23.11.20240709.205fd42  6.1.96                          *
2           2024-11-11 22:20:26  23.11.20240709.205fd42  6.1.96                          *
1           2024-11-11 22:17:47  23.11.20240709.205fd42  6.1.96                          *

At generation 9, sober has been installed again:

[root@nixos:~/config]# flatpak remotes
Name         Options
flathub      system
flathub-beta system
sober        system

[root@nixos:~/config]# flatpak list --app
Name        Application ID            Version             Branch       Installation
Sober       org.vinegarhq.Sober       0.0.0-78a4e30       master       system

[root@nixos:~/config]# cat /nix/var/nix/gcroots/flatpak-state.json 
{"overrides":{},"packages":["org.vinegarhq.Sober"],"remotes":["flathub","flathub-beta","sober"]}

I've run nixos-rebuild a couple more times. Let's check the service status:

[root@nixos:~/config]# systemctl status flatpak-managed-install
○ flatpak-managed-install.service
     Loaded: loaded (/etc/systemd/system/flatpak-managed-install.service; enabled; preset: enabled)
     Active: inactive (dead) since Mon 2024-11-11 22:49:18 UTC; 1s ago
TriggeredBy: ● flatpak-managed-install.timer
    Process: 13354 ExecStart=/nix/store/1cazmcxv9nb97il5fxai0mixp5xk1gng-flatpak-managed-install (code=exited, status=0/SUCCESS)
   Main PID: 13354 (code=exited, status=0/SUCCESS)
         IP: 70.4K in, 9.4K out
        CPU: 328ms

Nov 11 22:49:17 nixos systemd[1]: Starting flatpak-managed-install.service...
Nov 11 22:49:18 nixos systemd[1]: flatpak-managed-install.service: Deactivated successfully.
Nov 11 22:49:18 nixos systemd[1]: Finished flatpak-managed-install.service.
Nov 11 22:49:18 nixos systemd[1]: flatpak-managed-install.service: Consumed 328ms CPU time, received 70.4K IP traffic, sent 9.4K IP traffic.

@gmodena
Copy link
Owner Author

gmodena commented Nov 15, 2024

I'm merging after about a week of daily driving and tests in VM.

I won't resolve #90 yet.

@gmodena gmodena merged commit 8db1648 into main Nov 15, 2024
1 check passed
@gmodena gmodena deleted the fix-flatpakref-install branch November 15, 2024 19:22
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.

nix-flatpak keeps on uninstalling a remote before adding the remote from a flatpakref
2 participants