Skip to content

Commit

Permalink
🐛 Make checks.nixfmt work from everywhere
Browse files Browse the repository at this point in the history
If $nixFiles were expressed as relative to the root of the project,
nixfmt would fail when ran from a sub directory. Now cd to the root
first which will work for both relative and absolute paths.

Since nix (and thus we) have not committed to using flakes this instead
uses git to find the root of the project.
  • Loading branch information
simonrainerson committed Feb 16, 2024
1 parent 123f886 commit 04f7ff4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- `.#checks.nixfmt` can be run from everywhere when nixFiles are relative to project.

## [10.0.0] - 2024-02-06

### Added
Expand Down
2 changes: 2 additions & 0 deletions ci/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
, gnused
, python3
, actionlint
, git
}:
runCommandLocal "check"
{
Expand All @@ -22,6 +23,7 @@ runCommandLocal "check"
sed = "${gnused}/bin/sed";
pyflakes = "${python3.pkgs.pyflakes}/bin/pyflakes";
actionlint = "${actionlint}/bin/actionlint";
git = "${git}/bin/git";
preamble = ''
if [[ ",''${NEDRYLAND_NO_USE_CHECK_FILES:-}," =~ ",$(basename "$0")," ]]; then
echo "forcing file list off for tool \"$(basename "$0")\""
Expand Down
4 changes: 4 additions & 0 deletions ci/nixfmt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ if [[ $* =~ (^|[[:space:]])+--fix([[:space:]]|$)+ ]]; then
check=""
fi

if root="$(@git@ rev-parse --show-toplevel 2>/dev/null)"; then
cd "$root"
fi

if [ $# -eq 0 ] || [ -z "$check" ]; then
exitCode=0
files=()
Expand Down

0 comments on commit 04f7ff4

Please sign in to comment.