From efd667c76a47b5fe1d57548ce6b359164ae3a54a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Schwarz=C3=A4ugl?= Date: Tue, 31 Dec 2024 17:16:51 +0100 Subject: [PATCH] feat: add rust template to new structure --- templates/rust/.envrc | 1 + templates/rust/Cargo.lock | 7 ++++ templates/rust/Cargo.toml | 6 ++++ templates/rust/flake.nix | 69 ++++++++++++++++++++++++++++++++++++++ templates/rust/src/main.rs | 3 ++ templates/rust_flake.nix | 40 ---------------------- templates/toolchain.toml | 6 ---- 7 files changed, 86 insertions(+), 46 deletions(-) create mode 100644 templates/rust/.envrc create mode 100644 templates/rust/Cargo.lock create mode 100644 templates/rust/Cargo.toml create mode 100644 templates/rust/flake.nix create mode 100644 templates/rust/src/main.rs delete mode 100644 templates/rust_flake.nix delete mode 100644 templates/toolchain.toml diff --git a/templates/rust/.envrc b/templates/rust/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/templates/rust/.envrc @@ -0,0 +1 @@ +use flake diff --git a/templates/rust/Cargo.lock b/templates/rust/Cargo.lock new file mode 100644 index 0000000..b21cc6a --- /dev/null +++ b/templates/rust/Cargo.lock @@ -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" diff --git a/templates/rust/Cargo.toml b/templates/rust/Cargo.toml new file mode 100644 index 0000000..7d75412 --- /dev/null +++ b/templates/rust/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "rust" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix new file mode 100644 index 0000000..97dcb9a --- /dev/null +++ b/templates/rust/flake.nix @@ -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"; + }; + }); + }; +} diff --git a/templates/rust/src/main.rs b/templates/rust/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/templates/rust/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/templates/rust_flake.nix b/templates/rust_flake.nix deleted file mode 100644 index cd93ce7..0000000 --- a/templates/rust_flake.nix +++ /dev/null @@ -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"; - - # ... - }; - }; -} diff --git a/templates/toolchain.toml b/templates/toolchain.toml deleted file mode 100644 index e27fc5d..0000000 --- a/templates/toolchain.toml +++ /dev/null @@ -1,6 +0,0 @@ -[toolchain] -channel = "stable" -components = [ - "rust-src" - # ... -]