Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flake: add treefmt-nix #562

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/treefmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Check formatting with treefmt

on:
[push, pull_request]

jobs:
treefmt:
runs-on: ubuntu-latest
steps:
- uses: cachix/install-nix-action@v22
- uses: actions/checkout@v3
- id: files
uses: tj-actions/changed-files@v44
- name: Run treefmt
run: nix fmt
- name: Check diff
run: |
unformatted_touched=()
unformatted_untouched=()
while IFS= read -r unformatted_file; do
matched=
for changed_file in ${{ steps.files.outputs.all }}; do
if [[ "$changed_file" == "$unformatted_file" ]]; then
unformatted_touched+=("$unformatted_file")
matched=1
break
fi
done
if [[ -z "$matched" ]]; then
unformatted_untouched+=("$unformatted_file")
fi
done <<< "$(git diff --name-only)"

if (( ${#unformatted_untouched[@]} )); then
echo "These files are not formatted, but out of scope of this PR:"
printf '%s\n' "${unformatted_untouched[@]}"
fi

if (( ${#unformatted_touched[@]} )); then
echo "These files are created/edited but not formatted:"
printf '%s\n' "${unformatted_touched[@]}"
exit 1
fi
23 changes: 22 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
flake-parts.url = "github:hercules-ci/flake-parts";

flake-root.url = "github:srid/flake-root";

treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { nixpkgs, flake-parts, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } {
outputs = { nixpkgs, flake-parts, treefmt-nix, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
inputs.flake-root.flakeModule
Expand Down Expand Up @@ -45,6 +50,7 @@
'';
hardeningDisable = [ "fortify" ];
};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
packages.default = nixd;
Expand Down Expand Up @@ -103,6 +109,7 @@
(import ./nixd/docs/editors/vscodium.nix { inherit pkgs; })
];
};
formatter = treefmtEval.config.build.wrapper;
};
systems = nixpkgs.lib.systems.flakeExposed;
};
Expand Down
10 changes: 10 additions & 0 deletions treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ ... }:

{
projectRootFile = "flake.nix";
programs = {
clang-format.enable = true;
nixpkgs-fmt.enable = true;
black.enable = true;
};
}
Loading