From 112654f4480596d9a22014d0fa6b2065ef4c7ea6 Mon Sep 17 00:00:00 2001 From: cy Date: Sun, 11 May 2025 00:32:41 -0400 Subject: [PATCH] add flake checks and formatter, run some formatters --- flake.nix | 50 ++++++++++++++++++++++++++++++++++++--------- rust-toolchain.toml | 7 +------ src/cli.rs | 2 -- src/lib.rs | 1 - 4 files changed, 41 insertions(+), 19 deletions(-) delete mode 100644 src/cli.rs diff --git a/flake.nix b/flake.nix index 2d1191f..6e1b9d6 100644 --- a/flake.nix +++ b/flake.nix @@ -11,8 +11,15 @@ }; }; - outputs = inputs@{ nixpkgs, flake-utils, crane, ... }: - flake-utils.lib.eachDefaultSystem (system: + outputs = + inputs@{ + nixpkgs, + flake-utils, + crane, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = import nixpkgs { inherit system; @@ -21,13 +28,12 @@ ]; }; toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; - craneLib = (crane.mkLib pkgs).overrideToolchain(_: toolchain); + craneLib = (crane.mkLib pkgs).overrideToolchain (_: toolchain); lib = pkgs.lib; # don't clean cpp files cppFilter = path: _type: builtins.match ".*(cpp|hpp)$" path != null; - cppOrCargo = path: type: - (cppFilter path type) || (craneLib.filterCargoSources path type); + cppOrCargo = path: type: (cppFilter path type) || (craneLib.filterCargoSources path type); src = lib.cleanSourceWith { src = ./.; filter = cppOrCargo; @@ -48,16 +54,38 @@ ]; # for cpp bindings to work NIX_INCLUDE_PATH = "${lib.getDev pkgs.nix}/include"; - # skip integration tests (they need a connection to the nix store) - cargoTestExtraArgs = "--bins"; + # skip integration tests (they need a connection to the nix store) + cargoTestExtraArgs = "--bins"; }; cargoArtifacts = craneLib.buildDepsOnly commonArgs; - nixcp = craneLib.buildPackage (commonArgs // { - inherit cargoArtifacts; - }); + nixcp = craneLib.buildPackage ( + commonArgs + // { + inherit cargoArtifacts; + } + ); in { + checks = { + # clippy with all warnings denied + clippy = craneLib.cargoClippy ( + commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + + # check formatting + cargoFmt = craneLib.cargoFmt { + inherit src; + }; + tomlFmt = craneLib.taploFmt { + src = lib.sources.sourceFilesBySuffices src [ ".toml" ]; + }; + }; + devShells.default = craneLib.devShell { inputsFrom = [ nixcp ]; @@ -71,6 +99,8 @@ ]; }; + formatter = pkgs.nixfmt-rfc-style; + packages.default = nixcp; } ); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index eceaf24..c96aa24 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,9 +1,4 @@ [toolchain] channel = "nightly" profile = "minimal" -components = [ - "rust-src", - "rust-analyzer", - "rustfmt", - "clippy", -] \ No newline at end of file +components = ["rust-src", "rust-analyzer", "rustfmt", "clippy"] diff --git a/src/cli.rs b/src/cli.rs deleted file mode 100644 index 139597f..0000000 --- a/src/cli.rs +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/src/lib.rs b/src/lib.rs index fa4a43d..8b1fc18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,6 @@ use std::path::PathBuf; use clap::{Args, Parser, Subcommand}; mod bindings; -mod cli; pub mod make_nar; pub mod path_info; pub mod push;