From 83c91eeeab4080d4dccd87607cf887e0133aa625 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 29 Apr 2023 16:58:43 +0530 Subject: init --- .gitignore | 1 + Cargo.lock | 7 +++++++ Cargo.toml | 8 ++++++++ flake.lock | 24 ++++++++++++++++++++++++ flake.nix | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 3 +++ 6 files changed, 94 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b425a03 --- /dev/null +++ b/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-bin" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c97aa53 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rust-bin" +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/flake.lock b/flake.lock new file mode 100644 index 0000000..f231e8c --- /dev/null +++ b/flake.lock @@ -0,0 +1,24 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1677852945, + "narHash": "sha256-liiVJjkBTuBTAkRW3hrI8MbPD2ImYzwUpa7kvteiKhM=", + "path": "/nix/store/cgfz9cycn82cwhvpaskq80bfw0k711gq-source", + "rev": "f5ffd5787786dde3a8bf648c7a1b5f78c4e01abb", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..28b7a60 --- /dev/null +++ b/flake.nix @@ -0,0 +1,51 @@ +{ + description = "build rust binaries"; + + outputs = { self, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = forAllSystems (system: import nixpkgs { + inherit system; + overlays = [ self.overlays.default ]; + }); + in + { + + overlays.default = final: prev: { + rust-bin = + let + packageMeta = (final.lib.importTOML ./Cargo.toml).package; + in + final.rustPlatform.buildRustPackage { + pname = packageMeta.name; + inherit (packageMeta) version; + src = self; + cargoLock.lockFile = ./Cargo.lock; + }; + }; + + packages = forAllSystems (system: { + inherit (nixpkgsFor."${system}") rust-bin; + }); + + defaultPackage = forAllSystems (system: self.packages."${system}".rust-bin); + + devShell = forAllSystems (system: + let + pkgs = nixpkgsFor."${ system}"; + in + pkgs.mkShell { + nativeBuildInputs = [ + pkgs.rustc + pkgs.cargo + pkgs.rustfmt + pkgs.rust-analyzer + pkgs.cargo-watch + ]; + RUST_BACKTRACE = 1; + } + ); + + }; +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} -- cgit v1.2.3