Skip to content

Commit 548b4a9

Browse files
picnoirmergify[bot]
authored andcommitted
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 we're in a git repo and 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.
1 parent 3458298 commit 548b4a9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/nixos-anywhere.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ parseArgs() {
176176
abort "Unknown hardware config backend: $2"
177177
;;
178178
esac
179-
hardwareConfigPath=$3
179+
hardwareConfigPath="$(realpath "$3")"
180180
shift
181181
shift
182182
;;
@@ -456,7 +456,9 @@ generateHardwareConfig() {
456456
# to make sure nix knows about the new file
457457
if command -v git >/dev/null; then
458458
pushd "$(dirname "$hardwareConfigPath")"
459-
git add --intent-to-add --force -- "$hardwareConfigPath" >/dev/null 2>&1 || true
459+
if git rev-parse --is-inside-work-tree >/dev/null; then
460+
git add --intent-to-add --force -- "$hardwareConfigPath"
461+
fi
460462
popd
461463
fi
462464
}

0 commit comments

Comments
 (0)