commit 3918445f529ec4f5dc4061e993376631e58bd0c3 Author: L-Nafaryus Date: Mon Mar 4 15:01:40 2024 +0500 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ea0ee8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +result* diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b7026a0 --- /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-example" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..d461ec5 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "elnafo" +version = "0.1.0" +edition = "2021" + +[workspace] +members = ["crates/server"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..17df126 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Basic Rust Example + +* Creating/updating `Cargo.lock` +```shell +touch Cargo.lock +nix develop +cargo check +``` diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml new file mode 100644 index 0000000..6c9d648 --- /dev/null +++ b/crates/server/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "server" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "elnafo" +path = "src/main.rs" + +[dependencies] diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/crates/server/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ea06152 --- /dev/null +++ b/flake.lock @@ -0,0 +1,70 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709485267, + "narHash": "sha256-bunOdYTK9YNiy+u0D6YN8q40oAeHoQ+9EgoatF3InJ8=", + "owner": "ipetkov", + "repo": "crane", + "rev": "e4a71521a8eafc07524c55326ecc4ea942b06e25", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": [] + }, + "locked": { + "lastModified": 1709446916, + "narHash": "sha256-MX3eR3ao971besQvKt9aKu4tN8tZht7Do3G/eNylNY8=", + "owner": "nix-community", + "repo": "fenix", + "rev": "4b07da0f91ea99f263f47165a11a48678c9e0dc3", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1709386671, + "narHash": "sha256-VPqfBnIJ+cfa78pd4Y5Cr6sOWVW8GYHRVucxJGmRf8Q=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fa9a51752f1b5de583ad5213eb621be071806663", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "fenix": "fenix", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d91faa6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,65 @@ +{ + description = "Basic rust template"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.rust-analyzer-src.follows = ""; + }; + }; + + outputs = inputs @ { self, nixpkgs, crane, fenix, ... }: + let + forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" ]; + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); + in { + packages = forAllSystems (system: { + elnafo = let + pkgs = nixpkgsFor.${system}; + craneLib = crane.lib.${system}; + in craneLib.buildPackage { + src = craneLib.cleanCargoSource (craneLib.path ./.); + strictDeps = true; + + buildInputs = []; + }; + + default = self.packages.${system}.elnafo; + }); + + checks = forAllSystems (system: { + inherit (self.packages.${system}.elnafo); + + elnafo-fmt = let craneLib = crane.lib.${system}; in craneLib.cargoFmt { + src = craneLib.cleanCargoSource (craneLib.path ./.); + }; + }); + + apps = forAllSystems (system: { + default = { + type = "app"; + program = "${self.packages.${system}.elnafo}/bin/elnafo"; + }; + }); + + devShells = forAllSystems (system: { + default = let pkgs = nixpkgsFor.${system}; in pkgs.mkShell { + nativeBuildInputs = [ + fenix.packages.${system}.complete.toolchain + ]; + }; + elnafo = crane.lib.${system}.devShell { + checks = self.checks.${system}; + + packages = []; + }; + }); + }; + +}