aboutsummaryrefslogtreecommitdiffstats
path: root/modules/system/nix-update/nix-update.sh
diff options
context:
space:
mode:
Diffstat (limited to 'modules/system/nix-update/nix-update.sh')
-rw-r--r--modules/system/nix-update/nix-update.sh83
1 files changed, 43 insertions, 40 deletions
diff --git a/modules/system/nix-update/nix-update.sh b/modules/system/nix-update/nix-update.sh
index 79718fd..6ceaaa3 100644
--- a/modules/system/nix-update/nix-update.sh
+++ b/modules/system/nix-update/nix-update.sh
@@ -3,10 +3,13 @@
set -euo pipefail
-info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
-warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; }
+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; }
+die() {
+ error "$*"
+ exit 1
+}
HOME_MANAGER_CONFIG_DIR="$HOME/.config/home-manager"
NIXOS_CONFIG_DIR="/etc/nixos"
@@ -31,33 +34,33 @@ print_usage() {
parse_command_line_arguments() {
while [[ $# -gt 0 ]]; do
case "$1" in
- home-manager | nixos | both)
- if [[ -n "$UPDATE_TARGET" ]]; then
- error "only one target allowed"
- print_usage
- fi
- UPDATE_TARGET="$1"
- shift
- ;;
- --only-flake)
- ONLY_UPDATE_FLAKE_INPUTS=true
- shift
- ;;
- --only-switch)
- ONLY_SWITCH_CONFIGURATION=true
- shift
- ;;
- -h | --help)
- print_usage
- ;;
- *)
- error "unknown option '$1'"
+ home-manager | nixos | both)
+ if [[ -n $UPDATE_TARGET ]]; then
+ error "only one target allowed"
print_usage
- ;;
+ fi
+ UPDATE_TARGET="$1"
+ shift
+ ;;
+ --only-flake)
+ ONLY_UPDATE_FLAKE_INPUTS=true
+ shift
+ ;;
+ --only-switch)
+ ONLY_SWITCH_CONFIGURATION=true
+ shift
+ ;;
+ -h | --help)
+ print_usage
+ ;;
+ *)
+ error "unknown option '$1'"
+ print_usage
+ ;;
esac
done
- if [[ -z "$UPDATE_TARGET" ]]; then
+ if [[ -z $UPDATE_TARGET ]]; then
error "no target specified"
print_usage
fi
@@ -72,12 +75,12 @@ update_home_manager_configuration() {
trap 'git rm --cached users/arpit/private.nix >/dev/null 2>&1 || true' EXIT INT TERM HUP
- if [[ "$ONLY_SWITCH_CONFIGURATION" == false ]]; then
+ if [[ $ONLY_SWITCH_CONFIGURATION == false ]]; then
info "Running nix flake update..."
nix flake update
fi
- if [[ "$ONLY_UPDATE_FLAKE_INPUTS" == false ]]; then
+ if [[ $ONLY_UPDATE_FLAKE_INPUTS == false ]]; then
info "Running home-manager switch..."
home-manager switch --flake "$HOME_MANAGER_CONFIG_DIR#arpit"
fi
@@ -100,12 +103,12 @@ update_nixos_configuration() {
trap 'git rm --cached hardware-configuration.nix >/dev/null 2>&1 || true' EXIT INT TERM HUP
- if [[ "$ONLY_SWITCH_CONFIGURATION" == false ]]; then
+ if [[ $ONLY_SWITCH_CONFIGURATION == false ]]; then
info "Running nix flake update..."
nix flake update
fi
- if [[ "$ONLY_UPDATE_FLAKE_INPUTS" == false ]]; then
+ if [[ $ONLY_UPDATE_FLAKE_INPUTS == false ]]; then
info "Running nixos-rebuild switch..."
sudo nixos-rebuild switch
fi
@@ -121,14 +124,14 @@ update_nixos_configuration() {
parse_command_line_arguments "$@"
case "$UPDATE_TARGET" in
- home-manager)
- update_home_manager_configuration
- ;;
- nixos)
- update_nixos_configuration
- ;;
- both)
- update_nixos_configuration
- update_home_manager_configuration
- ;;
+home-manager)
+ update_home_manager_configuration
+ ;;
+nixos)
+ update_nixos_configuration
+ ;;
+both)
+ update_nixos_configuration
+ update_home_manager_configuration
+ ;;
esac