NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.63k stars 13.79k forks source link

Package request: depthai-core #292618

Open Pandapip1 opened 7 months ago

Pandapip1 commented 7 months ago

Project description

DepthAI API allows users to connect to, configure and communicate with their OAK devices.

Metadata


Add a :+1: reaction to issues you find important.

jayrahdevore commented 4 months ago

I looked into this a few months ago and got it to build. However, in the end, I ended up just using the binary python release. That said, I wanted to post a few things I found in case anyone wants to pick it up:

Anyways, this information is bound to change as it sits. That said, I hope it's helpful to someone who is able to take it on

tmayoff commented 4 months ago

I did start working on this, going through many of the same issues. Currently the issue is building with spdlog and fmt, I couldn't find the right versions. I'll try again with the versions you mentioned.

This is the repo I've been working on, it's currently a mess but once it builds and is usable I can clean it all up

tmayoff commented 4 months ago

@jayrahdevore, do you still have that attempt somewhere, if not would you be able to help me out with the spdlog/fmt stuff.

jayrahdevore commented 4 months ago

@tmayoff I had a giant flake I was working with to build a patched form of the repo. I builds something, but I left it at that. I took out a some fluff that I had commented out, so I doubt it runs as-is. That said, it should have the spdlog/fmt stuff taken care of

