From 0d0aea2a9745226cd90f1377cd707311e5a73385 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 13 May 2026 23:42:35 +0200 Subject: [PATCH] Create rust template --- flake.nix | 10 +++++++++ rust/.envrc | 1 + rust/flake.nix | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 flake.nix create mode 100644 rust/.envrc create mode 100644 rust/flake.nix 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 + ]; + }; + }); +}