mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2025-12-06 09:07:21 +01:00
feat: add rust template to new structure
This commit is contained in:
parent
ed9e8bc22e
commit
efd667c76a
7 changed files with 86 additions and 46 deletions
1
templates/rust/.envrc
Normal file
1
templates/rust/.envrc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
use flake
|
||||||
7
templates/rust/Cargo.lock
generated
Normal file
7
templates/rust/Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust"
|
||||||
|
version = "0.1.0"
|
||||||
6
templates/rust/Cargo.toml
Normal file
6
templates/rust/Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "rust"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
69
templates/rust/flake.nix
Normal file
69
templates/rust/flake.nix
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
{
|
||||||
|
description = "Nix Flake Template for Rust using Fenix and Naersk";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||||
|
systems.url = "github:nix-systems/default";
|
||||||
|
naersk.url = "github:nix-community/naersk";
|
||||||
|
fenix = {
|
||||||
|
url = "github:nix-community/fenix";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs =
|
||||||
|
{ self
|
||||||
|
, nixpkgs
|
||||||
|
, naersk
|
||||||
|
, fenix
|
||||||
|
, systems
|
||||||
|
, ...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
forEachSystem = nixpkgs.lib.genAttrs (import systems);
|
||||||
|
pkgsFor = forEachSystem (system:
|
||||||
|
|
||||||
|
import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [
|
||||||
|
fenix.overlays.default
|
||||||
|
];
|
||||||
|
});
|
||||||
|
rust-toolchain = forEachSystem (system: pkgsFor.${system}.fenix.stable);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
formatter = forEachSystem (system: pkgsFor.${system}.nixpkgs-fmt);
|
||||||
|
|
||||||
|
devShells = forEachSystem (system: {
|
||||||
|
default = pkgsFor.${system}.mkShell {
|
||||||
|
packages = with rust-toolchain.${system}; [
|
||||||
|
cargo
|
||||||
|
rustc
|
||||||
|
clippy
|
||||||
|
rustfmt
|
||||||
|
rust-analyzer
|
||||||
|
];
|
||||||
|
env = {
|
||||||
|
RUST_BACKTRACE = "full";
|
||||||
|
};
|
||||||
|
RUST_SRC_PATH = "${rust-toolchain.${system}.rust-src}/lib/rustlib/src/rust/library";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
packages = forEachSystem (system: {
|
||||||
|
default =
|
||||||
|
(pkgsFor.${system}.callPackage naersk {
|
||||||
|
inherit (rust-toolchain.${system}) cargo rustc;
|
||||||
|
}).buildPackage {
|
||||||
|
src = ./.;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
apps = forEachSystem (system: {
|
||||||
|
default = {
|
||||||
|
type = "app";
|
||||||
|
program = "${self.packages.${system}.default}/bin/rust";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
3
templates/rust/src/main.rs
Normal file
3
templates/rust/src/main.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
# flake.nix
|
|
||||||
{
|
|
||||||
inputs = {
|
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
||||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
|
||||||
};
|
|
||||||
|
|
||||||
outputs =
|
|
||||||
{ nixpkgs
|
|
||||||
, rust-overlay
|
|
||||||
, ...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
system = "x86_64-linux";
|
|
||||||
pkgs = import nixpkgs {
|
|
||||||
inherit system;
|
|
||||||
overlays = [ rust-overlay.overlays.default ];
|
|
||||||
};
|
|
||||||
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./toolchain.toml;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
devShells.${system}.default = pkgs.mkShell {
|
|
||||||
packages = with pkgs; [
|
|
||||||
cargo
|
|
||||||
clippy
|
|
||||||
rustc
|
|
||||||
rustfmt
|
|
||||||
toolchain
|
|
||||||
rust-analyzer-unwrapped
|
|
||||||
rust-analyzer
|
|
||||||
];
|
|
||||||
env = {
|
|
||||||
RUST_BACKTRACE = "full";
|
|
||||||
};
|
|
||||||
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
|
|
||||||
|
|
||||||
# ...
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
[toolchain]
|
|
||||||
channel = "stable"
|
|
||||||
components = [
|
|
||||||
"rust-src"
|
|
||||||
# ...
|
|
||||||
]
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue