new: templates: basic rust example

This commit is contained in:
L-Nafaryus 2023-12-15 16:08:32 +05:00
parent 831e14600f
commit 346ccb57d5
No known key found for this signature in database
GPG Key ID: C76D8DCD2727DBB7
8 changed files with 84 additions and 1 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
templates/*/result*
templates/*/flake.lock

View File

@ -18,5 +18,9 @@
nixosModules = {
bonfire = import ./nixosModules/bonfire.nix;
};
templates = {
rust = { path = ./templates/rust; description = "Basic Rust template"; };
};
};
}

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

@ -0,0 +1,2 @@
/target
result*

7
templates/rust/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "rust-example"
version = "0.1.0"

View File

@ -0,0 +1,6 @@
[package]
name = "rust-example"
version = "0.1.0"
edition = "2021"
[dependencies]

8
templates/rust/README.md Normal file
View File

@ -0,0 +1,8 @@
# Basic Rust Example
* Creating/updating `Cargo.lock`
```shell
touch Cargo.lock
nix develop
cargo check
```

52
templates/rust/flake.nix Normal file
View File

@ -0,0 +1,52 @@
{
description = "Basic rust template";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane = { url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; };
};
outputs = inputs @ { self, nixpkgs, crane, ... }:
let
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" ];
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in {
packages = forAllSystems (system: {
my-crate = let
pkgs = nixpkgsFor.${system};
craneLib = crane.lib.${system};
in craneLib.buildPackage {
src = craneLib.cleanCargoSource (craneLib.path ./.);
strictDeps = true;
buildInputs = [];
};
default = self.packages.${system}.my-crate;
});
checks = forAllSystems (system: {
inherit (self.packages.${system}.my-crate);
my-crate-fmt = let craneLib = crane.lib.${system}; in craneLib.cargoFmt {
src = craneLib.cleanCargoSource (craneLib.path ./.);
};
});
apps = forAllSystems (system: {
default = {
type = "app";
program = "${self.packages.${system}.my-crate}/bin/rust-example";
};
});
devShells = forAllSystems (system: {
default = crane.lib.${system}.devShell {
checks = self.checks.${system};
packages = [];
};
});
};
}

View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, nix!");
}