Compare commits

..

No commits in common. "bd5d09aaa69efe14c0025a4e84c3fe66f8c23f84" and "91459095f0a593c4988ce36418acc1cfdc9eff63" have entirely different histories.

3 changed files with 35 additions and 55 deletions

View file

@ -7,8 +7,6 @@
hostname, hostname,
nix, nix,
nixos-rebuild-ng, nixos-rebuild-ng,
nix-output-monitor,
dix,
... ...
}: }:
@ -28,7 +26,5 @@ writeShellApplication {
hostname hostname
nix nix
nixos-rebuild-ng nixos-rebuild-ng
nix-output-monitor
dix
]; ];
} }

View file

@ -11,11 +11,6 @@ UPDATE_INPUTS="" # Default list of inputs to update. Empty means
ROLLBACK=0 # Default to not rollback ROLLBACK=0 # Default to not rollback
SHOW_TRACE=0 # Default to not show detailed error messages SHOW_TRACE=0 # Default to not show detailed error messages
# Output functions
_status() { echo -e "\033[0;34m> $1\033[0m"; }
success() { echo -e "\033[0;32m$1\033[0m"; }
error() { echo -e "\033[0;31mError: $1\033[0m" >&2; exit 1; }
# Function to display the help message # Function to display the help message
Help() { Help() {
echo "Wrapper script for 'nixos-rebuild switch' and 'home-manager switch' commands." echo "Wrapper script for 'nixos-rebuild switch' and 'home-manager switch' commands."
@ -42,6 +37,12 @@ Help() {
echo " -u, --user <user> Specify the username (as in 'homeConfigurations.<user>@<host>'). Default: $HOME_USER" echo " -u, --user <user> Specify the username (as in 'homeConfigurations.<user>@<host>'). Default: $HOME_USER"
} }
# Function to handle errors
error() {
echo "Error: $1"
exit 1
}
# Function to rebuild NixOS configuration # Function to rebuild NixOS configuration
Rebuild_nixos() { Rebuild_nixos() {
local FLAKE="$FLAKE_PATH#$NIXOS_HOST" local FLAKE="$FLAKE_PATH#$NIXOS_HOST"
@ -55,31 +56,20 @@ Rebuild_nixos() {
[ -n "$BUILD_HOST" ] && CMD+=("--build-host" "$BUILD_HOST") [ -n "$BUILD_HOST" ] && CMD+=("--build-host" "$BUILD_HOST")
if [ "$NIXOS_HOST" != "$(hostname)" ] && [ -z "$TARGET_HOST" ]; then if [ "$NIXOS_HOST" != "$(hostname)" ] && [ -z "$TARGET_HOST" ]; then
TARGET_HOST="$NIXOS_HOST" TARGET_HOST="$NIXOS_HOST"
_status "Using '$TARGET_HOST' as target host." echo "Using '$TARGET_HOST' as target host."
fi fi
[ -n "$TARGET_HOST" ] && CMD+=("--target-host" "$TARGET_HOST") [ -n "$TARGET_HOST" ] && CMD+=("--target-host" "$TARGET_HOST")
# Build config first so we can diff it # Rebuild NixOS configuration
local BUILD_CMD=("nixos-rebuild" "build" "--flake" "$FLAKE") if [ "$ROLLBACK" = 0 ]; then
[ "$SHOW_TRACE" = 1 ] && BUILD_CMD+=("--show-trace") echo "Rebuilding NixOS configuration '$FLAKE'..."
[ -n "$BUILD_HOST" ] && BUILD_CMD+=("--build-host" "$BUILD_HOST")
if [ "$ROLLBACK" = 0 ]; then
_status "Building NixOS configuration '$FLAKE'..."
_status "Executing command: ${BUILD_CMD[*]}"
"${BUILD_CMD[@]}" |&nom || error "NixOS build failed"
_status "Package diff:"
dix /run/current-system result
rm result
else else
_status "Rolling back to last NixOS generation..." echo "Rolling back to last NixOS generation..."
fi fi
_status "Switching to new NixOS configuration" echo "Executing command: ${CMD[*]}"
sudo -v "${CMD[@]}" || error "NixOS rebuild failed"
_status "Executing command: ${CMD[*]}" echo "NixOS rebuild completed successfully."
"${CMD[@]}" |& nom || error "NixOS rebuild failed"
success "NixOS rebuild completed successfully."
} }
# Function to rebuild Home Manager configuration # Function to rebuild Home Manager configuration
@ -101,29 +91,21 @@ Rebuild_home() {
[ "$SHOW_TRACE" = 1 ] && CMD+=("--show-trace") [ "$SHOW_TRACE" = 1 ] && CMD+=("--show-trace")
fi fi
# Build config first so we can diff it # Rebuild Home Manager configuration
if [ "$ROLLBACK" = 0 ]; then if [ "$ROLLBACK" = 0 ]; then
local BUILD_CMD=("home-manager" "build" "--flake" "$FLAKE") echo "Rebuilding Home Manager configuration '$FLAKE'..."
[ "$SHOW_TRACE" = 1 ] && BUILD_CMD+=("--show-trace")
_status "Building Home Manager configuration '$FLAKE'..."
_status "Executing command: ${BUILD_CMD[*]}"
"${BUILD_CMD[@]}" |& nom || error "Home Manager build failed"
_status "Package diff:"
dix /run/current-system result
rm result
else else
_status "Rolling back to last Home Manager generation..." echo "Rolling back to last Home Manager generation..."
fi fi
_status "Switching to new Home Manager configuration" echo "Executing command: ${CMD[*]}"
_status "Executing command: ${CMD[*]}" "${CMD[@]}" || error "Home Manager rebuild failed"
"${CMD[@]}" |& nom || error "Home Manager rebuild failed" echo "Home Manager rebuild completed successfully."
success "Home Manager rebuild completed successfully."
} }
# Function to update flake repositories # Function to Update flake repositories
Update() { Update() {
_status "Updating flake inputs..." echo "Updating flake inputs..."
# Construct update command as an array # Construct update command as an array
local CMD=("nix" "flake" "update" "--flake" "$FLAKE_PATH") local CMD=("nix" "flake" "update" "--flake" "$FLAKE_PATH")
@ -135,18 +117,17 @@ Update() {
done done
fi fi
_status "Executing command: ${CMD[*]}" echo "Executing command: ${CMD[*]}"
"${CMD[@]}" || error "Failed to update flake repositories" "${CMD[@]}" || error "Failed to update flake repositories"
success "Flake repositories updated successfully." echo "Flake repositories updated successfully."
} }
# Parse command-line options # Parse command-line options
if [[ -z "${1:-}" ]]; then if [[ -z "${1:-}" ]]; then
echo -e "\033[0;31mError: No command specified. Printing help page.\033[0m" >&2 echo "Error: No command specified. Printing help page."
Help Help
exit 1 exit 1
fi fi
COMMAND=$1 COMMAND=$1
shift shift
@ -217,7 +198,9 @@ while [ $# -gt 0 ]; do
fi fi
;; ;;
*) *)
error "Unknown option '$1'" echo "Error: Unknown option '$1'"
Help
exit 1
;; ;;
esac esac
done done
@ -244,10 +227,10 @@ fi
[ "$UPDATE" = 1 ] && Update [ "$UPDATE" = 1 ] && Update
case "$COMMAND" in case "$COMMAND" in
nixos|os) nixos)
Rebuild_nixos Rebuild_nixos
;; ;;
home|hm) home)
Rebuild_home Rebuild_home
;; ;;
all) all)
@ -255,6 +238,9 @@ case "$COMMAND" in
Rebuild_home Rebuild_home
;; ;;
*) *)
error "Unknown command '$COMMAND'" echo "Error: Unknown command '$COMMAND'"
echo "Printing help page:"
Help
exit 1
;; ;;
esac esac

View file

@ -32,8 +32,6 @@ in
}; };
}; };
nix.settings.warn-dirty = mkDefault false;
# fallback quickly if substituters are not available. # fallback quickly if substituters are not available.
nix.settings.connect-timeout = mkDefault 5; nix.settings.connect-timeout = mkDefault 5;
nix.settings.fallback = true; nix.settings.fallback = true;