Skip to content

Commit

Permalink
options: add uninstallUnused
Browse files Browse the repository at this point in the history
Add an option to uninstall unused applications
and runtimes.
  • Loading branch information
gmodena committed Dec 17, 2024
1 parent 8bdc254 commit a53b7a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/installer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ let
done
'';

flatpakUninstallUnusedCmd = installation: ''
${pkgs.flatpak}/bin/flatpak --${installation} uninstall --unused --noninteractive
'';

overridesDir =
if (installation == "system")
then "/var/lib/flatpak/overrides"
Expand Down Expand Up @@ -204,14 +208,19 @@ pkgs.writeShellScript "flatpak-managed-install" ''
# Uninstall remotes that have been removed from services.flatpak.packages
# since the previous activation.
${flatpakDeleteRemotesCmd installation cfg.uninstallUnmanaged {}}
${flatpakDeleteRemotesCmd installation cfg.uninstallUnmanaged {}}
# Install packages
${mkFlatpakInstallCmd installation updateApplications cfg.packages}
# Configure overrides
${flatpakOverridesCmd installation {}}
# Clean up installation
${if cfg.uninstallUnused
then flatpakUninstallUnusedCmd installation
else "# services.flatpak.uninstallUnused is not enabled "}
# Save state
${pkgs.coreutils}/bin/ln -sf ${stateFile} ${statePath}
''
9 changes: 9 additions & 0 deletions modules/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,13 @@ in
they would get uninstalled on the next activation. The same applies to remotes manually setup via `flatpak remote-add`
'';
};

uninstallUnused = mkOption {
type = with types; bool;
default = config.services.flatpak.uninstallUnmanaged || false;
description = ''
If enabled, uninstalls unused packages and runtimes.
Defaults to `config.services.flatpak.uninstallUnmanaged`, or `false`.
'';
};
}

0 comments on commit a53b7a2

Please sign in to comment.