nix: partial incremental build of the router (#2416)

This is less incremental than crate2nix, but does build all dependencies
separately, so avoids full rebuilds.
This commit is contained in:
Daniël de Kok 2024-08-14 11:06:28 +02:00 committed by GitHub
parent 1cebccc72b
commit c5fff92b48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 57 additions and 27 deletions

View File

@ -1,4 +1,9 @@
{ mkPoetryApplication, pkg-config, protobuf, openssl }: {
mkPoetryApplication,
pkg-config,
protobuf,
openssl,
}:
mkPoetryApplication { mkPoetryApplication {
# name = "text-generation-server"; # name = "text-generation-server";

View File

@ -579,6 +579,27 @@
"type": "github" "type": "github"
} }
}, },
"naersk": {
"inputs": {
"nixpkgs": [
"tgi-nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1721727458,
"narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=",
"owner": "nix-community",
"repo": "naersk",
"rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "naersk",
"type": "github"
}
},
"nix-github-actions": { "nix-github-actions": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -880,6 +901,7 @@
"inputs": { "inputs": {
"crate2nix": "crate2nix", "crate2nix": "crate2nix",
"flake-utils": "flake-utils_6", "flake-utils": "flake-utils_6",
"naersk": "naersk",
"nixpkgs": [ "nixpkgs": [
"tgi-nix", "tgi-nix",
"nixpkgs" "nixpkgs"

View File

@ -7,6 +7,10 @@
tgi-nix.url = "github:danieldk/tgi-nix"; tgi-nix.url = "github:danieldk/tgi-nix";
nixpkgs.follows = "tgi-nix/nixpkgs"; nixpkgs.follows = "tgi-nix/nixpkgs";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "tgi-nix/nixpkgs";
};
poetry2nix.url = "github:nix-community/poetry2nix"; poetry2nix.url = "github:nix-community/poetry2nix";
rust-overlay = { rust-overlay = {
url = "github:oxalica/rust-overlay"; url = "github:oxalica/rust-overlay";
@ -17,6 +21,7 @@
{ {
self, self,
crate2nix, crate2nix,
naersk,
nixpkgs, nixpkgs,
flake-utils, flake-utils,
rust-overlay, rust-overlay,
@ -41,13 +46,32 @@
tgi-nix.overlay tgi-nix.overlay
]; ];
}; };
naersk' = pkgs.callPackage naersk { };
router =
with pkgs;
naersk'.buildPackage {
name = "router";
src = ./.;
cargoBuildOptions =
x:
x
++ [
"-p"
"text-generation-router-v3"
];
nativeBuildInputs = [ pkg-config ];
buildInputs = [
openssl.dev
protobuf
];
doCheck = false;
};
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryEditablePackage; inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryEditablePackage;
text-generation-server = mkPoetryEditablePackage { text-generation-server = mkPoetryEditablePackage { editablePackageSources = ./server; };
editablePackageSources = ./server;
};
in in
{ {
defaultPackage = router;
devShells.default = devShells.default =
with pkgs; with pkgs;
mkShell { mkShell {
@ -93,10 +117,7 @@
vllm vllm
cargoNix.workspaceMembers.text-generation-launcher.build cargoNix.workspaceMembers.text-generation-launcher.build
router
(callPackage ./router.nix {
inherit (rustPlatform) buildRustPackage importCargoLock;
})
]); ]);
venvDir = "./.venv"; venvDir = "./.venv";

View File

@ -1,18 +0,0 @@
{ buildRustPackage, importCargoLock, pkg-config, protobuf, openssl }:
buildRustPackage {
name = "text-generation-router";
src = ./.;
sourceDir = ./backends/v3;
cargoLock = {
lockFile = ./Cargo.lock;
};
nativeBuildInputs = [ pkg-config ];
buildInputs = [ openssl.dev protobuf ];
}