From 167954eaa70f60d2bd991ffbd6f45c52a03b46e9 Mon Sep 17 00:00:00 2001 From: Samuka007 Date: Sun, 23 Feb 2025 19:36:03 +0800 Subject: [PATCH] nix enable develop environment --- .envrc | 1 + .gitignore | 3 +- .vscode/extensions.json | 7 +++ Cargo.lock | 12 +++--- Cargo.toml | 4 +- app/Cargo.toml | 2 +- default.nix | 7 +++ flake.lock | 96 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 51 ++++++++++++++++++++++ service/Cargo.toml | 2 +- shell.nix | 7 +++ 11 files changed, 181 insertions(+), 11 deletions(-) create mode 100644 .envrc create mode 100644 .vscode/extensions.json create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index c41cc9e..a7d2ddd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/target \ No newline at end of file +/target +.direnv/* \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..487097c --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "pinage404.nix-extension-pack", + "rust-lang.rust-analyzer", + "tamasfe.even-better-toml" + ] +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index dde0ccc..9cc9b29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1312,9 +1312,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.13.4" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c0fef6c4230e4ccf618a35c59d7ede15dea37de8427500f50aff708806e42ec" +checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5" dependencies = [ "bytes", "prost-derive", @@ -1342,9 +1342,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.13.4" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3" +checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d" dependencies = [ "anyhow", "itertools", @@ -1355,9 +1355,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.13.4" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2f1e56baa61e93533aebc21af4d2134b70f66275e0fcdf3cbe43d77ff7e8fc" +checksum = "52c2c1bf36ddb1a1c396b3601a3cec27c2462e45f07c386894ec3ccf5332bd16" dependencies = [ "prost", ] diff --git a/Cargo.toml b/Cargo.toml index 708a76f..c19cfab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] -members = [ "app","service"] - +members = ["app", "service"] +resolver = "3" # API 模块:基于 Actix Web 提供 RESTful 接口,调用 service 模块的功能。 # 测试:编写单元测试和集成测试,确保服务的可靠性。 diff --git a/app/Cargo.toml b/app/Cargo.toml index 2b173a7..f8246a5 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "app" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] actix-web = "4.0" diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..39bacff --- /dev/null +++ b/default.nix @@ -0,0 +1,7 @@ +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..046b997 --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1739866667, + "narHash": "sha256-EO1ygNKZlsAC9avfcwHkKGMsmipUk1Uc0TbrEZpkn64=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "73cf49b8ad837ade2de76f87eb53fc85ed5d4680", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1736320768, + "narHash": "sha256-nIYdTAiKIGnFNugbomgBJR+Xv5F1ZQU+HfaBqJKroC0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4bc9c909d9ac828a039f288cf872d16d38185db8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1740104932, + "narHash": "sha256-FaN+HBAhOW1wAjxPI/Ko1DX0ax4ucHCZoMJ0dGMxm8o=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "c932b3873a5d56126bc1f1416fb8a58315f86c17", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bf8ef27 --- /dev/null +++ b/flake.nix @@ -0,0 +1,51 @@ +{ + description = "FaaS Rust Project"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + rustChannel = pkgs.rust-bin.nightly.latest; + in + with pkgs; + { + devShells.default = mkShell { + buildInputs = [ + openssl + pkg-config + protobuf + containerd + runc + (rustChannel.default.override { + extensions = [ "rust-src" ]; + }) + ]; + }; + defaultPackage = stdenv.mkDerivation { + name = "faas-rs-${rustChannel._version}"; + src = ./.; # 当前项目目录作为源码 + buildInputs = [ + openssl + pkg-config + protobuf + rustChannel.rustc # Rust 编译器 + rustChannel.cargo # Cargo 工具 + ]; + buildPhase = '' + cargo build --release + ''; + installPhase = '' + mkdir -p $out/bin + cp target/release/* $out/bin + ''; + }; + } + ); +} diff --git a/service/Cargo.toml b/service/Cargo.toml index 481b9a4..aa78ebc 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "service" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] containerd-client = "0.6" diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..77db547 --- /dev/null +++ b/shell.nix @@ -0,0 +1,7 @@ +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).shellNix