From 610e951914eb60683e24c610a3ecbaeb848e2900 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Fri, 21 Aug 2026 04:35:03 +0530 Subject: script: added --only-switch mode to nix-update script - added --only-switch option to nix-update script, that just runs home-manager switch or nixos-rebuild switch and no nix flake update - renamed the --flake-only option to --only-flake for consistency --- modules/scripts/nix-update/script.sh | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'modules/scripts/nix-update/script.sh') diff --git a/modules/scripts/nix-update/script.sh b/modules/scripts/nix-update/script.sh index 7f2b6d0..0f1c0c1 100644 --- a/modules/scripts/nix-update/script.sh +++ b/modules/scripts/nix-update/script.sh @@ -4,11 +4,12 @@ set -euo pipefail HM_DIR="$HOME/.config/home-manager" NIXOS_DIR="/etc/nixos" -FLAKE_ONLY=false +ONLY_FLAKE=false +ONLY_SWITCH=false TARGET="" usage() { - echo "Usage: nix-update [--flake-only]" + echo "Usage: nix-update [--only-flake|--only-switch]" echo "" echo "Options:" echo " home-manager Update and switch home-manager configuration" @@ -16,7 +17,8 @@ usage() { echo " both Update and switch both configurations" echo "" echo "Flags:" - echo " --flake-only Only run nix flake update, skip switch commands" + echo " --only-flake Only run nix flake update, skip switch commands" + echo " --only-switch Only run switch commands, skip nix flake update" exit 1 } @@ -31,8 +33,12 @@ parse_args() { TARGET="$1" shift ;; - --flake-only) - FLAKE_ONLY=true + --only-flake) + ONLY_FLAKE=true + shift + ;; + --only-switch) + ONLY_SWITCH=true shift ;; -h | --help) @@ -58,16 +64,20 @@ update_home_manager() { echo " Staging modules/private..." git add modules/private -f - echo " Running nix flake update..." - nix flake update + if [[ "$ONLY_SWITCH" == false ]]; then + echo " Running nix flake update..." + nix flake update + fi - if [[ "$FLAKE_ONLY" == false ]]; then + if [[ "$ONLY_FLAKE" == false ]]; then echo " Running home-manager switch..." home-manager switch --flake "$HM_DIR#arpit" fi echo " Unstaging modules/private..." - git rm --cached -r modules/private + for f in modules/private/*.nix; do + [[ "$f" == *.example.nix ]] || git rm --cached "$f" + done echo "==> home-manager update complete" } @@ -80,10 +90,12 @@ update_nixos() { echo " Staging hardware-configuration.nix..." git add hardware-configuration.nix -f - echo " Running nix flake update..." - nix flake update + if [[ "$ONLY_SWITCH" == false ]]; then + echo " Running nix flake update..." + nix flake update + fi - if [[ "$FLAKE_ONLY" == false ]]; then + if [[ "$ONLY_FLAKE" == false ]]; then echo " Running nixos-rebuild switch..." sudo nixos-rebuild switch fi -- cgit v1.2.3