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 | |
| 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')
| -rw-r--r-- | modules/system/deep-clean/deep-clean.sh | 26 | ||||
| -rw-r--r-- | modules/system/nix-update/nix-update.sh | 43 |
2 files changed, 39 insertions, 30 deletions
diff --git a/modules/system/deep-clean/deep-clean.sh b/modules/system/deep-clean/deep-clean.sh index bb28182..d698bfd 100644 --- a/modules/system/deep-clean/deep-clean.sh +++ b/modules/system/deep-clean/deep-clean.sh @@ -1,35 +1,39 @@ #!/usr/bin/env bash set -euo pipefail -echo "--- Starting Nix Deep Clean (keeping only current generations) ---" +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; } + +info "Starting Nix Deep Clean (keeping only current generations)" if [[ $EUID -eq 0 ]]; then - echo "Error: Do not run this script with sudo." - echo "Run it as your normal user; it will ask for sudo when required." - exit 1 + die "Do not run this script with sudo. +Run it as your normal user; it will ask for sudo when required." fi -echo "Removing old NixOS system generations..." +info "Removing old NixOS system generations..." sudo nix-env -p /nix/var/nix/profiles/system --delete-generations +1 -echo "Removing old Home Manager generations..." +info "Removing old Home Manager generations..." if command -v home-manager &> /dev/null; then home-manager generations | \ awk 'NR>1 {print $1}' | \ xargs -r home-manager remove-generations fi -echo "Removing old user profile generations..." +info "Removing old user profile generations..." nix-env --delete-generations +1 -echo "Removing result symlinks..." +info "Removing result symlinks..." find . -name "result" -type l -delete -echo "Running garbage collector..." +info "Running garbage collector..." sudo nix-collect-garbage -d nix-collect-garbage -d -echo "Optimising Nix store..." +info "Optimising Nix store..." nix store optimise -echo "--- Cleanup Complete ---" +info "Cleanup Complete."
\ No newline at end of file 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 |
