Skip to content

Commit

Permalink
feat: add rust template to new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Swarsel committed Dec 31, 2024
1 parent ed9e8bc commit efd667c
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 46 deletions.
1 change: 1 addition & 0 deletions templates/rust/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
7 changes: 7 additions & 0 deletions templates/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions templates/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "rust"
version = "0.1.0"
edition = "2021"

[dependencies]
69 changes: 69 additions & 0 deletions templates/rust/flake.nix
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions templates/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
40 changes: 0 additions & 40 deletions templates/rust_flake.nix

This file was deleted.

6 changes: 0 additions & 6 deletions templates/toolchain.toml

This file was deleted.

0 comments on commit efd667c

Please sign in to comment.