Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package request: Open3D #115218

Open
rowanG077 opened this issue Mar 6, 2021 · 31 comments
Open

Package request: Open3D #115218

rowanG077 opened this issue Mar 6, 2021 · 31 comments
Labels
0.kind: packaging request Request for a new package to be added

Comments

@rowanG077
Copy link
Member

rowanG077 commented Mar 6, 2021

Project description
Open3D is a modern fully featured 3D processing(Pointclouds, meshes etc) environment. I tried to package it myself but quickly ran into my limited nix knowledge. :(

Metadata

@rowanG077 rowanG077 added the 0.kind: packaging request Request for a new package to be added label Mar 6, 2021
@rowanG077 rowanG077 changed the title Package Open3D Package request: Open3D Mar 6, 2021
@rowanG077
Copy link
Member Author

The entire day I have attempted to package it. I'm stuck on trying to resolve an include for ``. Open3D depends on filament which depends on google test which depends on libcxxabi which apparently depends on libcxx. But that last dependency link goes wrong and I don't know how to fix it.

I have cloned the open3D repo added the nix files and patched some things. It's located here: https://github.com/rowanG077/Open3D/tree/v0.12.0-nix

Any help would be greatly appreciated!

@rowanG077
Copy link
Member Author

I have isolated the libcxxabi include issue to the following expression:

clangStdenv.mkDerivation {
    name = "filament";
    src = fetchFromGitHub {
      owner = "intel-isl";
      repo = "filament";
      rev = "13ad8e25289cb173a4f8e71e85cb4e0d026eacdc";
      sha256 = "1pq7cfws4k8havcb589mw8smwgl3hnkw7ignrmw8n0s2wp2zjgnv";
      fetchSubmodules = true;
    };

    buildInputs = [ python ninja xorg.libXi libGLU cmake libcxx libcxxabi ];
  };

@stale
Copy link

stale bot commented Sep 3, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 3, 2021
@aaronchall
Copy link
Contributor

I hope this will get support in the future. it looks like a pretty exciting new project: http://www.open3d.org/

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 13, 2021
@lapp0
Copy link

lapp0 commented Jan 12, 2022

@rowanG077 this expression works for me. Would you be willing to clean it up so it can be packaged?

(borrows some code from https://github.com/mipmip/nixos/blob/45dea7930eafa18b31424be0e2d850e7a3c7504a/pkgs/open3d/default.nix)

        pkgs = nixpkgs.legacyPackages.${system};
        pkgsUnfree = import nixpkgs {
          inherit system;
          config = { allowUnfree = true; };
        };
        pkgsUnfreeNoCheck = import nixpkgs {
          inherit system;
          config = { allowUnfree = true; doCheck = false; };
        };
        python = pkgs.python39;
        pythonPackages = python.pkgs;

        pytorch-cuda = pkgsUnfreeNoCheck.python39Packages.pytorch.override {
          cudaSupport = true;
        };
        libtorch-cuda = pkgs.libtorch-bin.override { cudaSupport = true; };

        open3d = pythonPackages.buildPythonPackage rec {
          pname = "open3d";
          version = "0.14.1";
          format = "wheel";

          src = pythonPackages.fetchPypi {
            inherit pname version format;
            dist = "cp39";
            python = "cp39";
            abi = "cp39";
            platform = "manylinux_2_27_x86_64";
            sha256 = "sha256-rgk+O4FDXIIQbCs5zpXR5lV8x7cCekiQfaoD/83JwCA=";
          };

          patchPhase = ''
            ${pkgs.unzip}/bin/unzip ./dist/open3d-0.14.1-cp39-cp39-manylinux_2_27_x86_64.whl -d tmp
            rm ./dist/open3d-0.14.1-cp39-cp39-manylinux_2_27_x86_64.whl
            sed -i 's/sklearn/scikit-learn/g' tmp/open3d-0.14.1.dist-info/METADATA
            cd tmp
            ${pkgs.zip}/bin/zip -0 -r ../dist/open3d-0.14.1-cp39-cp39-manylinux_2_27_x86_64.whl ./*
            cd ../
          '';

          nativeBuildInputs = [
            pkgs.autoPatchelfHook
          ];

          buildInputs = with pkgs; [
            stdenv.cc.cc.lib
            libusb.out
            pytorch-cuda
            libtensorflow-bin
            pkgsUnfree.cudaPackages.cudatoolkit_11.lib
            libtorch-cuda
            libGL
          ];

          propagatedBuildInputs = with pythonPackages; [
            jupyterlab
            jupyter-packaging
            ipywidgets
            tqdm
            pyyaml
            pandas
            plyfile
            scipy
            scikitlearn
            numpy
            addict
            matplotlib
          ];
        };

@rowanG077
Copy link
Member Author

@lapp0 Fun fact that linked expression was written by me a while back :), see here: https://gist.github.com/rowanG077/7f46a0807c108fe4b582067f237ae867. Just didn't care to upstream it. The reason for it is because it uses the precompiled wheels. Which I don't really like.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 1, 2022
@breakds
Copy link
Contributor

breakds commented Dec 14, 2022

@rowanG077 Are you still working on packaging open3d? I found that I am in need of packaging it as well. Ideally I think it should be built from source with one c++ library and one python library. But packing the wheel can also work for now.

May I ask what is your current solution to this? I am willing to join the effort if you are still on it. Thanks!

@breakds
Copy link
Contributor

breakds commented Dec 14, 2022

Not stale.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 14, 2022
@rowanG077
Copy link
Member Author

@breakds I'm still interested. But going to "correct" path will take a lot of time I don't have right now. My current solution is that I have packaged the wheel locally.

@breakds
Copy link
Contributor

breakds commented Dec 14, 2022

@rowanG077 Thank you! Do you have an updated wheel solution, or is the 0.12 gist the most up to date?

Meanwhile I'll make an attempt to package it from the source, but since I am less experienced, I might put problems / questioins here.

@rowanG077
Copy link
Member Author

@breakds yes 0.12 is the most uptodate.

@pfmephisto
Copy link

pfmephisto commented May 2, 2023

I am trying to get Open3D to work with python3.10 and I have gotten this far.

I seem to have trouble with the libraries that I mention under autoPatchelfIgnoreMissingDeps
If I include mesa as a dependency most of them are found but at run time I get an error that it can not find the swrast driver, which seems to me that it is not using the GPU but trying to rely on a fallback solution.
If I leave mesa out my issue now becomes that libglapi can not be found. So I have the impression that actually something with libGL is off, but I'm not sure what.

Which ever way I keep tying things something always does not seem to work properly.

Did anyone manage to get it to work or has any suggestions.

{ config, pkgs, lib, fetchPypi, fetchurl, ... }:
let
  unstable = import <nixos-unstable> {
    config.allowUnfree = true;
    config.cudaSupport = true;
  };


  my_python = unstable.pkgs.python3.override {
    packageOverrides = self: super: {

      nbformat = super.buildPythonPackage rec {

        pname = "nbformat";
        version = "5.7.0";
        format = "wheel";
        src = pkgs.fetchurl {
          url = "https://files.pythonhosted.org/packages/5c/9f/957655d02f43b8bff77e6da08c94472b1229c13e7455bbd662163c9b78c0/nbformat-5.7.0-py3-none-any.whl";
          sha256 = "sha256-GwXsLFUsLxrcdF9O3c4erIyp/9Wbuf2FnoJ+qgMTGfk=";
        };

        buildInputs = with super; [
          fastjsonschema
          jupyter_core
          jsonschema
        ];

        propagatedBuildInputs = with super; [
          fastjsonschema
          jsonschema
        ];

      };
    };
  };


  ml_python_packages = ps: with ps; [
    pip
    ipykernel
    torch-bin
    tensorflowWithoutCuda
    gpustat
    plotly
    scipy
    numpy
    dash
    werkzeug
    nbformat
    configargparse
    ipywidgets
    addict
    pillow
    matplotlib
    pandas
    pyyaml
    scikit-learn
    tqdm
    pyquaternion
    (
      buildPythonPackage rec {
        pname = "open3d";
        version = "0.17.0";
        format = "wheel";

        src = unstable.python3Packages.fetchPypi {
          inherit pname version format;
          sha256 = "sha256-PcMAaXMgu2iCRsXQn2gQRYFcMyIlaFc/GWSy11ZDFlc=";
          dist = "cp310";
          python = "cp310";
          abi = "cp310";
          platform = "manylinux_2_27_x86_64";
        };


        nativeBuildInputs = [
          unstable.autoPatchelfHook
        ];

        autoPatchelfIgnoreMissingDeps = [
          "libLLVM-10.so.1"
          #"libglapi.so.0"
          #"libdrm.so.2"
          #"libexpat.so.1"
          #"libXfixes.so.3"
          #"libXxf86vm.so.1"
        ];

        buildInputs = with unstable; [
          mesa
          zstd
          stdenv.cc.cc.lib
          libusb.out
          glibc
          libGL
          cudaPackages.cudatoolkit
          pkgs.libtorch-bin
          libtensorflow

        ];

        propagatedBuildInputs =  with unstable; [
          (my_python.withPackages(
            ps: with ps; [
              numpy
              dash
              werkzeug
              nbformat
              configargparse
              ipywidgets
              addict
              pillow
              matplotlib
              pandas
              pyyaml
              scikit-learn
              tqdm
              pyquaternion
              #pywinpty
          ]))
        ];


      })

    ];

in
  {

    nixpkgs.config = {
      allowUnfree = true;
      cudaSupport = true;
    };


    # List packages installed in system profile. To search, run:
    environment.systemPackages = with unstable.pkgs; [
      cudaPackages.cudatoolkit
          cudaPackages.cudnn
          conda
          wget
          nvtop
          ctop
          (my_python.withPackages ml_python_packages)
    ];


}


@rowanG077
Copy link
Member Author

libLLVM-10.so.1 can be fixed by symlinking:

postInstall = ''
    ln -s "${llvm_10.lib}/lib/libLLVM-10.so" "$out/lib/libLLVM-10.so.1"
''

It's an ubuntu-ism. Adding xorg.libXfixes, xorg.libXxf86vm, expat and libdrm fixes some more dependencies you marked.

Regarding libglapi I had the same problem while upgrading.

@pfmephisto
Copy link

@rowanG077 Thanks,

yah that brings me down to libglapi.so.0 libdrm.so.2 libexpat.so.1 libXfixes.so.3 and libXxf86vm.so.1 missing.

Those in turn seem to be dependencies of kms_swrast_dri.so libEGL.so.1 libgallium_dri.so libGL.so.1 and swrast_dri.so

Could it be that there are some libGL libraries that also simply just need to be remapped?

Is there a way to explore what is inside a package e.g. start a nix-shell and then explore the directories it adds?
Then I could try to have a look and see what I find.

@rowanG077
Copy link
Member Author

rowanG077 commented May 2, 2023

@pfmephisto

Yeah, honestly opengl/opencl/nvidia/cuda etc are all a mess in nix. I don't know how it all fits together.

You can use this command to get the nix store path of a package (mesa used here an example):

nix --extra-experimental-features nix-command --extra-experimental-features flakes eval -f '<nixpkgs>' --raw 'mesa'

You can look around in that folder to see what certain package bring into scope.

@ShaddyDC
Copy link
Contributor

ShaddyDC commented Jun 6, 2023

Hi, did any of you make any progress packaging the latest version?

@rowanG077
Copy link
Member Author

rowanG077 commented Jun 6, 2023

Tagging @pfmephisto, you are probably interested :).

Yes. I have something working. I have found no way to get pytorch to output the split cuda libraries. I tried various things but building it takes ages so I stopped trying since I didn't really need t anyway. See the pytorchSplitCuda which is unused.

{ stdenv, lib, buildPythonPackage, fetchPypi, addict
, numpy, matplotlib, ipywidgets, pandas, pyyaml, tqdm
, autoPatchelfHook, llvm_10, xorg, libtorch-bin, libtensorflow, libusb
, cudaPackages, libGL, nbformat, dash, configargparse, pyquaternion, scikit-learn
, expat, pytorchWithCuda }:

let
  nbformat-570 = nbformat.overridePythonAttrs (old: rec {
    version = "5.7.0";

    JUPYTER_PLATFORM_DIRS=1;
    src = fetchPypi {
      inherit version;
      pname = old.pname;
      hash = "sha256-HUdgwVwaBCae9crzdb6LmN0vaW5eueYD7Cvwkfmw0/M=";
    };
  });

  pytorchSplitCuda = pytorchWithCuda.overridePythonAttrs (old: rec {
    preConfigure = old.preConfigure + ''
      export BUILD_SPLIT_CUDA=1
    '';
  });
in buildPythonPackage rec {
    pname = "open3d";
    version = "0.17.0";
    format = "wheel";

    src = fetchPypi {
      inherit pname version format;
      sha256 = "sha256-PcMAaXMgu2iCRsXQn2gQRYFcMyIlaFc/GWSy11ZDFlc=";
      dist = "cp310";
      python = "cp310";
      abi = "cp310";
      platform = "manylinux_2_27_x86_64";
    };

  nativeBuildInputs = [
    autoPatchelfHook
  ];

  autoPatchelfIgnoreMissingDeps = [
    "libtorch_cuda_cpp.so"
    "libtorch_cuda_cu.so"
  ];

  # Fix llvm library name to match Ubuntu name
  # Remove libraries that actually should be provided by environment
  postInstall = ''
    ln -s "${llvm_10.lib}/lib/libLLVM-10.so" "$out/lib/libLLVM-10.so.1"

    rm $out/lib/python3.10/site-packages/open3d/libGL.so.1
    rm $out/lib/python3.10/site-packages/open3d/swrast_dri.so
    rm $out/lib/python3.10/site-packages/open3d/libgallium_dri.so
    rm $out/lib/python3.10/site-packages/open3d/kms_swrast_dri.so
    rm $out/lib/python3.10/site-packages/open3d/libEGL.so.1
  '';

  buildInputs = [
    stdenv.cc.cc.lib
    libusb.out
    libGL
    cudaPackages.cudatoolkit
    libtorch-bin
    libtensorflow
    expat
    xorg.libXfixes
    nbformat
  ];

  propagatedBuildInputs = [
    # py deps
    numpy
    dash
    configargparse
    scikit-learn
    ipywidgets
    addict
    matplotlib
    pandas
    pyyaml
    tqdm
    pyquaternion
    pytorchWithCuda
  ];
}

@pfmephisto
Copy link

I ended up switching to Ubuntu (I know 😅), but I need something that worked and did not have more time to debug the derivation.

@OladapoAjala
Copy link

OladapoAjala commented Jul 13, 2023

#115218 (comment)

@rowanG077 is this package available in a git repo on your profile?

Could you also help with pointers to convert your code to a flake version?

@breakds
Copy link
Contributor

breakds commented Jul 13, 2023

@OladapoAjala
Copy link

Screenshot from 2023-07-14 11-37-09

Thanks @breakds , ooks like Open3d is currently unavailable from the ml-pkgs. Can you confirm that the current open3d you have works or it still needs some fine tuning? @breakds

@breakds
Copy link
Contributor

breakds commented Jul 14, 2023

Screenshot from 2023-07-14 11-37-09

Thanks @breakds , ooks like Open3d is currently unavailable from the ml-pkgs. Can you confirm that the current open3d you have works or it still needs some fine tuning? @breakds

Right, sorry that I left it broken. It should be fixed now in the main branch. However, like @rowanG077 has mentioned there are still some dependencies for patchelf not being found. I tested it just by loading a .pcd file which works.

@spagnoloG
Copy link

Hello I have a similar problem now. On nixos 23.05 flake that @rowanG077 provided worked. But once i updated to nixos 23.11 I get segmentaiton fault on my system. (it worked before update)

Here is my flake.nix:

{
  description = "Obss python development environment";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils, ... }@inputs:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          config = { allowUnfree = true; };
        };

        fetchPypi = pkgs.python3Packages.fetchPypi;

        customPython = pkgs.python3.override {
          packageOverrides = self: super: {
            opencv4 = super.opencv4.override {
              enableGtk2 = true;
              gtk2 = pkgs.gtk2;
              enableFfmpeg = true;
            };
          };
        };

        nbformat-570 = pkgs.python3Packages.nbformat.overridePythonAttrs
          (old: rec {
            version = "5.7.0";

            JUPYTER_PLATFORM_DIRS = 1;
            src = fetchPypi {
              inherit version;
              pname = old.pname;
              hash = "sha256-HUdgwVwaBCae9crzdb6LmN0vaW5eueYD7Cvwkfmw0/M=";
            };
          });

        # Define a custom Python packages set with the nbformat override, version collision!
        customPythonPackages = pkgs.python3Packages.override {
          overrides = self: super: { nbformat = nbformat-570; };
        };

        open3d = pkgs.python3Packages.buildPythonPackage rec {
          pname = "open3d";
          version = "0.17.0";
          format = "wheel";

          src = pkgs.python3Packages.fetchPypi {
            pname = "open3d";
            version = "0.17.0";
            format = "wheel";
            sha256 = "sha256-PcMAaXMgu2iCRsXQn2gQRYFcMyIlaFc/GWSy11ZDFlc=";
            dist = "cp310";
            python = "cp310";
            abi = "cp310";
            platform = "manylinux_2_27_x86_64";
          };

          nativeBuildInputs = [ pkgs.autoPatchelfHook ];
          autoPatchelfIgnoreMissingDeps = [
            "libtorch_cuda_cpp.so"
            "libtorch_cuda_cu.so"
            "libtorch_cuda.so"
            "libc10_cuda.so"
          ];

          buildInputs = with pkgs; [
            cudaPackages.cudatoolkit
            stdenv.cc.cc.lib
            libusb.out
            libGL
            cudaPackages.cudatoolkit
            libtorch-bin
            libtensorflow
            expat
            xorg.libXfixes
            mesa
            xorg.libX11
            xorg.libXfixes
          ];

          propagatedBuildInputs = with customPythonPackages; [
            nbformat-570
            numpy
            dash
            configargparse
            scikit-learn
            ipywidgets
            addict
            matplotlib
            pandas
            pyyaml
            tqdm
            pyquaternion
          ];

          postInstall = ''
            ln -s "${pkgs.llvm_10.lib}/lib/libLLVM-10.so" "$out/lib/libLLVM-10.so.1"

            rm $out/lib/python3.10/site-packages/open3d/libGL.so.1
            rm $out/lib/python3.10/site-packages/open3d/swrast_dri.so
            rm $out/lib/python3.10/site-packages/open3d/libgallium_dri.so
            rm $out/lib/python3.10/site-packages/open3d/kms_swrast_dri.so
            rm $out/lib/python3.10/site-packages/open3d/libEGL.so.1
          '';

        };

        pythonEnv = customPython.withPackages (ps:
          with ps; [
            matplotlib
            numpy
            scipy
            requests
            opencv4
            flake8
            black
            open3d
          ]);

      in {
        devShell = pkgs.mkShell {
          buildInputs =
            [ pythonEnv pkgs.python3Packages.pip pkgs.gtk2 pkgs.ffmpeg ];

          shellHook = ''
            if [ ! -d ./.venv ]; then
              python3 -m venv .venv
            fi
            source .venv/bin/activate
            pip install pre-commit
            pre-commit autoupdate
            echo "Welcome to the Python development environment."
          '';
        };
      });
}
Finished processing files...
Segmentation fault (core dumped)

If I update the nixpkgs.url to 23.11 I get the following error:

error: builder for '/nix/store/crqckibld9wkq7lfmvqz7gykd1aqwxfb-python3.11-nbformat-5.7.0.drv' failed with exit code 2;
       last 10 log lines:
       > ERROR tests/v4/nbexamples.py - DeprecationWarning: Importing ErrorTree directly from the jsonschema packag...
       > ERROR tests/v4/test_convert.py - DeprecationWarning: Importing ErrorTree directly from the jsonschema packag...
       > ERROR tests/v4/test_convert.py - DeprecationWarning: Importing ErrorTree directly from the jsonschema packag...
       > ERROR tests/v4/test_json.py - DeprecationWarning: Importing ErrorTree directly from the jsonschema packag...
       > ERROR tests/v4/test_json.py - DeprecationWarning: Importing ErrorTree directly from the jsonschema packag...
       > ERROR tests/v4/test_validate.py - DeprecationWarning: Importing ErrorTree directly from the jsonschema packag...
       > ERROR tests/v4/test_validate.py - DeprecationWarning: Importing ErrorTree directly from the jsonschema packag...
       > !!!!!!!!!!!!!!!!!!! Interrupted: 20 errors during collection !!!!!!!!!!!!!!!!!!!
       > ============================== 20 errors in 3.65s ==============================
       > /nix/store/wr08yanv2bjrphhi5aai12hf2qz5kvic-stdenv-linux/setup: line 1559: pop_var_context: head of shell_variables not a function context
       For full logs, run 'nix log /nix/store/crqckibld9wkq7lfmvqz7gykd1aqwxfb-python3.11-nbformat-5.7.0.drv'.

I am a nixos newbie and would gladly accept any suggestions how to make it work. Thanks in advance :)

@spagnoloG
Copy link

Finally made it work :) 🥳 🥳 on nixos 23.11 and open3d version 0.18. Here is flake.nix if anyone is also struggling to make it work :)

{
  description = "Opend3d developmen environment";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils, ... }@inputs:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          config = { allowUnfree = true; };
        };

        fetchPypi = pkgs.python311Packages.fetchPypi;

        customPython = pkgs.python311.override {
          packageOverrides = self: super: {
            opencv4 = super.opencv4.override {
              enableGtk2 = true;
              gtk2 = pkgs.gtk2;
              enableFfmpeg = true;
            };
          };
        };

        open3d = pkgs.python311Packages.buildPythonPackage rec {
          pname = "open3d";
          version = "0.18.0";
          format = "wheel";

          src = pkgs.python311Packages.fetchPypi {
            pname = "open3d";
            version = "0.18.0";
            format = "wheel";
            sha256 = "sha256-jj0dGQCo9NlW9oGcJGx4CBclubCIj4VJ0qeknI2qEwM=";
            dist = "cp311";
            python = "cp311";
            abi = "cp311";
            platform = "manylinux_2_27_x86_64";
          };

          nativeBuildInputs = [ pkgs.autoPatchelfHook ];
          autoPatchelfIgnoreMissingDeps = [
            "libtorch_cuda_cpp.so"
            "libtorch_cuda_cu.so"
            "libtorch_cuda.so"
            "libc10_cuda.so"
          ];

          buildInputs = with pkgs; [
            cudaPackages.cudatoolkit
            stdenv.cc.cc.lib
            libusb.out
            libGL
            cudaPackages.cudatoolkit
            libtorch-bin
            libtensorflow
            expat
            xorg.libXfixes
            mesa
            xorg.libX11
            xorg.libXfixes
          ];

          propagatedBuildInputs = with pkgs.python311Packages; [
            nbformat
            numpy
            dash
            configargparse
            scikit-learn
            ipywidgets
            addict
            matplotlib
            pandas
            pyyaml
            tqdm
            pyquaternion
          ];

          postInstall = ''
            ln -s "${pkgs.llvm_10.lib}/lib/libLLVM-10.so" "$out/lib/libLLVM-10.so.1"

            rm $out/lib/python3.11/site-packages/open3d/libGL.so.1
            rm $out/lib/python3.11/site-packages/open3d/swrast_dri.so
            rm $out/lib/python3.11/site-packages/open3d/libgallium_dri.so
            rm $out/lib/python3.11/site-packages/open3d/kms_swrast_dri.so
            rm $out/lib/python3.11/site-packages/open3d/libEGL.so.1
          '';

        };

        pythonEnv = customPython.withPackages (ps:
          with ps; [
            matplotlib
            numpy
            scipy
            requests
            opencv4
            flake8
            black
            open3d
          ]);

      in {
        devShell = pkgs.mkShell {
          buildInputs =
            [ pythonEnv pkgs.python311Packages.pip pkgs.gtk2 pkgs.ffmpeg ];

          shellHook = ''
            echo "Welcome to the Python development environment."
          '';
        };
      });
}

@purepani
Copy link
Contributor

This currently doesn't work on unstable due to #283954 removing it.
Is there a way to get this built on unstable, or will upstream need to be patched for that to be possible?

@martiege
Copy link

Have anyone tried to get the C++ version of open3d to work? It is virtually impossible to build it from source, as open3d loves to download different third party dependencies over the internet through cmake, so I have this messy derivation:

{ stdenv
, cmake
, ninja
, autoPatchelfHook
, xorg
, assimp
, curl
, curlpp
, eigen
, embree
, fmt
, glew
, glfw
, gtest
, imgui
, libjpeg
, jsoncpp
, msgpack
, nanoflann
, openssl
, boringssl
, libpng
, qhull
, tbb
, tinyobjloader
, vtk
, zeromq
, libcxx
, libGL
, mesa
, libusb
, libtensorflow
, binutils
, libudev-zero
, libudev0-shim
, udev
, systemd
# , pytorchWithCuda
# , libtensorflow-bin
# , cudaPackages
, lib
}:
stdenv.mkDerivation rec {
  pname = "Open3D";
  version = "0.18.0";

  src = builtins.fetchTarball {
    url = "https://github.com/isl-org/Open3D/releases/download/v${version}/open3d-devel-linux-x86_64-cxx11-abi-${version}.tar.xz";
    sha256 = "sha256:0da7xw7gvc458s6jgsflkdkh54fj4gq5qxy1s0b8ls37hi80g5fy";
    # sha256 = lib.fakeHash;
  };

  installPhase = ''
    runHook preInstall
    mkdir -p $out
    cp -r $src/* $out
    runHook postInstall
  '';

  preFixup = let
    # we prepare our library path in the let clause to avoid it become part of the input of mkDerivation
    libPath = lib.makeLibraryPath [
      stdenv.cc.cc.lib  # libstdc++.so.6
      libudev-zero
      libudev0-shim
      udev
      systemd
      xorg.libX11
      libcxx
      libGL
    ];
    # --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
  in ''
    patchelf \
      --set-rpath "${libPath}" \
      --add-needed libudev.so \
      --add-needed libudev.so.1 \
      $out/lib/libOpen3D.so
  '';

  nativeBuildInputs = [
    autoPatchelfHook
  ];


  buildInputs = [
    xorg.libX11
    xorg.libXrandr
    xorg.libXinerama
    xorg.libXcursor

    assimp
    curl
    curlpp
    eigen
    embree
    fmt
    glew
    glfw
    gtest
    imgui
    libjpeg
    jsoncpp
    msgpack
    nanoflann
    openssl
    boringssl
    libpng
    qhull
    tbb
    tinyobjloader
    vtk
    zeromq

    libcxx
    libGL
    mesa

    stdenv.cc.cc.lib
    libusb.out
    libtensorflow
    binutils
      libudev-zero
      libudev0-shim
      udev
      systemd
    # pytorchWithCuda
    # libtensorflow-bin
    # cudaPackages.cudatoolkit_10_1.lib
  ];
}

This builds fine, but I get "undefined reference" errors regarding a bunch of libudev functions when I try to use this in my own C+++ project...

@nim65s
Copy link
Contributor

nim65s commented Sep 26, 2024

I have a wip from source.

As you mention, this is a nightmare, so clearly not finished yet :(

But I can be very stubborn on this topic, and I need this package by the end of the month, so I might open a PR next week :)

@martiege
Copy link

@nim65s it would be amazing if you got this working! Could you share your current wip, perhaps I could try to help out?

@rowanG077
Copy link
Member Author

Yeah I once tried to build it from source and spend a day chasing dependencies and gave up... There is an upstream PR for a nix setup: isl-org/Open3D#6854

@nim65s
Copy link
Contributor

nim65s commented Sep 26, 2024

my wip is clearly too early to be useful: https://github.com/nim65s/nixpkgs/tree/open3d
edit: actually, this seems more advanced: https://github.com/nim65s/nur-packages/blob/master/pkgs/open3d/default.nix

@martiege
Copy link

@rowanG077 Oooh, I saw that PR some time ago, but didn't follow to his nix derivation. I've slightly modified his derivation to build a C++ library instead, and that seems actually to work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: packaging request Request for a new package to be added
Projects
None yet
Development

No branches or pull requests