nix build available!

This commit is contained in:
Samuka007 2025-02-24 13:55:19 +08:00
parent 167954eaa7
commit d98cfd6289
5 changed files with 100 additions and 61 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
/target
.direnv/*
.direnv/*
result

22
Cargo.lock generated
View File

@ -243,17 +243,6 @@ version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
[[package]]
name = "app"
version = "0.1.0"
dependencies = [
"actix-web",
"serde",
"serde_json",
"service",
"tokio",
]
[[package]]
name = "async-stream"
version = "0.3.6"
@ -589,6 +578,17 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "faas-rs"
version = "0.1.0"
dependencies = [
"actix-web",
"serde",
"serde_json",
"service",
"tokio",
]
[[package]]
name = "fastrand"
version = "2.3.0"

View File

@ -1,5 +1,5 @@
[package]
name = "app"
name = "faas-rs"
version = "0.1.0"
edition = "2024"

36
flake.lock generated
View File

@ -1,5 +1,20 @@
{
"nodes": {
"crane": {
"locked": {
"lastModified": 1739936662,
"narHash": "sha256-x4syUjNUuRblR07nDPeLDP7DpphaBVbUaSoeZkFbGSk=",
"owner": "ipetkov",
"repo": "crane",
"rev": "19de14aaeb869287647d9461cbd389187d8ecdb7",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
@ -34,24 +49,9 @@
"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": {
"crane": "crane",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
@ -59,7 +59,9 @@
},
"rust-overlay": {
"inputs": {
"nixpkgs": "nixpkgs_2"
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1740104932,

View File

@ -3,49 +3,85 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
# reference: https://crane.dev/examples/quick-start-workspace.html
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
rustChannel = pkgs.rust-bin.nightly.latest;
inherit (pkgs) lib;
rustToolchainFor = p: p.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
extensions = [ "rust-src" ];
});
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchainFor;
src = craneLib.cleanCargoSource ./.;
commonArgs = {
inherit src;
strictDeps = true;
# Add additional build inputs here
buildInputs = with pkgs; [
pkg-config
];
nativeBuildInputs = with pkgs; [
openssl
protobuf
];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
individualCrateArgs = commonArgs // {
inherit cargoArtifacts;
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
doCheck = false;
};
fileSetForCrate = crate: lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
(craneLib.fileset.commonCargoSources ./app)
(craneLib.fileset.commonCargoSources ./service)
(craneLib.fileset.commonCargoSources crate)
];
};
faas-rs-crate = craneLib.buildPackage ( individualCrateArgs // {
pname = "faas-rs";
cargoExtraArgs = "--bin faas-rs";
src = fileSetForCrate ./app;
});
in
with pkgs;
{
devShells.default = mkShell {
buildInputs = [
openssl
pkg-config
protobuf
containerd
runc
(rustChannel.default.override {
extensions = [ "rust-src" ];
})
checks = { inherit faas-rs-crate; };
packages.default = faas-rs-crate;
devShells.default = craneLib.devShell {
checks = self.checks.${system};
inputsFrom = [ faas-rs-crate ];
packages = [
pkgs.cargo-hakari
pkgs.containerd
pkgs.runc
];
};
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
'';
};
}
);
}