Skip to content

Commit 505cc01

Browse files
committed
feat: implement ruff as flake checks
Had to add `--impure` to the call due to the following error otherwise: ``` error: … while checking flake output 'packages' at /nix/store/5cjz7jyqyfr5vq8b6bjs24vdnvdhy9rb-source/flake.nix:118:7: 117| 118| packages = forEachSystem (system: | ^ 119| let … while checking the derivation 'packages.x86_64-linux.bootstrap-aarch64' at /nix/store/dg3hg3ksr5sl3adskxiwj7357z47ggvr-source/lib/attrsets.nix:977:47: 976| */ 977| nameValuePair = name: value: { inherit name value; }; | ^ 978| (stack trace truncated; use '--show-trace' to show the full, detailed trace) error: 'builtins.storePath' is not allowed in pure evaluation mode ```
1 parent bd677b4 commit 505cc01

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

.github/workflows/lints.yml

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
schedule:
66
- cron: 0 0 * * 1
77
jobs:
8-
lint-nix:
8+
check:
99
runs-on: ubuntu-latest
1010

1111
steps:
@@ -15,21 +15,5 @@ jobs:
1515
- name: Install nix
1616
uses: cachix/install-nix-action@v25
1717

18-
- name: Run nix-formatter-pack-check
19-
run: nix build .#checks.x86_64-linux.nix-formatter-pack-check
20-
21-
lint-py:
22-
runs-on: ubuntu-latest
23-
24-
steps:
25-
- name: Checkout repository
26-
uses: actions/checkout@v4
27-
28-
- name: Install nix
29-
uses: cachix/install-nix-action@v25
30-
31-
- name: Run ruff linter
32-
run: nix run 'nixpkgs#ruff' -- check
33-
34-
- name: Run ruff formatter
35-
run: nix run 'nixpkgs#ruff' -- format --diff
18+
- name: Run flake checks
19+
run: nix flake check --impure -L

checks/ruff-fmt.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{ pkgs, checkRoot }:
2+
pkgs.runCommandLocal "ruff-fmt"
3+
{
4+
src = ./.;
5+
nativeBuildInputs = with pkgs; [ ruff ];
6+
}
7+
''
8+
cd ${checkRoot};
9+
ruff format --no-cache --diff && mkdir $out
10+
''

checks/ruff-lint.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{ pkgs, checkRoot }:
2+
pkgs.runCommandLocal "ruff-lint"
3+
{
4+
src = ./.;
5+
nativeBuildInputs = with pkgs; [ ruff ];
6+
}
7+
''
8+
cd ${checkRoot};
9+
ruff check --no-cache && mkdir $out
10+
''

flake.nix

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,16 @@
6363
};
6464
});
6565

66-
checks = forEachSystem (system: {
67-
nix-formatter-pack-check = nix-formatter-pack.lib.mkCheck formatterPackArgsFor.${system};
68-
});
66+
checks = forEachSystem (system:
67+
let
68+
pkgs = import nixpkgs { inherit system; };
69+
in
70+
{
71+
nix-formatter-pack-check = nix-formatter-pack.lib.mkCheck formatterPackArgsFor.${system};
72+
ruff-lint = import ./checks/ruff-lint.nix { inherit pkgs; checkRoot = ./.; };
73+
ruff-fmt = import ./checks/ruff-fmt.nix { inherit pkgs; checkRoot = ./.; };
74+
}
75+
);
6976

7077
formatter = forEachSystem (system: nix-formatter-pack.lib.mkFormatter formatterPackArgsFor.${system});
7178

0 commit comments

Comments
 (0)