feat: add rust template

This commit is contained in:
Moritz Böhme 2024-01-20 13:08:31 +01:00
parent 8d5300682c
commit c37a55d570
Signed by: moritz
GPG key ID: 970C6E89EB0547A9
5 changed files with 82 additions and 0 deletions

View file

@ -204,8 +204,13 @@
templates = {
python = {
description = "Simple poetry shell.nix";
path = ./templates/python;
};
rust = {
description = "Crane + Fenix flake with mold for faster local builds.";
path = ./templates/rust;
};
};
};
};

View file

@ -0,0 +1,2 @@
[target.x86_64-unknown-linux-gnu]
linker = "clang"

1
templates/rust/.envrc Normal file
View file

@ -0,0 +1 @@
use flake

24
templates/rust/.gitignore vendored Normal file
View file

@ -0,0 +1,24 @@
# Created by https://www.toptal.com/developers/gitignore/api/rust,direnv
# Edit at https://www.toptal.com/developers/gitignore?templates=rust,direnv
### direnv ###
.direnv
.envrc
### Rust ###
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
# Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# End of https://www.toptal.com/developers/gitignore/api/rust,direnv

50
templates/rust/flake.nix Normal file
View file

@ -0,0 +1,50 @@
{
inputs = {
crane = {
url = "github:ipetkov/crane";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/nixos-unstable";
};
outputs = { self, crane, fenix, flake-utils, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = (import nixpkgs) {
inherit system;
};
toolchain = fenix.packages.${system}.stable;
craneLib = crane.lib.${system}.overrideToolchain toolchain.toolchain;
in
{
packages.default =
let
inherit (pkgs.lib) fileset;
in
craneLib.buildPackage {
src = fileset.toSource {
root = ./.;
fileset = fileset.intersection
(fileset.difference ./.
(fileset.unions [ ./.cargo ./flake.nix ./flake.lock ./.envrc ]))
(fileset.gitTracked ./.);
};
};
devShell = pkgs.mkShell.override
{
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.clangStdenv;
}
{
nativeBuildInputs = with toolchain; [ rustc cargo rust-analyzer clippy ];
};
});
}