{
  description = "DepthAI Core WIP";

  inputs = {
    nixpkgs = { url = "github:nixos/nixpkgs/nixos-23.11"; };
    nixpkgs_unstable = { url = "github:nixos/nixpkgs/nixos-unstable"; };
    nixpkgs_21 = { url = "github:nixos/nixpkgs/nixos-21.05"; };
    nix-ros = { url = "github:clearpathrobotics/nix-ros"; };
  };

  outputs = { self, nixpkgs, nixpkgs_unstable, nixpkgs_21, nix-ros, ... }:
    let
      # system should match the system you are running on
      system = "x86_64-linux";

      psimd = pkgs.fetchFromGitHub {
        # We just want the source code
        owner = "Maratyszcza";
        repo = "psimd";
        rev = "072586a71b55b7f8c584153d223e95687148a900";
        sha256 = "sha256-lV+VZi2b4SQlRYrhKx9Dxc6HlDEFz3newvcBjTekupo=";
      };

    patched-zlib = pkgs.stdenv.mkDerivation {
      name = "zlib";
      version = "1.2.11-p2";
      src = pkgs.fetchurl {
        url = "https://github.com/luxonis/zlib/archive/refs/tags/v1.2.11-p2.tar.gz";
        hash = "sha256-KA/svhJsMkjjcPf37BCLLhwYkhDguWPqppIt+pWHHfU=";
      };
    };

    new-libarchive = pkgs.libarchive.overrideAttrs {
      cmakeFlags = [
        "-DENABLE_LZMA=ON"
      ];
    };

    depthai-shared = pkgs.fetchFromGitHub {
      owner = "luxonis";
      repo = "depthai-shared";
      rev = "0eb366fd836a062c42c7193d79eaa627cda57abd";
      sha256 = "sha256-uSMp+En1PcpiITutMxlBQMLYJA71hNexE6gWm7EGO8w=";
    };

    depthai-bootloader-shared = pkgs.fetchFromGitHub {
      owner = "luxonis";
      repo = "depthai-bootloader-shared";
      rev = "b287ecbacd3b0c963b5dfcf95767123b0c143b57";
      sha256 = "sha256-ZsfqApF2eQQdrLpazvThYAa+sOpV4t3f5oBIChHYVns=";
    };

    depthai-bootloader = pkgs.stdenv.mkDerivation {
      name = "depthai-bootloader";
      src = pkgs.fetchurl {
        url = "https://artifacts.luxonis.com/artifactory/luxonis-myriad-release-local/depthai-bootloader/0.0.17/depthai-bootloader-fwp-0.0.17.tar.xz";
        hash = "sha256-J+oNeXSY9//x2C6VJOpqJEpZmEJLUj6rmzU5RFSLy+8=";
      };
      unpackPhase = "";
      installPhase = ''
        mkdir -p $out
        # cp depthai-bootloader-fwp-0.0.17.tar.xz $out/depthai-bootloader-fwp.tar.gz
        cp $src $out/depthai-bootloader-fwp.tar.xz
      '';
      sourceRoot = ".";
    };

    depthai-bootloader-devices = pkgs.stdenv.mkDerivation {
      name = "depthai-bootloader-devices";
      src = pkgs.fetchurl {
        url = "https://artifacts.luxonis.com/artifactory/luxonis-myriad-snapshot-local/depthai-device-side/afe8d00c868344c73ee897e26278f80a444b9763/depthai-device-fwp-afe8d00c868344c73ee897e26278f80a444b9763.tar.xz";
        sha256 = "sha256-XMbmPVwQQww8xz90J4ySijnTa4YBYEA5YuiY5j75YEY=";
      };
      installPhase = ''
        mkdir -p $out
        # cp -r * $out
        cp $src $out/depthai-device-fwp.tar.xz
      '';
      sourceRoot = ".";
    };

    # https://github.com/luxonis/XLink
    xlink = pkgs.stdenv.mkDerivation {
      name = "XLink";
      src = pkgs.fetchFromGitHub {
        owner = "luxonis";
        repo = "xlink";
        # rev = "d209b7eeb8ac68435df5097e57e1dfd8ea1d0e83";
        # sha256 = "sha256-bDEBlakEoDst4eZTzx/VyADNwh+9NFQF2kOCsi3zUoA=";
        rev = "e9eb1ef38030176ad70cddd3b545d5e6c509f1e1";
        sha256 = "sha256-D0aKNni8LDqlWtllHwS/BQ2BGdB1GN1k9BDgjEgjEYM=";
      };
      cmakeFlags = [
        "-DHUNTER_ENABLED=false"
        "-DXLINK_LIBUSB_SYSTEM=true"
      ];
      nativeBuildInputs = with pkgs; [
        # autoPatchelfHook
        pkg-config
        cmake
      ];
      buildInputs = with pkgs; [
        libusb
      ];

    };

    luxonis-libnop = pkgs.stdenv.mkDerivation {
      name = "libnop";
      src = pkgs.fetchFromGitHub {
        owner = "luxonis";
        repo = "libnop"; # w/ cmake support
        # rev = "ab842f51dc2eb13916dc98417c2186b78320ed10";
        # sha256 = "sha256-d2z/lDI9pe5TR82MxGkR9bBMNXPvzqb9Gsd5jOv6x1A=";
        rev = "70d158961ce0459e32a2b1641cddc627550e5663";
        sha256 = "sha256-w1g+eMLTSZIwf8FgS85STBjulocy9ORsazUXEAOHTfQ=";
      };
      # cmakeFlags = [
      #   "-DHUNTER_ENABLED=false"
      # ];
      nativeBuildInputs = with pkgs; [
        # autoPatchelfHook
        pkg-config
        cmake
      ];

      buildInputs = with pkgs; [
        # cmake
        gtest
      ];
      hardeningDisable = [
        "fortify"
      ];
    };

    luxonis-libarchive = pkgs.stdenv.mkDerivation {
      name = "luxonis-lbarchive"; # fork
      src = pkgs.fetchFromGitHub {
        owner = "luxonis";
        repo = "libarchive";
        rev = "45baa3a3e57104519e1165bcd5ac29c3bd8c9f3a";
        sha256 = "sha256-6KTBpL1ibQAwRdzcan+qPhV5cNPHlxwhPJ+swOwJ92g=";
      };
      cmakeFlags = [
        "-DHUNTER_ENABLED=false"
      ];
      nativeBuildInputs = with pkgs; [
        # autoPatchelfHook
        pkg-config
      ];

      buildInputs = with pkgs; [
        cmake
        zlib
      ];
    };

    fp16 = pkgs.stdenv.mkDerivation {
      name = "FP16";
      src = pkgs.fetchFromGitHub {
        owner = "luxonis";
        repo = "FP16";
        rev = "c911175d2717e562976e606c6e5f799bf40cf94e";
        sha256 = "sha256-4U5WmqqljHYoKdKqtFRBX++vGCv/3weuqPFr4WG7GNM=";
      };
      cmakeFlags = [
        "-DPSIMD_SOURCE_DIR=${psimd}"
        "-DFP16_BUILD_TESTS=false"
        "-DFP16_BUILD_BENCHMARKS=false"
      ];
      nativeBuildInputs = with pkgs; [
        # autoPatchelfHook
        pkg-config
      ];

      buildInputs = with pkgs; [
        cmake
        psimd
      ];
    };

      # This is our package environment
      pkgs = import nixpkgs_unstable {
        config = {
          # allowUnfree = true;
          # we can enable cuda and cudnn here
          # cudaSupport = true;
          # cudnnSupport = true;
        };
        inherit system;
        overlays = [
          (final: prev: {

            fmt = prev.fmt.overrideAttrs( old: {
              version = "7.0.3";
              src = final.fetchFromGitHub {
                owner = "fmtlib";
                repo = "fmt";
                rev = final.fmt.version;
                sha256 = "sha256-Ks3UG3V0Pz6qkKYFhy71ZYlZ9CPijO6GBrfMqX5zAp8=";
              };
            });

            spdlog = pkgs_21.spdlog;
          })
        ];
      };

    in {

      packages."${system}".default = pkgs.gcc11Stdenv.mkDerivation {
        name = "depthai-core";
        src = self;
        preConfigure = ''
          mkdir -p /build/source/build/resources/
          cp ${depthai-bootloader}/depthai-bootloader-fwp.tar.xz /build/source/build/resources/
          cp ${depthai-bootloader-devices}/* /build/source/build/resources/
          '';
        cmakeFlags = [
          # "-DCMAKE_CXX_STANDARD=17"
          "-DCMAKE_INSTALL_PREFIX=$out"
          "-DHUNTER_ENABLED=false"
          "-DDEPTHAI_ENABLE_BACKWARD=false"
          # "-DEPTHAI_DOWNLOADED_SOURCES=/dev/null"
          "-DDEPTHAI_SHARED_LOCAL=${depthai-shared}"
          "-DDEPTHAI_BOOTLOADER_SHARED_LOCAL=${depthai-bootloader-shared}"
          # "-DDEPTHAI_DEVICE_FWP=/build/source/build/resources/depthai-device-fwp-afe8d00c868344c73ee897e26278f80a444b9763.cpp"
          "-DDEPTHAI_DEVICE_FWP=/build/source/build/resources/depthai-device-fwp.tar.xz"
          "-DDEPTHAI_BOOTLOADER_FWP=/build/source/build/resources/depthai-bootloader-fwp.tar.xz"
        ];
        installPhase = ''
          # cmake -S. -Bbuild -D'CMAKE_INSTALL_PREFIX=$out'
          # cmake --build . --target install
          # cmake . install $out #--target depthai-core
          make install || echo "ERROR: Did not finish"
          # install depthai-components
          # mkdir -p $out
          # cp -r * $out
        '';
        buildInputs = with pkgs; [
          # python-env # pull in the python environment
          # poetry
          depthai-shared
          depthai-bootloader
          depthai-bootloader-shared
          depthai-bootloader-devices
          cmake
          pkg-config
          bzip2
          fp16
          # luxonis-libarchive
          new-libarchive
          patched-zlib
          # depthai-core
          # liblzma
          xz
          spdlog
          backward-cpp
          nlohmann_json
          luxonis-libnop
          xlink
          git
          clang
          # fmt
        ];
      };
    };
}
Pandapip1 commented 2 weeks ago

I'm currently working on packaging this for nixpkgs now, using the patches at https://github.com/luxonis/depthai-core/issues/447#issuecomment-1164015416

tmayoff commented 2 weeks ago

If you haven't already gotten everything working this repo has a full flake with it building that I've been using, including the patches and everything

Pandapip1 commented 2 weeks ago

Thanks! If you want, I can also list you as a maintainer, if you'd be willing.

tmayoff commented 1 week ago

I don't mind being added as a maintainer