mirror of
https://github.com/perstarkse/minne.git
synced 2026-07-01 18:41:37 +02:00
refactor: harmonized nix ci alignment
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
crane,
|
||||
}: let
|
||||
inherit (nixpkgs.legacyPackages.x86_64-linux) lib;
|
||||
ortVersion = lib.removeSuffix "\n" (builtins.readFile "${self}/ort-version");
|
||||
ortVersion = "1.23.2";
|
||||
in
|
||||
flake-utils.lib.eachDefaultSystem (system: let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
@@ -24,83 +24,182 @@
|
||||
if pkgs.stdenv.isDarwin
|
||||
then "dylib"
|
||||
else "so";
|
||||
minne-pkg =
|
||||
if pkgs.onnxruntime.version == ortVersion then
|
||||
craneLib.buildPackage {
|
||||
minneVersion = "1.0.3";
|
||||
|
||||
# Pre-download mozjs binary archive for mozjs_sys (servo dep).
|
||||
# When updating mozjs_sys version in Cargo.lock, update this URL too.
|
||||
mozjsArchive = pkgs.fetchurl {
|
||||
url = "https://github.com/servo/mozjs/releases/download/mozjs-sys-v140.10.1-0/libmozjs-x86_64-unknown-linux-gnu.tar.gz";
|
||||
hash = "sha256-e5kW8HTg6Hrd3sGgU9bqFNTTf7wJCChFOwKE3xyYT4Q=";
|
||||
};
|
||||
|
||||
# Extra paths (common/db, html-router/templates, html-router/assets) are
|
||||
# embedded at compile time via include_dir! / minijinja_embed.
|
||||
commonArgs = {
|
||||
version = minneVersion;
|
||||
src = lib.cleanSourceWith {
|
||||
src = ./.;
|
||||
filter = let
|
||||
extraPaths = [
|
||||
filter = path: type:
|
||||
craneLib.filterCargoSources path type
|
||||
|| lib.any (x: lib.hasPrefix (toString x) (toString path)) [
|
||||
(toString ./Cargo.lock)
|
||||
(toString ./common/db)
|
||||
(toString ./html-router/templates)
|
||||
(toString ./html-router/assets)
|
||||
];
|
||||
in
|
||||
path: type: let
|
||||
p = toString path;
|
||||
in
|
||||
craneLib.filterCargoSources path type
|
||||
|| lib.any (x: lib.hasPrefix x p) extraPaths;
|
||||
};
|
||||
strictDeps = true;
|
||||
|
||||
pname = "minne";
|
||||
version = "1.0.3";
|
||||
# Uses nixpkgs rustc (stable). Release/Docker pin: rust-toolchain.toml (1.91.1).
|
||||
doCheck = false;
|
||||
buildInputs = [
|
||||
pkgs.openssl
|
||||
pkgs.libglvnd
|
||||
pkgs.onnxruntime
|
||||
pkgs.fontconfig # .pc for yeslogic-fontconfig-sys (servo dep)
|
||||
pkgs.libclang.lib # libclang.so for bindgen (servo dep)
|
||||
];
|
||||
|
||||
nativeBuildInputs = [pkgs.pkg-config pkgs.rustfmt pkgs.makeWrapper];
|
||||
buildInputs = [pkgs.openssl pkgs.libglvnd pkgs.onnxruntime];
|
||||
nativeBuildInputs = [
|
||||
pkgs.pkg-config
|
||||
pkgs.rustfmt
|
||||
pkgs.makeWrapper
|
||||
pkgs.python3 # needed by servo's stylo crate build.rs
|
||||
pkgs.llvmPackages.llvm # llvm-objdump for mozjs_sys (servo dep)
|
||||
pkgs.rustPlatform.bindgenHook # configures bindgen (servo deps)
|
||||
];
|
||||
|
||||
postInstall = ''
|
||||
wrapProgram $out/bin/main \
|
||||
--prefix LD_LIBRARY_PATH : ${pkgs.libglvnd}/lib \
|
||||
--set ORT_DYLIB_PATH ${pkgs.onnxruntime}/lib/libonnxruntime.${libExt}
|
||||
for b in worker server; do
|
||||
if [ -x "$out/bin/$b" ]; then
|
||||
wrapProgram $out/bin/$b \
|
||||
--prefix LD_LIBRARY_PATH : ${pkgs.libglvnd}/lib \
|
||||
--set ORT_DYLIB_PATH ${pkgs.onnxruntime}/lib/libonnxruntime.${libExt}
|
||||
fi
|
||||
done
|
||||
'';
|
||||
}
|
||||
else
|
||||
throw "pkgs.onnxruntime.version (${pkgs.onnxruntime.version}) must match ort-version (${ortVersion})";
|
||||
# Provide pre-downloaded mozjs archive so it doesn't need network
|
||||
MOZJS_ARCHIVE = "${mozjsArchive}";
|
||||
};
|
||||
|
||||
# cargoBuild (not buildDepsOnly) avoids mkDummySrc breaking native build scripts.
|
||||
cargoArtifacts = craneLib.cargoBuild (commonArgs
|
||||
// {
|
||||
cargoArtifacts = null;
|
||||
pname = "minne-deps";
|
||||
cargoExtraArgs = "--workspace";
|
||||
doCheck = false;
|
||||
doInstallCargoArtifacts = true;
|
||||
installPhaseCommand = "";
|
||||
});
|
||||
|
||||
minne-pkg =
|
||||
if pkgs.onnxruntime.version == ortVersion
|
||||
then
|
||||
craneLib.buildPackage (commonArgs
|
||||
// {
|
||||
pname = "minne";
|
||||
version = minneVersion;
|
||||
inherit cargoArtifacts;
|
||||
doCheck = false; # checks are in separate derivations
|
||||
doInstallCargoArtifacts = true; # for reuse by check derivations
|
||||
|
||||
postInstall = ''
|
||||
wrapProgram $out/bin/main \
|
||||
--prefix LD_LIBRARY_PATH : ${pkgs.libglvnd}/lib \
|
||||
--set ORT_DYLIB_PATH ${pkgs.onnxruntime}/lib/libonnxruntime.${libExt}
|
||||
for b in worker server; do
|
||||
if [ -x "$out/bin/$b" ]; then
|
||||
wrapProgram $out/bin/$b \
|
||||
--prefix LD_LIBRARY_PATH : ${pkgs.libglvnd}/lib \
|
||||
--set ORT_DYLIB_PATH ${pkgs.onnxruntime}/lib/libonnxruntime.${libExt}
|
||||
fi
|
||||
done
|
||||
'';
|
||||
})
|
||||
else throw "pkgs.onnxruntime.version (${pkgs.onnxruntime.version}) must match ortVersion in flake.nix (${ortVersion})";
|
||||
|
||||
dockerImage = pkgs.dockerTools.buildLayeredImage {
|
||||
name = "minne";
|
||||
tag = minneVersion;
|
||||
created = "now";
|
||||
|
||||
contents = [
|
||||
minne-pkg
|
||||
pkgs.cacert
|
||||
pkgs.bashInteractive
|
||||
pkgs.libglvnd
|
||||
pkgs.fontconfig.lib
|
||||
pkgs.freetype
|
||||
pkgs.stdenv.cc.cc.lib # libgomp (OpenMP) for ONNX Runtime
|
||||
];
|
||||
|
||||
maxLayers = 25;
|
||||
|
||||
config = {
|
||||
Cmd = ["${minne-pkg}/bin/main"];
|
||||
Env = [
|
||||
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-certificates.crt"
|
||||
"ORT_DYLIB_PATH=${pkgs.onnxruntime}/lib/libonnxruntime.${libExt}"
|
||||
];
|
||||
ExposedPorts = {"3000/tcp" = {};};
|
||||
User = "appuser";
|
||||
};
|
||||
};
|
||||
in {
|
||||
packages = {
|
||||
minne-pkg = minne-pkg;
|
||||
inherit minne-pkg dockerImage;
|
||||
default = minne-pkg;
|
||||
};
|
||||
|
||||
apps = {
|
||||
main = flake-utils.lib.mkApp {
|
||||
drv = minne-pkg;
|
||||
name = "main";
|
||||
main = {
|
||||
type = "app";
|
||||
program = "${minne-pkg}/bin/main";
|
||||
meta.description = "Minne main server — API, web UI, and background worker";
|
||||
};
|
||||
worker = flake-utils.lib.mkApp {
|
||||
drv = minne-pkg;
|
||||
name = "worker";
|
||||
worker = {
|
||||
type = "app";
|
||||
program = "${minne-pkg}/bin/worker";
|
||||
meta.description = "Minne standalone background worker (ingestion, indexing, maintenance)";
|
||||
};
|
||||
server = flake-utils.lib.mkApp {
|
||||
drv = minne-pkg;
|
||||
name = "server";
|
||||
server = {
|
||||
type = "app";
|
||||
program = "${minne-pkg}/bin/server";
|
||||
meta.description = "Minne API-only server (no background worker)";
|
||||
};
|
||||
default = flake-utils.lib.mkApp {
|
||||
drv = minne-pkg;
|
||||
name = "main";
|
||||
default = {
|
||||
type = "app";
|
||||
program = "${minne-pkg}/bin/main";
|
||||
meta.description = "Minne main server — API, web UI, and background worker";
|
||||
};
|
||||
};
|
||||
|
||||
checks = {
|
||||
ortVersion = pkgs.runCommand "ort-version-check" {} ''
|
||||
if [ "${pkgs.onnxruntime.version}" != "${ortVersion}" ]; then
|
||||
echo "pkgs.onnxruntime.version is ${pkgs.onnxruntime.version}, but ort-version pins ${ortVersion}" >&2
|
||||
echo "Update ort-version or wait for nixpkgs to catch up." >&2
|
||||
echo "pkgs.onnxruntime.version is ${pkgs.onnxruntime.version}, but flake pins ${ortVersion}" >&2
|
||||
echo "Update ortVersion in flake.nix or wait for nixpkgs to catch up." >&2
|
||||
exit 1
|
||||
fi
|
||||
touch $out
|
||||
'';
|
||||
|
||||
minne-clippy = craneLib.cargoClippy (commonArgs
|
||||
// {
|
||||
cargoArtifacts = minne-pkg;
|
||||
pname = "minne";
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
});
|
||||
|
||||
minne-test = craneLib.cargoTest (commonArgs
|
||||
// {
|
||||
cargoArtifacts = minne-pkg;
|
||||
pname = "minne";
|
||||
buildInputs = commonArgs.buildInputs ++ [ pkgs.cacert ];
|
||||
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-certificates.crt";
|
||||
cargoTestExtraArgs = "--lib --bins";
|
||||
});
|
||||
|
||||
minne-fmt = craneLib.cargoFmt {
|
||||
pname = "minne-fmt";
|
||||
version = minneVersion;
|
||||
src = craneLib.cleanCargoSource ./.;
|
||||
};
|
||||
};
|
||||
})
|
||||
// {
|
||||
lib = {
|
||||
inherit ortVersion;
|
||||
};
|
||||
}) // {
|
||||
ortVersion = ortVersion;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user