Skip to content

Depthaiv3 alpha15#402019

Draft
phodina wants to merge 8 commits into
NixOS:masterfrom
phodina:depthaiv3_alpha15_draft
Draft

Depthaiv3 alpha15#402019
phodina wants to merge 8 commits into
NixOS:masterfrom
phodina:depthaiv3_alpha15_draft

Conversation

@phodina

@phodina phodina commented Apr 26, 2025

Copy link
Copy Markdown
Contributor

Add DepthAI package which is basically OpenCV running on Edge devices made by Luxonis.

Currently work in progress therefore marked as Draft, would like to decrease the amoutn of patches by upstreaming some of the changes like

Package request

Github repo link

Upstreaming the flake environment

WIP Dependencies:

CC: @jayrahdevore @tmayoff @hacker1024 @Pandapip1

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin (don't have any around, might fail on install of the install of shared library)
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@phodina phodina force-pushed the depthaiv3_alpha15_draft branch from 170f800 to b902544 Compare April 26, 2025 13:18
@github-actions github-actions Bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Apr 26, 2025
@phodina phodina force-pushed the depthaiv3_alpha15_draft branch from b902544 to 4406da9 Compare April 26, 2025 13:37
@phodina

phodina commented Apr 30, 2025

Copy link
Copy Markdown
Contributor Author

@phodina

phodina commented May 1, 2025

Copy link
Copy Markdown
Contributor Author

The libnop and mp4v2 don't populate the lib/cmake so they are not found.

Porting basalt is still WIP, biggest issue is the large dependency on third party packages from ROS.

@phodina phodina changed the title DRAFT: Depthaiv3 alpha15 Depthaiv3 alpha15 May 1, 2025
@phodina phodina marked this pull request as ready for review May 1, 2025 17:43
Comment thread pkgs/by-name/ba/backward-cpp/package.nix Outdated
@Pandapip1

Copy link
Copy Markdown
Member

Porting basalt is still WIP, biggest issue is the large dependency on third party packages from ROS.

I was working on ROS stuff at #355629, but it stalled because it was noted that ROS is pretty actively developed. If you want I can restart the effort.

@phodina

phodina commented May 2, 2025

Copy link
Copy Markdown
Contributor Author

I was working on ROS stuff at #355629, but it stalled because it was noted that ROS is pretty actively developed. If you want I can restart the effort.

AFAIK basalt is not required. It's optional dependency, though would love to make it work. However, first I'd focus just on DAI and then on the ROS ecosystem and finding way to package basalt.

Would like to do one more pass of the DAI package and mark the optional stuff and split package into multiple outputs.

Also it might be work to make two definitions - one that does not have dependencies on GUI stuff (good for containers) and then full blown implementation.

@ofborg ofborg Bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 3, 2025
@phodina

phodina commented May 3, 2025

Copy link
Copy Markdown
Contributor Author

FIY oakctl Not required as dependency but useful tool for OAK4 line

#403889

@phodina phodina force-pushed the depthaiv3_alpha15_draft branch from a0a6b55 to 0bff900 Compare May 4, 2025 15:41
@ofborg ofborg Bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label May 4, 2025
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 17, 2025
@phodina phodina force-pushed the depthaiv3_alpha15_draft branch from b0d4a30 to f5db0dd Compare May 18, 2025 07:09
@phodina

phodina commented May 18, 2025

Copy link
Copy Markdown
Contributor Author

Rebased and removed the already merged commits for libnop and cpr

Should I also squash the commits for depthai-data and depthai-core`?

@ofborg ofborg Bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label May 18, 2025
@Pandapip1

Pandapip1 commented May 18, 2025

Copy link
Copy Markdown
Member

Should I also squash the commits for depthai-data and depthai-core`?

Nope! These are different packages and should keep their separate commits. The individual commits for each package probably should be squashed into one commit per package, but this is no means a requirement. See #347586

@phodina

phodina commented May 18, 2025

Copy link
Copy Markdown
Contributor Author

Nope! These are different packages and should keep their separate commits. The individual commits for each package probably should be squashed into one commit per package, but this is no means a requirement. See #347586

Agreed on that.

Well meant just per package as each has several changes so that there's just one depthai-core and another for depthai-data. IMHO I don't see benefit in keeping both the alpha14 and alpha15 versions as there are alpha.

@phodina

phodina commented May 18, 2025

Copy link
Copy Markdown
Contributor Author

There are additional points. IMHO I'd split the definition into multiple subpackages:

  • depthai-core-minimal (OpenCV without GTK support, optional CMake flags turned off)
  • depthai-core (OpenCV with GTK support, more CMake flags turned on)
  • depthai-core-full (turn on examples and tests, for C++ and Python)

Also there are tests but they require HW attached or available on either the USB or network. Therefore they can't be just enabled and executed as part of the derivation, right? Or is there as it's similar to GPU as they are also not available in the sandbox environment but do have test suites.

If so could set up hardware to run the tests to see if everything is working (I just use subset of the DAI features that in my case so far work).

@github-actions github-actions Bot added the 6.topic: python Python is a high-level, general-purpose programming language. label May 18, 2025
@nix-owners nix-owners Bot requested a review from natsukium May 18, 2025 10:33
@phodina phodina force-pushed the depthaiv3_alpha15_draft branch 2 times, most recently from c399786 to 82d9152 Compare May 22, 2025 07:51
@nix-owners nix-owners Bot requested a review from mweinelt May 22, 2025 07:53
@phodina

phodina commented May 22, 2025

Copy link
Copy Markdown
Contributor Author

So pushed changes tracking the v3_develop branch as there were many changes that allow more CMake config options and more offline build.

@mweinelt

mweinelt commented May 22, 2025

Copy link
Copy Markdown
Member

Looks like you grabbed an unrelated home-assistant commit when rebasing.

66c0c09

@mweinelt mweinelt removed their request for review May 22, 2025 13:07
@nix-owners nix-owners Bot requested a review from mweinelt May 28, 2025 10:50
@phodina

phodina commented May 28, 2025

Copy link
Copy Markdown
Contributor Author

@Pandapip1 switched to v3.0.0-beta.1 and squashed the previous commits. Also put all the nixpkgs changes into single patch. Rest of the patches is either merged in the v3_develop branch or pending review.

@phodina phodina force-pushed the depthaiv3_alpha15_draft branch from 82d9152 to 9cf32e7 Compare May 28, 2025 10:55
@phodina phodina force-pushed the depthaiv3_alpha15_draft branch from 9cf32e7 to 61bb2e6 Compare May 28, 2025 11:06
@phodina

phodina commented May 31, 2025

Copy link
Copy Markdown
Contributor Author

There are additional points. IMHO I'd split the definition into multiple subpackages:

depthai-core-minimal (OpenCV without GTK support, optional CMake flags turned off)
depthai-core (OpenCV with GTK support, more CMake flags turned on)
depthai-core-full (turn on examples and tests, for C++ and Python)

Split the package into multiple based on enabled features.

Also there are tests but they require HW attached or available on either the USB or network. Therefore they can't be just enabled and executed as part of the derivation, right? Or is there as it's similar to GPU as they are also not available in the sandbox environment but do have test suites.

Also the nix package builds as a part of depthai-core repo Github CI. The tests are next step to implement.

Lastly I'd like to also split further the outputs - probably dev, out, python and share.

@phodina phodina force-pushed the depthaiv3_alpha15_draft branch from 21f1b34 to 86d47f1 Compare May 31, 2025 10:35
@phodina phodina force-pushed the depthaiv3_alpha15_draft branch from 86d47f1 to b86b6db Compare May 31, 2025 10:44
@phodina

phodina commented May 31, 2025

Copy link
Copy Markdown
Contributor Author

What needs to improve/minimize is the pkgs/by-name/de/depthai-core/0001-nixos-specific-patches.patch. The patched out lines are mostly due to VCPKG that has CMake configs for the dependencies but they are not present in Nix so needs revert to pkg-config.

@phodina

phodina commented May 31, 2025

Copy link
Copy Markdown
Contributor Author

Any idea how to handle the check if the package is split?

- Because pkgs/by-name/de/depthai-core exists, the attribute `pkgs.depthai-core` must be defined like

    depthai-core = callPackage ./../by-name/de/depthai-core/package.nix { /* ... */ };

  However, in this PR, it isn't defined that way. See the definition in pkgs/top-level/all-packages.nix:363

    depthai-core

@phodina

phodina commented Jul 10, 2025

Copy link
Copy Markdown
Contributor Author

@Pandapip1 could I ask you for in-depth review?

@Pandapip1 Pandapip1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass. Please excuse any typos, this was written on my phone over a train ride.

@@ -0,0 +1 @@
{ lib, callPackage }: callPackage ./package.nix { inherit lib; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here? This seemingly serves no purpose.


catch2_3WithSharedLibs = catch2_3.overrideAttrs (oldAttrs: {
cmakeFlags = (oldAttrs.cmakeFlags or [ ]) ++ [
"-DBUILD_SHARED_LIBS=ON"

@Pandapip1 Pandapip1 Jul 10, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be stdenv.hostPlatform.isStatic, not just always on. Also, consider using the helper for readability:

Suggested change
"-DBUILD_SHARED_LIBS=ON"
(lib.cmakeBool "BUILD_SHARED_LIBS" (!(stdenv.hostPlatform.isStatic)))

Also, this seems like an oversight and you should feel free to add this to the actual catch2_3 package.

Comment on lines +63 to +64
# Latest commits are not compatible, use older version
ws-protocolCompat = ws-protocol.overrideAttrs (old: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, but:

  1. Has this been reported yet;
  2. If it has, can you add a comment with a link to the issue?

Also, is there a specific commit that broke it? If so, consider adding a patch that reverts that commit.

patches = [ ./001-Ws-protocol-add-missing-libs.patch ];
});

prefixVar = "\${" + "prefix}";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prefixVar = "\${" + "prefix}";
prefixVar = "''${prefix}";

This is apparently how you properly escape this.

Comment on lines +76 to +77
# Latest commits are not compatible, use older version
xtensorCompat = xtensor.overrideAttrs (old: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, if there's an existing issue please link to it, else please create one.

src = fetchFromGitHub {
owner = "foxglove";
repo = "ws-protocol";
tag = "releases/cpp/v${finalAttrs.version}";

@Pandapip1 Pandapip1 Jul 10, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⁉️

Is there any reason this can't be used?

tag = "v${finalAttrs.version}";

Never mind, this is actually correct. That's actually horrible.

hash = "sha256-JMCwxShOOv1PSrlKiPGtsCgKJVR+7ds9otKrlPHfIio=";
};

# On Darwin the `openssl` and `zlib` are not found during linking

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been reported upstream?


sourceRoot = "${finalAttrs.src.name}/cpp/foxglove-websocket";

cmakeFlags = [ (lib.cmakeBool "BUILD_SHARED_LIBS" true) ];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know the drill

Suggested change
cmakeFlags = [ (lib.cmakeBool "BUILD_SHARED_LIBS" true) ];
cmakeFlags = [ (lib.cmakeBool "BUILD_SHARED_LIBS" (!(stdenv.hostPlatform.isStatic))) ];

cat > $out/lib/pkgconfig/foxglove-websocket.pc << EOF
Name: foxglove-websocket
Description: Foxglove WebSocket Protocol Implementation
Version: ${finalAttrs.version}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider:

Suggested change
Version: ${finalAttrs.version}
Version: $version

I'm pretty sure this is preferred. I could be wrong though.

Comment on lines +362 to +366
inherit (callPackage ../by-name/de/depthai-core/package.nix { })
depthai-core
depthai-core-minimal
depthai-core-full
;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, a few things:

  1. default.nix is seemingly unused then and should be removed;
  2. package.nixes in by-name should resolve to a derivation, not an attrset. The fact that it's not and then you're masking it in all-packages.nix is very cursed and will likely break something at some point.
  3. To fix 2, just use depthai-core-full = depthai-core.override { ... } in all-packages.nix

@Pandapip1 Pandapip1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2nd pass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding pytestCheckHook, and a pythonImportsCheck

Comment on lines +23 to +27
nativeBuildInputs = [ flit-core ];
propagatedBuildInputs = [
docutils
libclang
];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nativeBuildInputs = [ flit-core ];
propagatedBuildInputs = [
docutils
libclang
];
build-system = [ flit-core ];
dependencies = [
docutils
libclang
];

python packages are weird and use different naming. I think there's some additional handling that happens when you name things correctly.


# Create foxglove-websocketConfigVersion.cmake
cat > $out/lib/cmake/foxglove-websocket/foxglove-websocketConfigVersion.cmake << EOF
set(PACKAGE_VERSION "${finalAttrs.version}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(PACKAGE_VERSION "${finalAttrs.version}")
set(PACKAGE_VERSION "$version")

Missed this too. Again, not required but I seem to recall this is recommended over string templates.

# foxglove-websocket CMake configuration file

# Compute installation prefix relative to this file
get_filename_component(_IMPORT_PREFIX "\''${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that \ is required. Could be wrong, but:

Suggested change
get_filename_component(_IMPORT_PREFIX "\''${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
get_filename_component(_IMPORT_PREFIX "''${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)


cmakeFlags = [
(lib.cmakeBool "BUILD_EXAMPLE" true)
(lib.cmakeBool "BUILD_TESTS" true)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be run in checkPhase.

});

# Latest commits are not compatible, use older version
ws-protocolCompat = ws-protocol.overrideAttrs (old: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old is seemingly not used

Suggested change
ws-protocolCompat = ws-protocol.overrideAttrs (old: {
ws-protocolCompat = ws-protocol.overrideAttrs {

});

# Latest commits are not compatible, use older version
xlinkCompat = xlink.overrideAttrs (old: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old is seemingly not used

Suggested change
xlinkCompat = xlink.overrideAttrs (old: {
xlinkCompat = xlink.overrideAttrs {

Comment on lines +127 to +130
pyOpencv4WithGtk = python3Packages.opencv4.override {
enableGtk2 = true; # For GTK2 support
enableGtk3 = true; # For GTK3 support
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pyOpencv4WithGtk = python3Packages.opencv4.override {
enableGtk2 = true; # For GTK2 support
enableGtk3 = true; # For GTK3 support
};

Unused

Comment on lines +132 to +136
rerun_sdk = fetchzip {
url = "https://github.com/rerun-io/rerun/releases/download/0.16.1/rerun_cpp_sdk.zip";
hash = "sha256-tYwcRjlU8m+OHkwdbQeM+X5outF0NFbj8Ee3y5h9+l0=";
stripRoot = false; # Important for zip files to preserve the directory structure
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be a fetchFromGitHub?


preConfigure = ''
echo "Fixing xtensor.pc.in for Nix compatibility..."
find . -name xtensor.pc.in -exec sed -i 's|${prefixVar}/@CMAKE_INSTALL_LIBDIR@|@CMAKE_INSTALL_FULL_LIBDIR@|g' {} \;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefixVar is only ever used here. Consider:

Suggested change
find . -name xtensor.pc.in -exec sed -i 's|${prefixVar}/@CMAKE_INSTALL_LIBDIR@|@CMAKE_INSTALL_FULL_LIBDIR@|g' {} \;
find . -name xtensor.pc.in -exec sed -i 's|''${prefix}/@CMAKE_INSTALL_LIBDIR@|@CMAKE_INSTALL_FULL_LIBDIR@|g' {} \;

and dropping the variable

@phodina

phodina commented Jul 15, 2025

Copy link
Copy Markdown
Contributor Author

First pass. Please excuse any typos, this was written on my phone over a train ride.

No porblem. Thanks, started on the fixes

@nixpkgs-ci nixpkgs-ci Bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Oct 6, 2025
@nixpkgs-ci nixpkgs-ci Bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 12, 2026
@phodina

phodina commented Jan 28, 2026

Copy link
Copy Markdown
Contributor Author

As I'm no longer affiliated with Luxonis I must put this into a draft mode.

If there would be anyone willing to take up the mantel feel free :)

@MaticTonin would you take on the challenge?

@phodina phodina marked this pull request as draft January 28, 2026 09:37
@nixpkgs-ci nixpkgs-ci Bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 28, 2026
@Amronos

Amronos commented Feb 8, 2026

Copy link
Copy Markdown
Member

I have been very slowly going through the code and cleaning it up for a while now. It will take a lot more time to have a mergeable PR ready, but if somebody wants to take a look/collaborate, I can put up a draft PR.

@Amronos Amronos mentioned this pull request Mar 15, 2026
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: python Python is a high-level, general-purpose programming language. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants