diff options
| author | arpitchakladar <arpitchakladar@gmail.com> | 2026-09-09 23:29:20 +0530 |
|---|---|---|
| committer | arpitchakladar <arpitchakladar@gmail.com> | 2026-09-09 23:29:20 +0530 |
| commit | d2e6e6b5de1d56d53aee2da81c2e9ee553971c72 (patch) | |
| tree | feee7479f6b4574696cc6d780f55ce044cafa3bc /modules/system/nix-update/nix-update.sh | |
| parent | 7879122dfc8e7ca7b905e10d5f55df09f9051295 (diff) | |
| download | home-manager-config-d2e6e6b5de1d56d53aee2da81c2e9ee553971c72.tar.gz home-manager-config-d2e6e6b5de1d56d53aee2da81c2e9ee553971c72.zip | |
refactor(modules): consistent message formats across all scripts
Diffstat (limited to 'modules/system/nix-update/nix-update.sh')
| -rw-r--r-- | modules/system/nix-update/nix-update.sh | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/modules/system/nix-update/nix-update.sh b/modules/system/nix-update/nix-update.sh index 0f499db..943a1d8 100644 --- a/modules/system/nix-update/nix-update.sh +++ b/modules/system/nix-update/nix-update.sh @@ -2,6 +2,11 @@ set -euo pipefail +info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } +warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } +error() { printf '\033[1;31m==> error:\033[0m %s\n' "$*" >&2; } +die() { error "$*"; exit 1; } + HM_DIR="$HOME/.config/home-manager" NIXOS_DIR="/etc/nixos" ONLY_FLAKE=false @@ -9,14 +14,14 @@ ONLY_SWITCH=false TARGET="" usage() { - echo "Usage: nix-update <home-manager|nixos|both> [--only-flake|--only-switch]" + echo "Usage: $0 <home-manager|nixos|both> [--only-flake|--only-switch]" echo "" - echo "Options:" + echo "Commands:" echo " home-manager Update and switch home-manager configuration" echo " nixos Update and switch NixOS configuration" echo " both Update and switch both configurations" echo "" - echo "Flags:" + echo "Options:" echo " --only-flake Only run nix flake update, skip switch commands" echo " --only-switch Only run switch commands, skip nix flake update" exit 1 @@ -27,7 +32,7 @@ parse_args() { case "$1" in home-manager | nixos | both) if [[ -n "$TARGET" ]]; then - echo "Error: only one target allowed" + error "only one target allowed" usage fi TARGET="$1" @@ -45,63 +50,63 @@ parse_args() { usage ;; *) - echo "Error: unknown option '$1'" + error "unknown option '$1'" usage ;; esac done if [[ -z "$TARGET" ]]; then - echo "Error: no target specified" + error "no target specified" usage fi } update_home_manager() { - echo "==> Updating home-manager..." + info "Updating home-manager..." cd "$HM_DIR" - echo " Staging users/arpit/private.nix..." + info "Staging users/arpit/private.nix..." git add users/arpit/private.nix -f if [[ "$ONLY_SWITCH" == false ]]; then - echo " Running nix flake update..." + info "Running nix flake update..." nix flake update fi if [[ "$ONLY_FLAKE" == false ]]; then - echo " Running home-manager switch..." + info "Running home-manager switch..." home-manager switch --flake "$HM_DIR#arpit" fi - echo " Unstaging users/arpit/private.nix..." + info "Unstaging users/arpit/private.nix..." git rm --cached users/arpit/private.nix - echo "==> home-manager update complete" + info "home-manager update complete" } update_nixos() { - echo "==> Updating NixOS..." + info "Updating NixOS..." sudo -v cd "$NIXOS_DIR" - echo " Staging hardware-configuration.nix..." + info "Staging hardware-configuration.nix..." git add hardware-configuration.nix -f if [[ "$ONLY_SWITCH" == false ]]; then - echo " Running nix flake update..." + info "Running nix flake update..." nix flake update fi if [[ "$ONLY_FLAKE" == false ]]; then - echo " Running nixos-rebuild switch..." + info "Running nixos-rebuild switch..." sudo nixos-rebuild switch fi - echo " Unstaging hardware-configuration.nix..." + info "Unstaging hardware-configuration.nix..." git rm --cached hardware-configuration.nix - echo "==> NixOS update complete" + info "NixOS update complete" } parse_args "$@" @@ -117,4 +122,4 @@ case "$TARGET" in update_nixos update_home_manager ;; -esac +esac
\ No newline at end of file |
