flake.nix builds the whole project with Nix instead of a manual uv venv: - the Python tracker as a pure Nix-built environment via uv2nix, from tracker/uv.lock (generated by uv lock against pyproject.tomls pins - numpy==2.5.5, opencv-python-headless==5.1.0.95, mediapipe==1.2.3, Python 3.12), so the environment is an immutable Nix store path assembled from hash-pinned wheels, never a mutable venv or a pip install step. libglvnd replaces the manual libGLESv2.so.2 .deb-extraction workaround. - the OS-agnostic core + CTest suite via cmake (nix run .#core-test). - the Windows shim + native tracker cross-compiled via nixpkgs mingw-w64 (pkgsCross.mingwW64/mingw32; nix run .#shim-build), with CXX32/CXX64/CXX_WIN wired to the build scripts override hooks. nix run .#tracker runs the tracker directly; nix develop gives a shell with everything for manual work. docs/setup-linux.md documents the Nix path as the lead option, keeping the uv/venv path as the no-Nix fallback. Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
170 lines
5.8 KiB
Nix
170 lines
5.8 KiB
Nix
{
|
|
description = ''
|
|
Webcam-driven virtual Kinect v1. Builds the whole project with Nix, no
|
|
manual venv:
|
|
- the Python tracker (tracker/) as a pure Nix-built environment from
|
|
tracker/uv.lock (via uv2nix - no `uv venv` / `uv pip install` step,
|
|
the environment itself is a Nix store path built from locked,
|
|
hash-pinned wheels),
|
|
- the OS-agnostic C++ core + its CTest suite (cmake),
|
|
- the Windows Kinect10.dll shim and the native Windows tracker, cross
|
|
compiled with mingw-w64.
|
|
'';
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
|
|
|
pyproject-nix = {
|
|
url = "github:pyproject-nix/pyproject.nix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
uv2nix = {
|
|
url = "github:pyproject-nix/uv2nix";
|
|
inputs.pyproject-nix.follows = "pyproject-nix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
pyproject-build-systems = {
|
|
url = "github:pyproject-nix/build-system-pkgs";
|
|
inputs.pyproject-nix.follows = "pyproject-nix";
|
|
inputs.uv2nix.follows = "uv2nix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
};
|
|
|
|
outputs =
|
|
{
|
|
self,
|
|
nixpkgs,
|
|
pyproject-nix,
|
|
uv2nix,
|
|
pyproject-build-systems,
|
|
...
|
|
}:
|
|
let
|
|
inherit (nixpkgs) lib;
|
|
forAllSystems = lib.genAttrs [
|
|
"x86_64-linux"
|
|
"aarch64-linux"
|
|
];
|
|
|
|
# The Python project lives in tracker/ (its own pyproject.toml + uv.lock,
|
|
# pinned to the known-good combination: Python 3.12, numpy 2.5.5,
|
|
# opencv-python-headless 5.1.0.95, mediapipe 1.2.3).
|
|
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./tracker; };
|
|
|
|
overlay = workspace.mkPyprojectOverlay { sourcePreference = "wheel"; };
|
|
|
|
pythonSets = forAllSystems (
|
|
system:
|
|
let
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
python = pkgs.python312;
|
|
in
|
|
(pkgs.callPackage pyproject-nix.build.packages { inherit python; }).overrideScope
|
|
(
|
|
lib.composeManyExtensions [
|
|
pyproject-build-systems.overlays.wheel
|
|
overlay
|
|
]
|
|
)
|
|
);
|
|
|
|
# Native toolchain (core/ + fallback/windows-nui/ + tracker-native/) shared
|
|
# by the devShell and the build/test/run apps below.
|
|
nativeTools =
|
|
pkgs: with pkgs; [
|
|
cmake
|
|
gnumake
|
|
gcc
|
|
git
|
|
curl
|
|
pkgsCross.mingwW64.buildPackages.gcc # x86_64-w64-mingw32-g++ (64-bit shim + native tracker)
|
|
pkgsCross.mingw32.buildPackages.gcc # i686-w64-mingw32-g++ (32-bit shim, most DEA/spice2x builds)
|
|
];
|
|
|
|
# libGLESv2.so.2 is what mediapipe's native bindings dlopen at runtime
|
|
# (docs/setup-linux.md step 2b used to stage this by hand from a .deb;
|
|
# Nix just needs it on the library path).
|
|
runtimeLibs = pkgs: with pkgs; [ libglvnd ];
|
|
in
|
|
{
|
|
devShells = forAllSystems (
|
|
system:
|
|
let
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
pythonSet = pythonSets.${system};
|
|
# A pure Nix-built environment containing every locked dependency
|
|
# (tracker/uv.lock) - not a venv, not `pip install`d, a Nix store
|
|
# path assembled from hash-pinned wheels.
|
|
trackerEnv = pythonSet.mkVirtualEnv "kinect-tracker-env" workspace.deps.all;
|
|
in
|
|
{
|
|
default = pkgs.mkShell {
|
|
packages = [ trackerEnv ] ++ nativeTools pkgs ++ runtimeLibs pkgs;
|
|
LD_LIBRARY_PATH = lib.makeLibraryPath (runtimeLibs pkgs);
|
|
# Match the shim build scripts' override knobs (fallback/windows-nui/build.sh,
|
|
# tracker-native/build_win.sh) to nixpkgs' mingw-w64 binary names, since the
|
|
# scripts default to the Debian/Ubuntu "-win32"/"-posix" thread-variant names.
|
|
CXX32 = "i686-w64-mingw32-g++";
|
|
CXX64 = "x86_64-w64-mingw32-g++";
|
|
CXX_WIN = "x86_64-w64-mingw32-g++";
|
|
OBJDUMP32 = "i686-w64-mingw32-objdump";
|
|
OBJDUMP64 = "x86_64-w64-mingw32-objdump";
|
|
};
|
|
}
|
|
);
|
|
|
|
apps = forAllSystems (
|
|
system:
|
|
let
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
pythonSet = pythonSets.${system};
|
|
trackerEnv = pythonSet.mkVirtualEnv "kinect-tracker-env" workspace.deps.all;
|
|
in
|
|
{
|
|
# nix run .#tracker -- --source 0 --depth-size 640x480 --shm-name virtual_kinect_frames
|
|
tracker = {
|
|
type = "app";
|
|
program = toString (
|
|
pkgs.writeShellScript "kinect-tracker-run" ''
|
|
exec "${trackerEnv}/bin/python" -m tracker.tracker "$@"
|
|
''
|
|
);
|
|
};
|
|
|
|
core-test = {
|
|
type = "app";
|
|
program = toString (
|
|
pkgs.writeShellScript "kinect-core-test" ''
|
|
set -euo pipefail
|
|
cd "${self}"
|
|
build_dir="$(mktemp -d)"
|
|
trap 'rm -rf "$build_dir"' EXIT
|
|
${pkgs.cmake}/bin/cmake -S . -B "$build_dir"
|
|
${pkgs.cmake}/bin/cmake --build "$build_dir"
|
|
${pkgs.cmake}/bin/ctest --test-dir "$build_dir" --output-on-failure
|
|
''
|
|
);
|
|
};
|
|
|
|
shim-build = {
|
|
type = "app";
|
|
program = toString (
|
|
pkgs.writeShellScript "kinect-shim-build" ''
|
|
set -euo pipefail
|
|
export PATH="${pkgs.pkgsCross.mingwW64.buildPackages.gcc}/bin:${pkgs.pkgsCross.mingw32.buildPackages.gcc}/bin:$PATH"
|
|
export CXX64=x86_64-w64-mingw32-g++
|
|
export CXX32=i686-w64-mingw32-g++
|
|
export OBJDUMP64=x86_64-w64-mingw32-objdump
|
|
export OBJDUMP32=i686-w64-mingw32-objdump
|
|
exec "${self}/fallback/windows-nui/build.sh"
|
|
''
|
|
);
|
|
};
|
|
}
|
|
);
|
|
};
|
|
}
|