New to NixOS - help installing Open3D

Hi,

I am trying to install open3d on my system and I am running in to different challenges. I am new to Nix/NixOS and am learning as I go. Online I found a gist that I took as inspiration, but that one is installing a prior version of open3D, so I have been adapting it.

As far as I can tell from my log, my issues are with the build of nccl-2.12.10-1-cuda-11.7 failing if I include tensorflow as a build buildInput.
And If I leave tensorflow out, then then the autoPatchlfHook failes to find the following binaries.

libglapi.so.0 -> kms_swrast_dri.so
libdrm.so.2 -> kms_swrast_dri.so
libLLVM-10.so.1 -> kms_swrast_dri.so
libzstd.so.1 -> kms_swrast_dri.so

libglapi.so.0 -> libEGL.so.1
libdrm.so.2 -> libEGL.so.1

libglapi.so.0 -> libgallium_dri.so
libdrm.so.2 -> libgallium_dri.so
libLLVM-10.so.1 -> libgallium_dri.so
libzstd.so.1 -> libgallium_dri.so

libglapi.so.0 -> libGL.so.1
libdrm.so.2 -> libGL.so.1
libXxf86vm.so.1 -> libGL.so.1

libglapi.so.0 -> swrast_dri.so
libdrm.so.2 -> swrast_dri.so
libLLVM-10.so.1 -> swrast_dri.so
libzstd.so.1 -> swrast_dri.so

I am on system.stateVersion = "22.11";
and here is what I believe is relevant form my config file.

The unstable channel I am referencing is unstable https://nixos.org/channels/nixpkgs-unstable

If you have any pointers as to what I could try or see what I am doing wrong, I’d be happy for any hint.

{ 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
          jupyter_core
          jsonschema
        ];
    };
  };
};
in
{
  nixpkgs.config = {
    allowUnfree = true;
    cudaSupport = true;
  };


  # List packages installed in system profile. To search, run:
  environment.systemPackages = with pkgs; [
    linuxPackages.nvidia_x11
    cudaPackages.cudatoolkit
    cudaPackages.cudnn
    conda

    (my_python.withPackages( ps: with ps; [
      pip
      numpy
      torch-bin
      matplotlib
      pandas
      ipywidgets
#    tensorflow
#    tensorflowWithCuda

      (
        buildPythonPackage rec {
          pname = "open3d";
          version = "0.17.0";
          format = "pyproject";
          src = unstable.fetchurl {
            url ="https://github.com/isl-org/Open3D/releases/download/v0.16.0/open3d-devel-linux-x86_64-cxx11-abi-cuda-0.16.0.tar.xz";
            sha256 = "sha256-0HnwgZPfeDNy+0bKL/pT1u9q4413Jeht48MUyHQMAxA=";
          };

          nativeBuildInputs = [
            autoPatchelfHook
          ];
        }
      )

  (
    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";
  };

#  patchPhase = ''
#  ${unzip}/bin/unzip ./dist/open3d-0.17.0-cp310-cp310-manylinux_2_27_x86_64.whl -d tmp
#  rm ./dist/open3d-0.17.0-cp310-cp310-manylinux_2_27_x86_64.whl
#  sed -i 's/sklearn/scikit-learn/g' tmp/open3d-0.17.0.dist-info/METADATA
#  cd tmp
#  ${zip}/bin/zip -0 -r ../dist/open3d-0.17.0-cp310-cp310-manylinux_2_27_x86_64.whl ./*
#  cd ../
#  ';
    nativeBuildInputs = [
     autoPatchelfHook
    ];

  buildInputs = with pkgs; [
    # so deps
    stdenv.cc.cc.lib
    libusb.out

    cudaPackages.cudatoolkit

    libtorch-bin
    libGL

    (my_python.withPackages( ps: with ps; [
      torch-bin
      tensorboard
      tensorflow-bin
    ]))

   ];

   propagatedBuildInputs =  [


    # py deps
    (my_python.withPackages(
     ps: with ps; [
       dash
       configargparse
       pyquaternion

       ipywidgets
       tqdm
       pyyaml
       pandas
       plyfile
       scipy
       scikitlearn
       numpy
       addict
       matplotlib
       tensorboard
       nbformat

      ]))
     ];
    })
  ]))
 ];
}

I thought it might be helpful if I add the build log with the errors.

