From 83714e3b99cebcf186bf6bd48e0644bab55b3c26 Mon Sep 17 00:00:00 2001 From: Picnoir Date: Tue, 12 Nov 2024 14:14:45 +0100 Subject: [PATCH] hardware config: fix git add logic Fixing the git add hardware config logic in case the user provides a relative path. We're doing two things: 1. Failing loudly if the git add command fails. At that point, we already know git is in $PATH. If the git add fails, the evaluation will likely fail in a flake setting. Better fail early with a helpful git error message. 2. We're resolving the hardware config path in the CLI parsing layer to make sure this path has the meaning the user intented it to have. --- src/nixos-anywhere.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/nixos-anywhere.sh b/src/nixos-anywhere.sh index 644ab69a..a90ef1f5 100755 --- a/src/nixos-anywhere.sh +++ b/src/nixos-anywhere.sh @@ -176,7 +176,7 @@ parseArgs() { abort "Unknown hardware config backend: $2" ;; esac - hardwareConfigPath=$3 + hardwareConfigPath=$(realpath $3) shift shift ;; @@ -455,9 +455,7 @@ generateHardwareConfig() { # to make sure nix knows about the new file if command -v git >/dev/null; then - pushd "$(dirname "$hardwareConfigPath")" - git add --intent-to-add --force -- "$hardwareConfigPath" >/dev/null 2>&1 || true - popd + git add --intent-to-add --force -- "$hardwareConfigPath" fi }