function nix_upgrade --description "Upgrade nix packages" # Step 1: Update Nixpkgs channel nix-channel --update # Step 2: Determine changes, if any set --local nix_pkgs_filepath "$HOME/.config/nix/packages.nix" set --local nix_pkgs_available (nix-env -qacf "$nix_pkgs_filepath" | grep -v ' = ' | string collect) set --local nix_pkgs_installed (nix-env -qcf "$nix_pkgs_filepath" | grep -v ' = ' | string collect) if test -z "$nix_pkgs_available" && test -z "$nix_pkgs_installed" echo "All packages up-to-date." return 0 end set --local nix_pkgs_upd (echo $nix_pkgs_available | grep -v ' - \? ' | awk '{print $1}') set --local nix_pkgs_out (echo $nix_pkgs_installed | grep -v ' - \? ' | awk '{print $1}') set --local nix_pkgs_add (echo $nix_pkgs_available | grep ' - \? ' | awk '{print $1}') set --local nix_pkgs_rem (echo $nix_pkgs_installed | grep ' - \? ' | awk '{print $1}') test -z "$nix_pkgs_add" || echo "Added packages: $nix_pkgs_add" test -z "$nix_pkgs_upd" || echo "Updated packages: $nix_pkgs_upd" test -z "$nix_pkgs_out" || echo "Outdated packages: $nix_pkgs_out" test -z "$nix_pkgs_rem" || echo "Removed packages: $nix_pkgs_rem" # Step 3: Confirm changes if confirm "Continue with upgrade?" nix-env -irf "$nix_pkgs_filepath" end end