The first one is with tensorflow included, and to me it seems that there is an issue with CUDA support.
Although CUDA seems to work just fine for me in pyTorch.

include/debug.h:34:77: note: in definition of macro 'WARN'
   34 | #define WARN(...) ncclDebugLog(NCCL_LOG_WARN, NCCL_ALL, __FILE__, __LINE__, __VA_ARGS__)
      |                                                                             ^~~~~~~~~~~
include/alloc.h:158:3: note: in expansion of macro 'CUDACHECK'
  158 |   CUDACHECK(cudaThreadExchangeStreamCaptureMode(&mode));
      |   ^~~~~~~~~
include/checks.h:24:53: error: 'cudaGetErrorString' was not declared in this scope; did you mean 'cuGetErrorString'?
   24 |         WARN("Cuda failure '%s'", cudaGetErrorString(err)); \
      |                                   ~~~~~~~~~~~~~~~~~~^~~~~
include/debug.h:34:77: note: in definition of macro 'WARN'
   34 | #define WARN(...) ncclDebugLog(NCCL_LOG_WARN, NCCL_ALL, __FILE__, __LINE__, __VA_ARGS__)
      |                                                                             ^~~~~~~~~~~
include/alloc.h:159:3: note: in expansion of macro 'CUDACHECKGOTO'
  159 |   CUDACHECKGOTO(cudaFree(ptr), result, finish);
      |   ^~~~~~~~~~~~~
include/checks.h:16:53: error: 'cudaGetErrorString' was not declared in this scope; did you mean 'cuGetErrorString'?
   16 |         WARN("Cuda failure '%s'", cudaGetErrorString(err)); \
      |                                   ~~~~~~~~~~~~~~~~~~^~~~~
include/debug.h:34:77: note: in definition of macro 'WARN'
   34 | #define WARN(...) ncclDebugLog(NCCL_LOG_WARN, NCCL_ALL, __FILE__, __LINE__, __VA_ARGS__)
      |                                                                             ^~~~~~~~~~~
include/alloc.h:161:3: note: in expansion of macro 'CUDACHECK'
  161 |   CUDACHECK(cudaThreadExchangeStreamCaptureMode(&mode));
      |   ^~~~~~~~~
make[1]: *** [Makefile:120: /build/source/build/obj/enqueue.o] Error 1
make[1]: Leaving directory '/build/source/src'
make: *** [Makefile:25: src.build] Error 2
error: builder for '/nix/store/9yqjl3wqd5n92y1zjsahcsj0bl4aspyg-nccl-2.16.5-1-cuda-11.drv' failed with exit code 2
error: 1 dependencies of derivation '/nix/store/mrg93381myi59y29br39hcs464kl2p6l-bazel-build-jaxlib-0.3.22-deps.tar.gz.drv' failed to build
error: 2 dependencies of derivation '/nix/store/6zsszdn1cciv334l6h00jffv628sqhx5-bazel-build-jaxlib-0.3.22.drv' failed to build
error: 2 dependencies of derivation '/nix/store/247xv7haia8v59s2fgs1q1mgp968b75w-python3.10-jaxlib-0.3.22.drv' failed to build
error: 1 dependencies of derivation '/nix/store/6kjnzjavz88z5zypks6d0lgxm8k0dahx-python3.10-jax-0.4.1.drv' failed to build
error: 1 dependencies of derivation '/nix/store/g1jvj6l6rhqlqfxaz8lcasbcfxca94n3-python3.10-tensorflow-gpu-2.12.0.drv' failed to build
error: 2 dependencies of derivation '/nix/store/4mr03lgbic446yc72zj1ma57x1n1l115-python3-3.10.10-env.drv' failed to build
error: 1 dependencies of derivation '/nix/store/mpmqvjcd8ljxf2n9kdhgn6yqp4wcrkb4-python3.10-open3d-0.17.0.drv' failed to build
error: 2 dependencies of derivation '/nix/store/g6lcb7jql4ypaig67fy087bpgympgy5j-python3-3.10.10-env.drv' failed to build
error: 1 dependencies of derivation '/nix/store/78amws50vanwf7kvvjdin1gr65cla2g9-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/sdqb88ps8w8f4rfrm157aj2vj05n5i22-dbus-1.drv' failed to build
error: 1 dependencies of derivation '/nix/store/z5wacjp4n4177ikbanaw69g7fqcygpp9-unit-accounts-daemon.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/1kmmpzcry1rmsldd0kyr67raw3176lqj-unit-polkit.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/sycza7vzgx31iy8v2hx83ycg78ywxb3z-unit-systemd-fsck-.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/473xnva59n14yb179qj7cv84npifwglq-unit-dbus.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ia31zpka3yc6s9ga6cmk189ibmd3p8y7-unit-dbus.service.drv' failed to build
error: 4 dependencies of derivation '/nix/store/vjb13w6050pd5zbaxp833b55b5643nkk-system-units.drv' failed to build
error: 1 dependencies of derivation '/nix/store/cymlqx76wp3qwfp5yanzrs41sg7f58p7-user-units.drv' failed to build
error: 4 dependencies of derivation '/nix/store/4pb4icy0vznmpv4qbjcaincas97xvknx-etc.drv' failed to build
error: 2 dependencies of derivation '/nix/store/pkckqm1lfhlk859mbviaa6j1mk32y9jr-nixos-system-nixos-22.11.3781.cd749f58ba8.drv' failed to build

