Skip to content

Commit

Permalink
Merge pull request #9 from huuff/leptos
Browse files Browse the repository at this point in the history
feat: better-features leptos template (closes #3)
  • Loading branch information
huuff authored Oct 14, 2024
2 parents 53b91cd + 8e8a1af commit 92ee288
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 35 deletions.
86 changes: 52 additions & 34 deletions leptos/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
];
};
}
Expand Down
46 changes: 46 additions & 0 deletions leptos/pre-commit.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};

}
17 changes: 17 additions & 0 deletions leptos/treefmt.nix
Original file line number Diff line number Diff line change
@@ -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" ];
};
};
}
2 changes: 1 addition & 1 deletion rust/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
statix = checks.statix ./.;
deadnix = checks.deadnix ./.;
flake-checker = checks.flake-checker ./.;
checks = checks.clippy ./.;
clippy = checks.clippy ./.;
};

# for nix fmt
Expand Down

0 comments on commit 92ee288

Please sign in to comment.