Skip to content

Commit

Permalink
hardware config: fix git add logic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
picnoir authored and picnoir committed Nov 15, 2024
1 parent 51d347d commit bae44b6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ parseArgs() {
abort "Unknown hardware config backend: $2"
;;
esac
hardwareConfigPath=$3
hardwareConfigPath="$(realpath "$3")"
shift
shift
;;
Expand Down Expand Up @@ -455,9 +455,11 @@ 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
if git rev-parse --is-inside-work-tree >/dev/null; then
pushd "$(dirname "$hardwareConfigPath")"
git add --intent-to-add --force -- "$hardwareConfigPath"
popd
fi
fi
}

Expand Down

0 comments on commit bae44b6

Please sign in to comment.