From b49ac1d626532852a376cb1c98f833d31b3b775e Mon Sep 17 00:00:00 2001 From: Simon Rainerson Date: Tue, 13 Feb 2024 10:02:24 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Make=20checks.nixfmt=20work=20fr?= =?UTF-8?q?om=20everywhere?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- CHANGELOG.md | 3 +++ ci/default.nix | 2 ++ ci/nixfmt | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b8f605..6979961 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/ci/default.nix b/ci/default.nix index 4fde08e..881255a 100644 --- a/ci/default.nix +++ b/ci/default.nix @@ -9,6 +9,7 @@ , gnused , python3 , actionlint +, git }: runCommandLocal "check" { @@ -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")\"" diff --git a/ci/nixfmt b/ci/nixfmt index 70490a2..c75f77e 100644 --- a/ci/nixfmt +++ b/ci/nixfmt @@ -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=()