diff --git a/leptos/flake.nix b/leptos/flake.nix index eb9967a..1a026c1 100644 --- a/leptos/flake.nix +++ b/leptos/flake.nix @@ -4,6 +4,19 @@ nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; rust-overlay.url = "github:oxalica/rust-overlay"; systems.url = "github:nix-systems/x86_64-linux"; + my-drvs.url = "github:huuff/nix-derivations"; + treefmt = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nix-checks = { + url = "github:huuff/nix-checks"; + inputs.my-derivations.follows = "my-drvs"; + }; + pre-commit = { + url = "github:cachix/git-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; utils = { url = "github:numtide/flake-utils"; inputs.systems.follows = "systems"; @@ -16,59 +29,64 @@ nixpkgs, utils, rust-overlay, + my-drvs, + treefmt, + pre-commit, + nix-checks, }: utils.lib.eachDefaultSystem ( system: let overlays = [ (import rust-overlay) - (_: _: { - leptosfmt = self.rustPlatform.buildRustPackage rec { - pname = "leptosfmt"; - version = "0.1.30"; - - src = self.fetchCrate { - inherit version; - crateName = pname; - hash = "sha256-BSWU4KjEfbs8iDkCq+n2D34WS9kqKCVePKnghgQQb/0="; - }; - - cargoHash = "sha256-ZhzcrjVLdR7V6ylmZrQJAFFOL6hSuiORA3iNQdSXEzA="; - - meta = { - description = "A formatter for the leptos view! macro"; - mainProgram = "leptosfmt"; - homepage = "https://github.com/bram209/leptosfmt"; - changelog = "https://github.com/bram209/leptosfmt/blob/${version}/CHANGELOG.md"; - license = with self.lib.licenses; [ - asl20 - mit - ]; - }; - }; - }) ]; pkgs = import nixpkgs { inherit system overlays; }; + rustPkgs = pkgs.rust-bin.stable.latest.default.override { + targets = [ + "x86_64-unknown-linux-musl" + "wasm32-unknown-unknown" + ]; + }; + myPkgs = my-drvs.packages.${system}; + treefmt-build = + (treefmt.lib.evalModule pkgs (import ./treefmt.nix { inherit (myPkgs) leptosfmt; })).config.build; + pre-commit-check = pre-commit.lib.${system}.run { + src = ./.; + hooks = import ./pre-commit.nix { + inherit pkgs rustPkgs; + treefmt = treefmt-build.wrapper; + }; + }; + inherit (nix-checks.lib.${system}) checks; in { - devShell = + checks = { + formatting = treefmt-build.check self; + statix = checks.statis ./.; + deadnix = checks.deadnix ./.; + flake-checker = checks.flake-checker ./.; + clippy = checks.clippy ./.; + }; + + devShell.default = with pkgs; mkShell { + inherit (pre-commit-check) shellHook; buildInputs = [ - (rust-bin.stable.latest.default.override { - targets = [ - "x86_64-unknown-linux-musl" - "wasm32-unknown-unknown" - ]; - }) + # nix + nil + nixfmt-rfc-style + + rustPkgs rust-analyzer cargo-leptos + cargo-expand # expand macros cargo-generate # required for cargo-leptos dart-sass binaryen # required for release compilation - leptosfmt - stylance-cli + my-drvs.leptosfmt + stylance-cli # bundle sass ]; }; } diff --git a/leptos/pre-commit.nix b/leptos/pre-commit.nix new file mode 100644 index 0000000..0e505cc --- /dev/null +++ b/leptos/pre-commit.nix @@ -0,0 +1,46 @@ +{ + pkgs, + treefmt, + rustPkgs, +}: + +{ + check-merge-conflicts.enable = true; + check-added-large-files.enable = true; + commitizen.enable = true; + + gitleaks = { + name = "gitleaks"; + enable = true; + entry = "${pkgs.gitleaks}/bin/gitleaks detect"; + stages = [ "pre-commit" ]; + }; + + treefmt = { + enable = true; + packageOverrides.treefmt = treefmt; + }; + + statix.enable = true; + deadnix.enable = true; + nil.enable = true; + flake-checker.enable = true; + + actionlint.enable = true; + + markdownlint.enable = true; + typos.enable = true; + + clippy = { + enable = true; + # override from rust-overlay, which is more up-to-date + packageOverrides = { + clippy = rustPkgs; + cargo = rustPkgs; + }; + settings = { + allFeatures = true; + }; + }; + +} diff --git a/leptos/treefmt.nix b/leptos/treefmt.nix new file mode 100644 index 0000000..a7b9ed0 --- /dev/null +++ b/leptos/treefmt.nix @@ -0,0 +1,17 @@ +{ leptosfmt }: +_: { + projectRootFile = "flake.nix"; + + programs = { + nixfmt.enable = true; + rustfmt.enable = true; + taplo.enable = true; + }; + + settings.formatter = { + leptosfmt = { + command = "${leptosfmt}/bin/leptosfmt"; + includes = [ "*.rs" ]; + }; + }; +} diff --git a/rust/flake.nix b/rust/flake.nix index 060392c..a90d87c 100644 --- a/rust/flake.nix +++ b/rust/flake.nix @@ -57,7 +57,7 @@ statix = checks.statix ./.; deadnix = checks.deadnix ./.; flake-checker = checks.flake-checker ./.; - checks = checks.clippy ./.; + clippy = checks.clippy ./.; }; # for nix fmt