diff --git a/.chezmoiscripts/run_onchange_before_10-install-packages.sh.tmpl b/.chezmoiscripts/run_onchange_before_10-install-packages.sh.tmpl index f925ae9..564a757 100755 --- a/.chezmoiscripts/run_onchange_before_10-install-packages.sh.tmpl +++ b/.chezmoiscripts/run_onchange_before_10-install-packages.sh.tmpl @@ -39,23 +39,26 @@ else rm -rf "$build_dir" fi -if [ "$UPDATE" = "1" ]; then - paru -Su --noconfirm -else - echo "Skipping paru upgrade (CHEZMOI_SYSTEM_UPDATE!=1)" -fi - -# install AUR packages +# Updates only when requested, otherwise install packages that are missing and leave the installed version. aur_pkgs=() {{ range .packages.aur }} -if ! pacman -Q "{{ . }}" &>/dev/null; then - aur_pkgs+=("{{ . }}") +name="{{ . }}" +if [ "$UPDATE" = "1" ] || ! pacman -Q "$name" &>/dev/null; then + aur_pkgs+=("$name") fi {{ end }} if [[ ${#aur_pkgs[@]} -gt 0 ]]; then - echo "Installing AUR packages..." - paru -S --noconfirm --needed "${aur_pkgs[@]}" + if [ "$UPDATE" = "1" ]; then + echo "Installing latest AUR packages..." + paru -Su --noconfirm + paru -S --noconfirm --needed "${aur_pkgs[@]}" + else + echo "Installing AUR packages..." + paru -S --noconfirm --needed "${aur_pkgs[@]}" + fi +elif [ "$UPDATE" != "1" ]; then + echo "Skipping AUR upgrades (CHEZMOI_SYSTEM_UPDATE!=1)" fi {{ end }} @@ -86,17 +89,21 @@ if ! command -v nix > /dev/null 2>&1; then else FLAKE_DIR="$HOME/.config/nixpkgs" - # Update profile - if [ "$UPDATE" = "1" ]; then - nix profile upgrade '.*' - else - echo "Skipping Nix profile upgrade (CHEZMOI_SYSTEM_UPDATE!=1)" - fi - - # Install packages + # Latest bumps flake.lock, (same as for go), otherwise install from the existing lock. if [ -d "$FLAKE_DIR" ] && [ -f "$FLAKE_DIR/flake.nix" ]; then - echo "Installing Nix packages..." - nix profile install "$FLAKE_DIR" || true + if [ "$UPDATE" = "1" ]; then + echo "Updating Nix packages to latest..." + nix flake update --flake "$FLAKE_DIR" + nix profile upgrade --all + nix profile install "$FLAKE_DIR" || true + else + echo "Skipping Nix profile upgrade (CHEZMOI_SYSTEM_UPDATE!=1)" + if [ -f "$FLAKE_DIR/flake.lock" ]; then + nix profile install --no-update-lock-file "$FLAKE_DIR" || true + else + nix profile install "$FLAKE_DIR" || true + fi + fi fi fi