From 812db7c511d14cbc34645aa082bb74d5908e8b8d Mon Sep 17 00:00:00 2001 From: Gabriele Modena Date: Tue, 23 Jan 2024 23:00:11 +0100 Subject: [PATCH] installer: don't uninstall on empty OLD_STATE. Check that OLD_STATE has been populated before attempting to diff it with NEW_STATE to determine what packages to uninstall. --- modules/installer.nix | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/installer.nix b/modules/installer.nix index f351ef8..9294c2f 100644 --- a/modules/installer.nix +++ b/modules/installer.nix @@ -30,13 +30,16 @@ let flatpakUninstallCmd = installation: {}: '' # Uninstall all packages that are present in the old state but not the new one - ${pkgs.jq}/bin/jq -r -n \ - --argjson old "$OLD_STATE" \ - --argjson new "$NEW_STATE" \ - '($old.packages - $new.packages)[]' \ + # $OLD_STATE and $NEW_STATE are globals, declared in the output of pkgs.writeShellScript. + if [ "$OLD_STATE" != "{}" ]; then + ${pkgs.jq}/bin/jq -r -n \ + --argjson old "$OLD_STATE" \ + --argjson new "$NEW_STATE" \ + '($old.packages - $new.packages)[]' \ | while read -r APP_ID; do ${pkgs.flatpak}/bin/flatpak uninstall --${installation} -y $APP_ID - done + done + fi ''; flatpakInstallCmd = installation: update: { appId, origin ? "flathub", commit ? null, ... }: ''