Skip to content

Commit

Permalink
installer: forcefully delete remotes when managing state. (#86)
Browse files Browse the repository at this point in the history
Remove remotes even if refs are installed. This
can happen in case of manual installation or remotes
and packages. If the user sets
uninstallUnmanagedState = true forcefully remove
any eventuall dangling dependency.
  • Loading branch information
gmodena authored Oct 20, 2024
1 parent 8d1193a commit 849a15b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/installer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,16 @@ let
'';
flatpakAddRemote = installation: remotes: map (flatpakAddRemotesCmd installation) remotes;

flatpakDeleteRemotesCmd = installation: {}: ''
flatpakDeleteRemotesCmd = installation: uninstallUnmanagedState: {}: ''
# Delete all remotes that are present in the old state but not the new one
# $OLD_STATE and $NEW_STATE are globals, declared in the output of pkgs.writeShellScript.
# If uninstallUnmanagedState is true, then the remotes will be deleted forcefully.
${pkgs.jq}/bin/jq -r -n \
--argjson old "$OLD_STATE" \
--argjson new "$NEW_STATE" \
'(($old.remotes // []) - ($new.remotes // []))[]' \
| while read -r REMOTE_NAME; do
${pkgs.flatpak}/bin/flatpak remote-delete --${installation} $REMOTE_NAME
${pkgs.flatpak}/bin/flatpak remote-delete ${if uninstallUnmanagedState then " --force " else " " } --${installation} $REMOTE_NAME
done
'';

Expand Down Expand Up @@ -215,7 +216,7 @@ pkgs.writeShellScript "flatpak-managed-install" ''
# Uninstall remotes that have been removed from services.flatpak.packages
# since the previous activation.
${flatpakDeleteRemotesCmd installation {}}
${flatpakDeleteRemotesCmd installation uninstallUnmanagedState {}}
# Install packages
${mkFlatpakInstallCmd installation updateApplications cfg.packages}
Expand Down

3 comments on commit 849a15b

@LuNeder
Copy link

@LuNeder LuNeder commented on 849a15b Oct 20, 2024

Choose a reason for hiding this comment

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

Uhhh this seems to break nix-flatpak?

(Long error message I can send if u want, but ending with error: undefined variable 'uninstallUnmanagedState')

@gmodena
Copy link
Owner Author

@gmodena gmodena commented on 849a15b Oct 28, 2024

Choose a reason for hiding this comment

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

Sorry about that! I had borked a PR.

That issu should have been fixed in a subsequent patch and main should be usable.

@LuNeder
Copy link

Choose a reason for hiding this comment

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

Thanks!! ^-^

Please sign in to comment.