From 505cc019aef7c217c700b61536adcb22d0f7b4d1 Mon Sep 17 00:00:00 2001 From: Philippe Laflamme Date: Fri, 11 Jul 2025 14:52:52 -0400 Subject: [PATCH 1/2] feat: implement `ruff` as flake checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ``` --- .github/workflows/lints.yml | 22 +++------------------- checks/ruff-fmt.nix | 10 ++++++++++ checks/ruff-lint.nix | 10 ++++++++++ flake.nix | 13 ++++++++++--- 4 files changed, 33 insertions(+), 22 deletions(-) create mode 100644 checks/ruff-fmt.nix create mode 100644 checks/ruff-lint.nix diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index db8db96..dc114e0 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -5,7 +5,7 @@ on: schedule: - cron: 0 0 * * 1 jobs: - lint-nix: + check: runs-on: ubuntu-latest steps: @@ -15,21 +15,5 @@ jobs: - name: Install nix uses: cachix/install-nix-action@v25 - - name: Run nix-formatter-pack-check - run: nix build .#checks.x86_64-linux.nix-formatter-pack-check - - lint-py: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install nix - uses: cachix/install-nix-action@v25 - - - name: Run ruff linter - run: nix run 'nixpkgs#ruff' -- check - - - name: Run ruff formatter - run: nix run 'nixpkgs#ruff' -- format --diff + - name: Run flake checks + run: nix flake check --impure -L diff --git a/checks/ruff-fmt.nix b/checks/ruff-fmt.nix new file mode 100644 index 0000000..941abc3 --- /dev/null +++ b/checks/ruff-fmt.nix @@ -0,0 +1,10 @@ +{ pkgs, checkRoot }: +pkgs.runCommandLocal "ruff-fmt" +{ + src = ./.; + nativeBuildInputs = with pkgs; [ ruff ]; +} + '' + cd ${checkRoot}; + ruff format --no-cache --diff && mkdir $out + '' diff --git a/checks/ruff-lint.nix b/checks/ruff-lint.nix new file mode 100644 index 0000000..c1d9560 --- /dev/null +++ b/checks/ruff-lint.nix @@ -0,0 +1,10 @@ +{ pkgs, checkRoot }: +pkgs.runCommandLocal "ruff-lint" +{ + src = ./.; + nativeBuildInputs = with pkgs; [ ruff ]; +} + '' + cd ${checkRoot}; + ruff check --no-cache && mkdir $out + '' diff --git a/flake.nix b/flake.nix index ad92e98..576d711 100644 --- a/flake.nix +++ b/flake.nix @@ -63,9 +63,16 @@ }; }); - checks = forEachSystem (system: { - nix-formatter-pack-check = nix-formatter-pack.lib.mkCheck formatterPackArgsFor.${system}; - }); + checks = forEachSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + nix-formatter-pack-check = nix-formatter-pack.lib.mkCheck formatterPackArgsFor.${system}; + ruff-lint = import ./checks/ruff-lint.nix { inherit pkgs; checkRoot = ./.; }; + ruff-fmt = import ./checks/ruff-fmt.nix { inherit pkgs; checkRoot = ./.; }; + } + ); formatter = forEachSystem (system: nix-formatter-pack.lib.mkFormatter formatterPackArgsFor.${system}); From 819abe1fabaa29be8795c81b2f6706fe18234fb9 Mon Sep 17 00:00:00 2001 From: Philippe Laflamme Date: Fri, 11 Jul 2025 15:09:32 -0400 Subject: [PATCH 2/2] feat: nix flake update to get more recent `ruff` --- flake.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index 888acae..361cb01 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1709445365, - "narHash": "sha256-DVv6nd9FQBbMWbOmhq0KVqmlc3y3FMSYl49UXmMcO+0=", + "lastModified": 1752256062, + "narHash": "sha256-2s0PrY3vIFusm4UrqPnskY6SgdVolEDAz9wHcCSadcw=", "owner": "nix-community", "repo": "home-manager", - "rev": "4de84265d7ec7634a69ba75028696d74de9a44a7", + "rev": "b8b7e5ec3570eb003d55f4947dd39af15c3ca98d", "type": "github" }, "original": { @@ -31,11 +31,11 @@ "nmt": "nmt" }, "locked": { - "lastModified": 1705252799, - "narHash": "sha256-HgSTREh7VoXjGgNDwKQUYcYo13rPkltW7IitHrTPA5c=", + "lastModified": 1742249870, + "narHash": "sha256-U37ECk3zpfp92D3H0gzfWPyb5sf0RdOdublCq1zjq+w=", "owner": "Gerschtli", "repo": "nix-formatter-pack", - "rev": "2de39dedd79aab14c01b9e2934842051a160ffa5", + "rev": "fe5b4498e3161191bd93fe0683dff347f6f689df", "type": "github" }, "original": { @@ -46,11 +46,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1708172716, - "narHash": "sha256-3M94oln0b61m3dUmLyECCA9hYAHXZEszM4saE3CmQO4=", + "lastModified": 1752259019, + "narHash": "sha256-XHjyWQjmXCaoU36cTPO6QRemYNTgIRyyKiy0pDwk7c4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5d874ac46894c896119bce68e758e9e80bdb28f1", + "rev": "1cf71b641e2358e0f92536b5df0a72a8c05edb05", "type": "github" }, "original": {