From 71e4268600147a3f1ba1d9f9817ea369ee7493c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Tue, 17 Sep 2024 12:14:30 +0200 Subject: [PATCH] nix: pure Rust check/fmt/clippy/test (#2525) Runs the tests in a Nix build sandbox. --- .github/workflows/nix_tests.yaml | 2 +- flake.nix | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nix_tests.yaml b/.github/workflows/nix_tests.yaml index f2209f8a..06768a7b 100644 --- a/.github/workflows/nix_tests.yaml +++ b/.github/workflows/nix_tests.yaml @@ -38,4 +38,4 @@ jobs: env: HF_TOKEN: ${{ secrets.HF_TOKEN }} - name: Rust tests. - run: nix develop .#test --command cargo test + run: nix build .#checks.$(nix eval --impure --raw --expr 'builtins.currentSystem').rust -L diff --git a/flake.nix b/flake.nix index c6adf0a6..3d349ff2 100644 --- a/flake.nix +++ b/flake.nix @@ -69,7 +69,29 @@ server = pkgs.python3.pkgs.callPackage ./nix/server.nix { inherit nix-filter; }; in { + checks = { + rust = with pkgs; rustPlatform.buildRustPackage { + name = "rust-checks"; + src = ./.; + cargoLock = { + lockFile = ./Cargo.lock; + }; + buildInputs = [ openssl.dev ]; + nativeBuildInputs = [ clippy pkg-config protobuf python3 rustfmt ]; + buildPhase = '' + cargo check + ''; + checkPhase = '' + cargo fmt -- --check + cargo test -j $NIX_BUILD_CORES + cargo clippy + ''; + installPhase = "touch $out"; + } ; + }; + formatter = pkgs.nixfmt-rfc-style; + devShells = with pkgs; rec { default = pure;