diff --git a/src/nixos-anywhere.sh b/src/nixos-anywhere.sh index 644ab69a..bc56a19e 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,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 }