commit 0d0aea2a9745226cd90f1377cd707311e5a73385 Author: Alexander Date: Wed May 13 23:42:35 2026 +0200 Create rust template diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..651d0f8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,10 @@ +{ + description = "A collection of flake templates"; + + outputs = { self }: { + rust = { + path = ./rust; + description = "Rust template"; + }; + }; +} diff --git a/rust/.envrc b/rust/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/rust/.envrc @@ -0,0 +1 @@ +use flake diff --git a/rust/flake.nix b/rust/flake.nix new file mode 100644 index 0000000..7135f5f --- /dev/null +++ b/rust/flake.nix @@ -0,0 +1,61 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + utils.url = "github:numtide/flake-utils"; + git-hooks.url = "github:cachix/git-hooks.nix"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { self, nixpkgs, utils, git-hooks, rust-overlay }: + utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + + rustToolchain = pkgs.rust-bin.stable.latest.default.override { + extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ]; + }; + + pre-commit-check = git-hooks.lib.${system}.run { + src = ./.; + hooks = { + rustfmt = { + enable = true; + packageOverrides = { + cargo = rustToolchain; + rustfmt = rustToolchain; + }; + }; + clippy = { + enable = true; + packageOverrides = { + cargo = rustToolchain; + clippy = rustToolchain; + }; + }; + }; + }; + in + { + checks = { + inherit pre-commit-check; + }; + + devShells.default = pkgs.mkShell { + inherit (pre-commit-check) shellHook; + nativeBuildInputs = with pkgs; [ + pre-commit + gitleaks + + rustToolchain + cargo-watch + crates-lsp + pkg-config + ]; + + buildInputs = with pkgs; [ + openssl + ]; + }; + }); +}