From ba4fe10465e752d701e44bb8c5a8fc670b3845a1 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Fri, 9 May 2025 20:56:58 +0200 Subject: [PATCH 1/2] workflows/editorconfig: drop and move to treefmt We already have treefmt running for nixfmt, so it's easy to just add another formatter to it. This gives a much better UX, because all formatting errors are reported through the same channel. It also saves us one CI job, which takes most of the time to just set up the machine, clone the repo and download Nix - while doing a minimum of actual work. Total execution time for treefmt is ~10% slower: - 38s only nixfmt - 43s nixfmt + editorconfig-checker --- ...{check-nix-format.yml => check-format.yml} | 11 ++-- .github/workflows/editorconfig-v2.yml | 52 ------------------- ci/OWNERS | 2 +- ci/default.nix | 7 +++ 4 files changed, 12 insertions(+), 60 deletions(-) rename .github/workflows/{check-nix-format.yml => check-format.yml} (80%) delete mode 100644 .github/workflows/editorconfig-v2.yml diff --git a/.github/workflows/check-nix-format.yml b/.github/workflows/check-format.yml similarity index 80% rename from .github/workflows/check-nix-format.yml rename to .github/workflows/check-format.yml index 8c35196e4944..ca3da602575b 100644 --- a/.github/workflows/check-nix-format.yml +++ b/.github/workflows/check-format.yml @@ -1,7 +1,4 @@ -# NOTE: Formatting with the RFC-style nixfmt command is not yet stable. -# See https://github.com/NixOS/rfcs/pull/166. - -name: Check that Nix files are formatted +name: Check that files are formatted on: pull_request_target: @@ -14,7 +11,7 @@ jobs: uses: ./.github/workflows/get-merge-commit.yml nixos: - name: nixfmt-check + name: fmt-check runs-on: ubuntu-24.04 needs: get-merge-commit if: needs.get-merge-commit.outputs.mergedSha @@ -27,13 +24,13 @@ jobs: with: extra_nix_config: sandbox = true - - name: Check that Nix files are formatted + - name: Check that files are formatted run: | # Note that it's fine to run this on untrusted code because: # - There's no secrets accessible here # - The build is sandboxed if ! nix-build ci -A fmt.check; then - echo "Some Nix files are not properly formatted" + echo "Some files are not properly formatted" echo "Please format them by going to the Nixpkgs root directory and running one of:" echo " nix-shell --run treefmt" echo " nix develop --command treefmt" diff --git a/.github/workflows/editorconfig-v2.yml b/.github/workflows/editorconfig-v2.yml deleted file mode 100644 index 68d780f2190f..000000000000 --- a/.github/workflows/editorconfig-v2.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: "Checking EditorConfig v2" - -on: - pull_request_target: - -permissions: {} - -jobs: - get-merge-commit: - uses: ./.github/workflows/get-merge-commit.yml - - tests: - name: editorconfig-check - runs-on: ubuntu-24.04 - needs: get-merge-commit - if: "needs.get-merge-commit.outputs.mergedSha && !contains(github.event.pull_request.title, '[skip treewide]')" - steps: - - name: Get list of changed files from PR - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh api \ - repos/${{ github.repository }}/pulls/${{ github.event.number }}/files --paginate \ - | jq '.[] | select(.status != "removed") | .filename' \ - > "$HOME/changed_files" - - - name: print list of changed files - run: | - cat "$HOME/changed_files" - - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - ref: ${{ needs.get-merge-commit.outputs.mergedSha }} - - - name: Get Nixpkgs revision for editorconfig-checker - run: | - # Pin to a commit from nixpkgs-unstable to avoid building from e.g. staging. - # This should not be a URL, because it would allow PRs to run arbitrary code in CI! - rev=$(jq -r .rev ci/pinned-nixpkgs.json) - echo "url=https://github.com/NixOS/nixpkgs/archive/$rev.tar.gz" >> "$GITHUB_ENV" - - - uses: cachix/install-nix-action@526118121621777ccd86f79b04685a9319637641 # v31 - with: - nix_path: nixpkgs=${{ env.url }} - - - name: Checking EditorConfig - run: | - < "$HOME/changed_files" nix-shell -p editorconfig-checker --run 'xargs -r editorconfig-checker -disable-indent-size' - - - if: ${{ failure() }} - run: | - echo "::error :: Hey! It looks like your changes don't follow our editorconfig settings. Read https://editorconfig.org/#download to configure your editor so you never see this error again." diff --git a/ci/OWNERS b/ci/OWNERS index 13b5c0ac4f0a..69a122d537e7 100644 --- a/ci/OWNERS +++ b/ci/OWNERS @@ -16,7 +16,7 @@ # CI /.github/*_TEMPLATE* @SigmaSquadron /.github/workflows @NixOS/Security @Mic92 @zowoq @infinisil @azuwis @wolfgangwalther -/.github/workflows/check-nix-format.yml @infinisil @wolfgangwalther +/.github/workflows/check-format.yml @infinisil @wolfgangwalther /.github/workflows/codeowners-v2.yml @infinisil @wolfgangwalther /.github/workflows/nixpkgs-vet.yml @infinisil @philiptaron @wolfgangwalther /ci @infinisil @philiptaron @NixOS/Security @wolfgangwalther diff --git a/ci/default.nix b/ci/default.nix index 67f59d61bfd4..59fb1b48574c 100644 --- a/ci/default.nix +++ b/ci/default.nix @@ -48,6 +48,13 @@ let # the default formatter for Nix code. # See https://github.com/NixOS/nixfmt programs.nixfmt.enable = true; + + settings.formatter.editorconfig-checker = { + command = "${pkgs.lib.getExe pkgs.editorconfig-checker}"; + options = [ "-disable-indent-size" ]; + includes = [ "*" ]; + priority = 1; + }; }; fs = pkgs.lib.fileset; nixFilesSrc = fs.toSource { From 1cb7a384e022733ba8c1387a9aef9ad382c86394 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Fri, 9 May 2025 21:54:12 +0200 Subject: [PATCH 2/2] workflows/keep-sorted: drop and move to treefmt Same reasoning as the commit before, but keep-sorted has even less overhead than editorconfig-checker. Benchmark has it at 1 second per run. --- .github/workflows/keep-sorted.yml | 41 ------------------------------- ci/default.nix | 2 ++ 2 files changed, 2 insertions(+), 41 deletions(-) delete mode 100644 .github/workflows/keep-sorted.yml diff --git a/.github/workflows/keep-sorted.yml b/.github/workflows/keep-sorted.yml deleted file mode 100644 index ec2237f52bd9..000000000000 --- a/.github/workflows/keep-sorted.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Check that files are sorted - -on: - pull_request_target: - types: [opened, synchronize, reopened] - -permissions: {} - -jobs: - get-merge-commit: - uses: ./.github/workflows/get-merge-commit.yml - - nixos: - name: keep-sorted - runs-on: ubuntu-24.04 - needs: get-merge-commit - if: "needs.get-merge-commit.outputs.mergedSha && !contains(github.event.pull_request.title, '[skip treewide]')" - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - ref: ${{ needs.get-merge-commit.outputs.mergedSha }} - - - name: Get Nixpkgs revision for keep-sorted - run: | - # Pin to a commit from nixpkgs-unstable to avoid e.g. building nixfmt from staging. - # This should not be a URL, because it would allow PRs to run arbitrary code in CI! - rev=$(jq -r .rev ci/pinned-nixpkgs.json) - echo "url=https://github.com/NixOS/nixpkgs/archive/$rev.tar.gz" >> "$GITHUB_ENV" - - - uses: cachix/install-nix-action@526118121621777ccd86f79b04685a9319637641 # v31 - with: - extra_nix_config: sandbox = true - nix_path: nixpkgs=${{ env.url }} - - - name: Install keep-sorted - run: "nix-env -f '' -iAP keep-sorted jq" - - - name: Check that Nix files are sorted - shell: bash - run: | - git ls-files | xargs keep-sorted --mode lint | jq --raw-output '.[] | "Please make sure any new entries in \(.path) are sorted alphabetically."' diff --git a/ci/default.nix b/ci/default.nix index 59fb1b48574c..9d0fff7d119a 100644 --- a/ci/default.nix +++ b/ci/default.nix @@ -44,6 +44,8 @@ let # By default it's info, which is too noisy since we have many unmatched files settings.on-unmatched = "debug"; + programs.keep-sorted.enable = true; + # This uses nixfmt-rfc-style underneath, # the default formatter for Nix code. # See https://github.com/NixOS/nixfmt