From 9083ff41ab1365d5b979ff31968cc5c29502133f Mon Sep 17 00:00:00 2001 From: Artur Manuel Date: Wed, 14 Aug 2024 23:44:43 +0100 Subject: [PATCH] feat(rust): add rust to the templates --- flake.nix | 4 +++ templates/rust/Cargo.lock | 7 ++++ templates/rust/Cargo.toml | 8 +++++ templates/rust/flake.lock | 61 ++++++++++++++++++++++++++++++++++ templates/rust/flake.nix | 41 +++++++++++++++++++++++ templates/rust/nix/package.nix | 8 +++++ templates/rust/nix/shell.nix | 7 ++++ templates/rust/src/main.rs | 3 ++ 8 files changed, 139 insertions(+) create mode 100644 templates/rust/Cargo.lock create mode 100644 templates/rust/Cargo.toml create mode 100644 templates/rust/flake.lock create mode 100644 templates/rust/flake.nix create mode 100644 templates/rust/nix/package.nix create mode 100644 templates/rust/nix/shell.nix create mode 100644 templates/rust/src/main.rs diff --git a/flake.nix b/flake.nix index e57e9d2..9df03f0 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,10 @@ path = ./templates/go; description = "go flake template"; }; + "rust" = { + path = ./templates/rust; + description = "rust flake template"; + }; }; }; } diff --git a/templates/rust/Cargo.lock b/templates/rust/Cargo.lock new file mode 100644 index 0000000..9c64ef4 --- /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-app" +version = "0.1.0" diff --git a/templates/rust/Cargo.toml b/templates/rust/Cargo.toml new file mode 100644 index 0000000..e5e90c8 --- /dev/null +++ b/templates/rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rust-app" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/templates/rust/flake.lock b/templates/rust/flake.lock new file mode 100644 index 0000000..5c1674b --- /dev/null +++ b/templates/rust/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1723673859, + "narHash": "sha256-FLYl6raDlRSUf6o3DkbCg/KkOUBGHcyNKZ0RlzoSLcA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c55e2908deb848d0e94d8170cb4b0a1e9bc30c8c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1718428119, + "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust": "rust" + } + }, + "rust": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1723602049, + "narHash": "sha256-Z/noCSn9WPkv7O77dWKLcBxe4Ub4bWyNzsL5JhjaQfw=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "ea0bf33a11a26a62c60123c49d96011da396602c", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix new file mode 100644 index 0000000..36958f7 --- /dev/null +++ b/templates/rust/flake.nix @@ -0,0 +1,41 @@ +{ + description = "Rust Developer Environment"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + rust.url = "github:oxalica/rust-overlay"; + }; + outputs = { self, nixpkgs, rust }: let + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + forAllSystems = nixpkgs.lib.genAttrs systems; + in { + packages = forAllSystems (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [ + (import rust) + ]; + }; + inherit system; + in { + rust-app = pkgs.callPackage ./nix/package.nix { }; + default = self.packages.${system}.rust-app; + }); + + devShells = forAllSystems (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [ + (import rust) + ]; + }; + inherit system; + in { + default = pkgs.callPackage ./nix/shell.nix { + inherit (self.packages.${system}) rust-app; + }; + }); + }; +} diff --git a/templates/rust/nix/package.nix b/templates/rust/nix/package.nix new file mode 100644 index 0000000..4cef8f8 --- /dev/null +++ b/templates/rust/nix/package.nix @@ -0,0 +1,8 @@ +{ rustPlatform }: let + pname = "rust-app"; + version = "0.1.0"; +in rustPlatform.buildRustPackage { + inherit pname version; + src = ../.; + cargoLock.lockFile = ../Cargo.lock; +} diff --git a/templates/rust/nix/shell.nix b/templates/rust/nix/shell.nix new file mode 100644 index 0000000..811b574 --- /dev/null +++ b/templates/rust/nix/shell.nix @@ -0,0 +1,7 @@ +{ mkShell, rust-app, rust-bin }: +mkShell { + inputsFrom = [ rust-app ]; + buildInputs = [ + rust-bin.stable.latest.default + ]; +} 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!"); +}