diff options
Diffstat (limited to 'modules/system/nix-update')
| -rw-r--r-- | modules/system/nix-update/nix-update.sh | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/modules/system/nix-update/nix-update.sh b/modules/system/nix-update/nix-update.sh index e65a33c..79718fd 100644 --- a/modules/system/nix-update/nix-update.sh +++ b/modules/system/nix-update/nix-update.sh @@ -8,13 +8,13 @@ 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 -ONLY_SWITCH=false -TARGET="" +HOME_MANAGER_CONFIG_DIR="$HOME/.config/home-manager" +NIXOS_CONFIG_DIR="/etc/nixos" +ONLY_UPDATE_FLAKE_INPUTS=false +ONLY_SWITCH_CONFIGURATION=false +UPDATE_TARGET="" -usage() { +print_usage() { echo "Usage: $0 <home-manager|nixos|both> [--only-flake|--only-switch]" echo "" echo "Commands:" @@ -28,58 +28,58 @@ usage() { exit 1 } -parse_args() { +parse_command_line_arguments() { while [[ $# -gt 0 ]]; do case "$1" in home-manager | nixos | both) - if [[ -n "$TARGET" ]]; then + if [[ -n "$UPDATE_TARGET" ]]; then error "only one target allowed" - usage + print_usage fi - TARGET="$1" + UPDATE_TARGET="$1" shift ;; --only-flake) - ONLY_FLAKE=true + ONLY_UPDATE_FLAKE_INPUTS=true shift ;; --only-switch) - ONLY_SWITCH=true + ONLY_SWITCH_CONFIGURATION=true shift ;; -h | --help) - usage + print_usage ;; *) error "unknown option '$1'" - usage + print_usage ;; esac done - if [[ -z "$TARGET" ]]; then + if [[ -z "$UPDATE_TARGET" ]]; then error "no target specified" - usage + print_usage fi } -update_home_manager() { +update_home_manager_configuration() { info "Updating home-manager..." - cd "$HM_DIR" + cd "$HOME_MANAGER_CONFIG_DIR" info "Staging users/arpit/private.nix..." git add users/arpit/private.nix -f trap 'git rm --cached users/arpit/private.nix >/dev/null 2>&1 || true' EXIT INT TERM HUP - if [[ "$ONLY_SWITCH" == false ]]; then + if [[ "$ONLY_SWITCH_CONFIGURATION" == false ]]; then info "Running nix flake update..." nix flake update fi - if [[ "$ONLY_FLAKE" == false ]]; then + if [[ "$ONLY_UPDATE_FLAKE_INPUTS" == false ]]; then info "Running home-manager switch..." - home-manager switch --flake "$HM_DIR#arpit" + home-manager switch --flake "$HOME_MANAGER_CONFIG_DIR#arpit" fi info "Unstaging users/arpit/private.nix..." @@ -90,22 +90,22 @@ update_home_manager() { info "home-manager update complete" } -update_nixos() { +update_nixos_configuration() { info "Updating NixOS..." sudo -v - cd "$NIXOS_DIR" + cd "$NIXOS_CONFIG_DIR" info "Staging hardware-configuration.nix..." git add hardware-configuration.nix -f trap 'git rm --cached hardware-configuration.nix >/dev/null 2>&1 || true' EXIT INT TERM HUP - if [[ "$ONLY_SWITCH" == false ]]; then + if [[ "$ONLY_SWITCH_CONFIGURATION" == false ]]; then info "Running nix flake update..." nix flake update fi - if [[ "$ONLY_FLAKE" == false ]]; then + if [[ "$ONLY_UPDATE_FLAKE_INPUTS" == false ]]; then info "Running nixos-rebuild switch..." sudo nixos-rebuild switch fi @@ -118,17 +118,17 @@ update_nixos() { info "NixOS update complete" } -parse_args "$@" +parse_command_line_arguments "$@" -case "$TARGET" in +case "$UPDATE_TARGET" in home-manager) - update_home_manager + update_home_manager_configuration ;; nixos) - update_nixos + update_nixos_configuration ;; both) - update_nixos - update_home_manager + update_nixos_configuration + update_home_manager_configuration ;; esac |
