Files
face-detector/flake.nix
uttarayan21 ac8f1d01b4
Some checks failed
build / checks-build (push) Has been cancelled
build / codecov (push) Has been cancelled
docs / docs (push) Has been cancelled
build / checks-matrix (push) Has been cancelled
feat(detector): add CUDA support for ONNX face detection
2025-08-28 18:32:00 +05:30

245 lines
7.5 KiB
Nix

{
description = "A simple rust flake using rust-overlay and craneLib";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
nix-github-actions = {
url = "github:nix-community/nix-github-actions";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
mnn-overlay = {
url = "github:uttarayan21/mnn-nix-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
mnn-src = {
url = "github:alibaba/MNN/3.2.2";
flake = false;
};
};
outputs = {
self,
crane,
flake-utils,
nixpkgs,
rust-overlay,
advisory-db,
nix-github-actions,
mnn-overlay,
mnn-src,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
config.cudaSupport = pkgs.stdenv.isLinux;
overlays = [
rust-overlay.overlays.default
(final: prev: {
mnn = mnn-overlay.packages.${system}.mnn.override {
src = mnn-src;
buildConverter = true;
enableMetal = pkgs.stdenv.isDarwin;
enableOpencl = true;
};
})
];
};
inherit (pkgs) lib;
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
name = cargoToml.package.name;
stableToolchain = pkgs.rust-bin.stable.latest.default;
stableToolchainWithLLvmTools = stableToolchain.override {
extensions = [
"rust-src"
"llvm-tools"
];
};
stableToolchainWithRustAnalyzer = stableToolchain.override {
extensions = [
"rust-src"
"rust-analyzer"
];
};
craneLib = (crane.mkLib pkgs).overrideToolchain stableToolchain;
craneLibLLvmTools = (crane.mkLib pkgs).overrideToolchain stableToolchainWithLLvmTools;
ort_static = (pkgs.onnxruntime.overide {cudaSupport = true;}).overrideAttrs (old: {
cmakeFlags =
old.cmakeFlags
++ [
"-Donnxruntime_BUILD_SHARED_LIB=OFF"
"-Donnxruntime_BUILD_STATIC_LIB=ON"
];
});
patchedOnnxruntime = pkgs.onnxruntime.overrideAttrs (old: {
patches = [./patches/ort_env_global_mutex.patch];
});
src = let
filterBySuffix = path: exts: lib.any (ext: lib.hasSuffix ext path) exts;
sourceFilters = path: type:
(craneLib.filterCargoSources path type)
|| filterBySuffix path [
".c"
".h"
".hpp"
".cpp"
".cc"
".mnn"
".onnx"
];
in
lib.cleanSourceWith {
filter = sourceFilters;
src = ./.;
};
commonArgs =
{
inherit src;
pname = name;
stdenv = p: p.clangStdenv;
doCheck = false;
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
# ORT_LIB_LOCATION = "${patchedOnnxruntime}";
# ORT_ENV_SYSTEM_LIB_LOCATION = "${patchedOnnxruntime}/lib";
# ORT_ENV_PREFER_DYNAMIC_LINK = true;
nativeBuildInputs = with pkgs; [
cmake
pkg-config
];
buildInputs = with pkgs;
[
patchedOnnxruntime
sqlite
]
++ (lib.optionals pkgs.stdenv.isDarwin [
libiconv
apple-sdk_13
]);
}
// (lib.optionalAttrs pkgs.stdenv.isLinux {
# BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.llvmPackages.libclang.lib}/lib/clang/18/include";
});
cargoArtifacts = craneLib.buildPackage commonArgs;
in {
checks =
{
"${name}-clippy" = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
"${name}-docs" = craneLib.cargoDoc (commonArgs // {inherit cargoArtifacts;});
"${name}-fmt" = craneLib.cargoFmt {inherit src;};
"${name}-toml-fmt" = craneLib.taploFmt {
src = pkgs.lib.sources.sourceFilesBySuffices src [".toml"];
};
# Audit dependencies
"${name}-audit" = craneLib.cargoAudit {
inherit src advisory-db;
};
# Audit licenses
"${name}-deny" = craneLib.cargoDeny {
inherit src;
};
"${name}-nextest" = craneLib.cargoNextest (
commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
}
);
}
// lib.optionalAttrs (!pkgs.stdenv.isDarwin) {
"${name}-llvm-cov" = craneLibLLvmTools.cargoLlvmCov (commonArgs // {inherit cargoArtifacts;});
};
packages = let
pkg = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
}
// {
nativeBuildInputs = with pkgs;
commonArgs.nativeBuildInputs
++ [
installShellFiles
];
postInstall = ''
installShellCompletion --cmd ${name} \
--bash <($out/bin/${name} completions bash) \
--fish <($out/bin/${name} completions fish) \
--zsh <($out/bin/${name} completions zsh)
'';
}
);
in {
"${name}" = pkg;
default = pkg;
onnxruntime = ort_static;
};
devShells = {
default = pkgs.mkShell.override {stdenv = pkgs.clangStdenv;} (
commonArgs
// rec {
LLDB_DEBUGSERVER_PATH = "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver";
LD_LIBRARY_PATH = "$LD_LIBRARY_PATH:${builtins.toString (pkgs.lib.makeLibraryPath packages)}";
packages = with pkgs;
[
stableToolchainWithRustAnalyzer
cargo-expand
cargo-outdated
cargo-nextest
cargo-deny
cmake
mnn
cargo-make
hyperfine
opencv
]
++ (lib.optionals pkgs.stdenv.isDarwin [
apple-sdk_13
])
++ (lib.optionals pkgs.stdenv.isLinux [
xorg.libX11
xorg.libXcursor
xorg.libXrandr
xorg.libXi
xorg.libxcb
libxkbcommon
vulkan-loader
wayland
zenity
cudatoolkit
]);
}
);
};
}
)
// {
githubActions = nix-github-actions.lib.mkGithubMatrix {
checks = nixpkgs.lib.getAttrs ["x86_64-linux"] self.checks;
};
};
}