The second one. Here I omitted tensorflow and now I seem to be missing some binaries that look as though they relate to openGL

setting RPATH to: /nix/store/zqix2nszqij97ldlryzw7qypx43fp5kv-libtorch-1.12.1/lib:/nix/store/6plx60y4x4q2lfp6n7190kaihyxr7m1w-gcc-11.3.0-lib/lib
searching for dependencies of /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/cpu/pybind.cpython-310-x86_64-linux-gnu.so
    libudev.so.1 -> found: /nix/store/x53598nbd84lz90f10zdw8w6g2a98qw6-systemd-minimal-251.15/lib
    libgomp.so.1 -> found: /nix/store/6plx60y4x4q2lfp6n7190kaihyxr7m1w-gcc-11.3.0-lib/lib
    libX11.so.6 -> found: /nix/store/33qdhi8l6f4ixqzdc387w9gwdxrdsara-libX11-1.8.4/lib
    libstdc++.so.6 -> found: /nix/store/6plx60y4x4q2lfp6n7190kaihyxr7m1w-gcc-11.3.0-lib/lib
    libc++.so.1 -> found: /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d
    libGL.so.1 -> found: /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d
    libgcc_s.so.1 -> found: /nix/store/6plx60y4x4q2lfp6n7190kaihyxr7m1w-gcc-11.3.0-lib/lib
