chore: initialise repository and cargo project

This commit is contained in:
Muhammad Nauman Raza 2023-11-26 21:32:11 +00:00
commit 08c4cbcbe8
Signed by: devraza
GPG key ID: 91EAD6081011574B
8 changed files with 4269 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
target/
result
.direnv/

4040
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

21
Cargo.toml Normal file
View file

@ -0,0 +1,21 @@
[package]
name = "aspiration"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# Enable a small amount of optimization in debug mode
[profile.dev]
opt-level = 1
# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
[dependencies]
bevy = { version = "0.12.0", features = [ "wayland", "dynamic_linking" ] }

35
README.md Normal file
View file

@ -0,0 +1,35 @@
<div align=center>
# ❄️ nix-template-rust-nightly 🦀
[![NixOS](https://img.shields.io/badge/Made_for-Rust-orange.svg?logo=rust&style=for-the-badge)](https://www.rust-lang.org/) [![NixOS](https://img.shields.io/badge/Flakes-Nix-informational.svg?logo=nixos&style=for-the-badge)](https://nixos.org) ![License](https://img.shields.io/github/license/mordragt/nix-templates?style=for-the-badge)
Minimal **Rust** development template for **Nix**
</div>
## About
This is a minimal template for Rust development on the nightly channel.
## Initialization
See the parent README for further instructions, but you can initialize this template
with the following command in your current directory.
```bash
nix flake init -t github:MordragT/nix-templates#rust-nightly
```
## Usage
- `nix develop`: opens up a `bash` shell with the bare minimum Rust toolset (`cargo` & `rustc`) by default
- `nix build` : builds the Rust project. Outputs the binary to `./result/bin/<name>`
- `nix run`: runs the Rust program.
## Reference
1. [wiki/Flakes](https://nixos.wiki/wiki/Flakes)
2. [Fenix](https://github.com/nix-community/fenix) - used for managing Rust toolchains (read the `makeRustPlatform` example)
3. [rust-section of language frameworks](https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md#cargo-features-cargo-features) - optional (use it for extending the template)

98
flake.lock Normal file
View file

@ -0,0 +1,98 @@
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1697178193,
"narHash": "sha256-LBDLUWlwSDPMA1Ui9wC9YcQEnJL0UP627RoUmtz4TTo=",
"owner": "nix-community",
"repo": "fenix",
"rev": "ff6c27356cbde594e598e388a32d79ef79cbe1b1",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1697009197,
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"fenix": "fenix",
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1697098808,
"narHash": "sha256-OfatUxSwuzYd17IDy9eNOedwioq0dX6mOuiTghKol3s=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "84e1d273439413ab4ca1718db0b574dffba443ce",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

68
flake.nix Normal file
View file

@ -0,0 +1,68 @@
{
description = "Rust development template using fenix";
inputs = {
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
utils,
fenix,
...
}:
utils.lib.eachDefaultSystem
(
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [fenix.overlays.default];
};
toolchain = pkgs.fenix.complete;
in rec
{
# Executed by `nix build`
packages.default =
(pkgs.makeRustPlatform {
# Use nightly rustc and cargo provided by fenix for building
inherit (toolchain) cargo rustc;
})
.buildRustPackage {
pname = "template";
version = "0.1.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
# For other makeRustPlatform features see:
# https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md#cargo-features-cargo-features
};
# Executed by `nix run`
apps.default = utils.lib.mkApp {drv = packages.default;};
# Used by `nix develop`
devShells.default = pkgs.mkShell {
# Use nightly cargo & rustc provided by fenix. Add for packages for the dev shell here
buildInputs = with pkgs; [
(with toolchain; [
cargo rustc rust-src clippy rustfmt # rust components
])
xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr # To use the x11 feature
libxkbcommon wayland # To use the wayland feature
mold
clang
pkg-config
];
# Specify the rust-src path (many editors rely on this)
RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library";
};
}
);
}

3
src/main.rs Normal file
View file

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