feat: test-configuration script get real errors
This commit is contained in:
@@ -19,9 +19,9 @@ fi
|
||||
|
||||
HOSTNAME="$1"
|
||||
|
||||
# Check if 'nixos-rebuild' command is available
|
||||
if ! command -v nixos-rebuild > /dev/null; then
|
||||
echo "ERROR: 'nixos-rebuild' command not found. Please ensure it is installed and in your PATH." >&2
|
||||
# Check if 'nix-instantiate' command is available
|
||||
if ! command -v nix-instantiate > /dev/null; then
|
||||
echo "ERROR: 'nix-instantiate' command not found. Please ensure Nix is installed and in your PATH." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -38,27 +38,42 @@ if [ ! -f "$CONFIG_PATH" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for host-specific channel file
|
||||
CHANNEL_PATH="$SCRIPT_DIR/../hosts/$HOSTNAME/channel"
|
||||
CHANNEL_OPT=""
|
||||
|
||||
if [ -f "$CHANNEL_PATH" ]; then
|
||||
CHANNEL_URL=$(cat "$CHANNEL_PATH")
|
||||
# Append /nixexprs.tar.xz to get the actual tarball URL
|
||||
TARBALL_URL="${CHANNEL_URL}/nixexprs.tar.xz"
|
||||
echo "INFO: Using channel '$TARBALL_URL' from '$CHANNEL_PATH'."
|
||||
CHANNEL_OPT="-I nixpkgs=$TARBALL_URL"
|
||||
else
|
||||
echo "WARNING: No channel file found at '$CHANNEL_PATH'. Using system default." >&2
|
||||
fi
|
||||
|
||||
echo "INFO: Attempting dry-build for host '$HOSTNAME' using configuration '$CONFIG_PATH'..."
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
echo "INFO: Verbose mode enabled, --show-trace will be used."
|
||||
fi
|
||||
|
||||
# Execute nixos-rebuild dry-build
|
||||
# Store the output and error streams, and the exit code
|
||||
NIX_OUTPUT_ERR=$(nixos-rebuild dry-build $SHOW_TRACE_OPT -I nixos-config="$CONFIG_PATH" --show-trace 2>&1)
|
||||
# Execute nix-instantiate to evaluate the configuration
|
||||
# nix-instantiate fetches fresh tarballs and catches all evaluation errors
|
||||
# unlike nixos-rebuild which may use cached results
|
||||
NIX_OUTPUT_ERR=$(nix-instantiate $SHOW_TRACE_OPT $CHANNEL_OPT -I nixos-config="$CONFIG_PATH" '<nixpkgs/nixos>' -A system 2>&1)
|
||||
NIX_EXIT_STATUS=$?
|
||||
|
||||
# Check the exit status
|
||||
if [ "$NIX_EXIT_STATUS" -eq 0 ]; then
|
||||
echo "INFO: Dry-build for host '$HOSTNAME' completed successfully."
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
echo "Output from nixos-rebuild:"
|
||||
echo "Output from nix-instantiate:"
|
||||
echo "$NIX_OUTPUT_ERR"
|
||||
fi
|
||||
exit 0
|
||||
else
|
||||
echo "ERROR: Dry-build for host '$HOSTNAME' failed. 'nixos-rebuild' exited with status $NIX_EXIT_STATUS." >&2
|
||||
echo "Output from nixos-rebuild:" >&2
|
||||
echo "ERROR: Dry-build for host '$HOSTNAME' failed. 'nix-instantiate' exited with status $NIX_EXIT_STATUS." >&2
|
||||
echo "Output from nix-instantiate:" >&2
|
||||
echo "$NIX_OUTPUT_ERR" >&2
|
||||
exit "$NIX_EXIT_STATUS"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user