setting RPATH to: /nix/store/x53598nbd84lz90f10zdw8w6g2a98qw6-systemd-minimal-251.15/lib:/nix/store/6plx60y4x4q2lfp6n7190kaihyxr7m1w-gcc-11.3.0-lib/lib:/nix/store/33qdhi8l6f4ixqzdc387w9gwdxrdsara-libX11-1.8.4/lib:/nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d
auto-patchelf: 19 dependencies could not be satisfied
error: auto-patchelf could not satisfy dependency libglapi.so.0 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/kms_swrast_dri.so
error: auto-patchelf could not satisfy dependency libdrm.so.2 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/kms_swrast_dri.so
error: auto-patchelf could not satisfy dependency libLLVM-10.so.1 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/kms_swrast_dri.so
error: auto-patchelf could not satisfy dependency libzstd.so.1 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/kms_swrast_dri.so
error: auto-patchelf could not satisfy dependency libglapi.so.0 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/libEGL.so.1
error: auto-patchelf could not satisfy dependency libdrm.so.2 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/libEGL.so.1
error: auto-patchelf could not satisfy dependency libglapi.so.0 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/libgallium_dri.so
error: auto-patchelf could not satisfy dependency libdrm.so.2 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/libgallium_dri.so
error: auto-patchelf could not satisfy dependency libLLVM-10.so.1 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/libgallium_dri.so
error: auto-patchelf could not satisfy dependency libzstd.so.1 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/libgallium_dri.so
error: auto-patchelf could not satisfy dependency libglapi.so.0 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/libGL.so.1
error: auto-patchelf could not satisfy dependency libdrm.so.2 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/libGL.so.1
error: auto-patchelf could not satisfy dependency libXxf86vm.so.1 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/libGL.so.1
error: auto-patchelf could not satisfy dependency libglapi.so.0 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/swrast_dri.so
error: auto-patchelf could not satisfy dependency libdrm.so.2 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/swrast_dri.so
error: auto-patchelf could not satisfy dependency libLLVM-10.so.1 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/swrast_dri.so
error: auto-patchelf could not satisfy dependency libzstd.so.1 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/swrast_dri.so
error: auto-patchelf could not satisfy dependency libtensorflow_framework.so.2 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/cuda/open3d_tf_ops.so
error: auto-patchelf could not satisfy dependency libtensorflow_framework.so.2 wanted by /nix/store/zhrg5nn412h76y5l80z9c37hqcc98w90-python3.10-open3d-0.17.0/lib/python3.10/site-packages/open3d/cpu/open3d_tf_ops.so
auto-patchelf failed to find all the required dependencies.
Add the missing dependencies to --libs or use `--ignore-missing="foo.so.1 bar.so etc.so"`.
/nix/store/5s1yg5l36wzgy1dj0vv1ibarc4g7vrdr-stdenv-linux/setup: line 79: pop_var_context: head of shell_variables not a function context
/nix/store/5s1yg5l36wzgy1dj0vv1ibarc4g7vrdr-stdenv-linux/setup: line 1457: pop_var_context: head of shell_variables not a function context
/nix/store/5s1yg5l36wzgy1dj0vv1ibarc4g7vrdr-stdenv-linux/setup: line 1594: pop_var_context: head of shell_variables not a function context
error: builder for '/nix/store/9sh9yjq6ahb63pc8aqdz45xiz1hg212i-python3.10-open3d-0.17.0.drv' failed with exit code 1
error: 2 dependencies of derivation '/nix/store/q447a12jdyk6ycpi92wvb72qh3cgnn8r-python3-3.10.10-env.drv' failed to build
error: 1 dependencies of derivation '/nix/store/mlgjwl5qg9jf9hmj5c0lcsf29xdgxgy5-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/64gcl7vvxpyrhr3iy0nfr9hpcpl8wap4-dbus-1.drv' failed to build
error: 1 dependencies of derivation '/nix/store/flqz1s269qcj3q11hfbdq0yhkfb5yda1-unit-accounts-daemon.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/hlxp7pw6p5y6vi77mgn19331iaqwhv6x-unit-polkit.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/720qnib9lnwm7f3sj15vhgv7ni85390m-unit-systemd-fsck-.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/rzanv5sc49zzl2am29ddydmgi3p6hglp-unit-dbus.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/xicyxmw94y22jkdbdg47birnl9vc9ifc-unit-dbus.service.drv' failed to build
error: 4 dependencies of derivation '/nix/store/98nnnl4c4d2yjwzwrcffkqx5rqpww7gx-system-units.drv' failed to build
error: 1 dependencies of derivation '/nix/store/34bxyiymyzvas2ph9jasz3wp5j2pxbdb-user-units.drv' failed to build
error: 4 dependencies of derivation '/nix/store/y61pg4n3gjhydmmkhxp0n0jpck03qvwy-etc.drv' failed to build
error: 2 dependencies of derivation '/nix/store/zkyi3mqhk9dhidaiynh7pwdf5mym4mzf-nixos-system-nixos-22.11.3781.cd749f58ba8.drv' failed to build

I think I ended up solving it.
Turns out I was missing the mesa, zstd and libtensorflow packages.

I still have an issue with nix not finding libLLVM-10.so.1 which I think might have something to do with the build dependency of mesa but ignoring it has so far not produced any issues.

For reference this is my config file:

{ 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
     numpy
     torch-bin
     matplotlib
     pandas
     ipywidgets
     tensorflowWithoutCuda

     gpustat

     plotly
     dash
     scikitlearn
     addict
     tqdm


     (
      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 = [
         pkgs.autoPatchelfHook
       ];

       autoPatchelfIgnoreMissingDeps = [
        "libLLVM-10.so.1"
      ];

      buildInputs = with pkgs; [
        mesa
        zstd

        #libllvm
        stdenv.cc.cc.lib
        libusb.out

        cudaPackages.cudatoolkit
        cudaPackages.nccl

      libtorch-bin
      libtensorflow
    ];

    propagatedBuildInputs =  [
      (my_python.withPackages(
        ps: with ps; [
          nbformat
          werkzeug
          dash
          ipywidgets
          matplotlib
          pyyaml
          tqdm
          configargparse
          addict
          scikitlearn
          pyquaternion
          pandas
          #tensorflowWithoutCuda
        ]))
      ];


    })

  ];

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



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