Add rust workspace template

This commit is contained in:
Patrick Auernig 2024-04-24 16:53:15 +02:00
commit f64c01ab6f
10 changed files with 117 additions and 0 deletions

12
flake.nix Normal file
View File

@ -0,0 +1,12 @@
{
description = "Various project templates";
outputs = { nixpkgs, ... }: {
templates = {
rust-workspace = {
path = ./templates/rust/workspace;
description = "Cargo based rust project using a virtual workspace";
};
};
};
}

View File

@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

View File

@ -0,0 +1 @@
use flake

2
templates/rust/workspace/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
.envrc

View File

@ -0,0 +1,15 @@
[workspace]
resolver = "2"
members = [
"./crates/mylib",
]
[workspace.package]
edition = "2021"
version = "0.1.0"
# license-file = "LICENSE"
# authors = []
[workspace.dependencies]

View File

@ -0,0 +1,14 @@
[package]
name = "mylib"
version.workspace = true
edition.workspace = true
# license.workspace = true
# authors.workspace = true
publish = false
[features]
default = []
[dependencies]

View File

@ -0,0 +1,38 @@
{
description = "@project_description@";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { nixpkgs, rust-overlay, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rustNightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal.override {
extensions = [ "rustfmt" ];
targets = [ "x86_64-unknown-linux-gnu" ];
});
buildTools = with pkgs; [
rustToolchain
rustNightlyToolchain
pkg-config
];
devShell = pkgs.mkShell {
name = "@project_name@";
buildInputs = buildTools;
};
in {
devShells.${system}.default = devShell;
};
}

View File

@ -0,0 +1,5 @@
[toolchain]
channel = "stable"
components = ["clippy", "rust-analyzer", "rust-src"]
targets = ["x86_64-unknown-linux-gnu"]
profile = "minimal" # includes rustc, cargo, and rust-std

View File

@ -0,0 +1,18 @@
edition = "2021"
# Just enforce it here as well instead of relying on editorconfig alone
hard_tabs = false
tab_spaces = 4
newline_style = "Unix"
imports_granularity = "Module"
group_imports = "StdExternalCrate"
force_multiline_blocks = false
fn_single_line = false
comment_width = 100
wrap_comments = true
hex_literal_case = "Upper"
blank_lines_upper_bound = 2
overflow_delimited_expr = true
reorder_impl_items = true