feat: add rust template

nixos
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 ];
};
});
}