Trying to use py3dtiles Python package

Edit: replaced shell.nix content with the proper content

Hi,

First post here :slight_smile:

I’d like to use py3dtiles under NixOS. I’m running NixOS 24.05 with Flakes and Home Manager on a fresh install.

As py3dtiles is not on nixpkgs, I’m trying to follow this method to make it available. I’ve used nix-init to generate this py3dtiles.nix file:

{ lib
, python3
, fetchFromGitLab
}:

python3.pkgs.buildPythonApplication rec {
  pname = "py3dtiles";
  version = "8.0.2";
  pyproject = true;

  src = fetchFromGitLab {
    owner = "py3dtiles";
    repo = "py3dtiles";
    rev = "v${version}";
    hash = "sha256-Y7tectMpeckx6fO7xNZZOmmjZjuXpI1oogDXjkebE98=";
  };

  nativeBuildInputs = [
    python3.pkgs.setuptools
    python3.pkgs.setuptools-scm
    python3.pkgs.wheel
  ];

  propagatedBuildInputs = with python3.pkgs; [
    cython
    earcut
    lz4
    numba
    numpy
    psutil
    pygltflib
    pyproj
    pyzmq
  ];

  passthru.optional-dependencies = with python3.pkgs; {
    dev = [
      line-profiler
      mypy
      pre-commit
      pytest
      pytest-benchmark
      pytest-cov
      types-psutil
      types-psycopg2
      typing-extensions
    ];
    doc = [
      myst-parser
      sphinx
      sphinx-multiversion
      sphinx-rtd-theme
      sphinxcontrib-apidoc
    ];
    las = [
      laspy
    ];
    pack = [
      build
      commitizen
      twine
      wheel
    ];
    ply = [
      plyfile
    ];
    postgres = [
      psycopg2-binary
    ];
  };

  pythonImportsCheck = [ "py3dtiles" ];

  meta = with lib; {
    description = "Python module to manage 3DTiles format";
    homepage = "https://gitlab.com/py3dtiles/py3dtiles";
    changelog = "https://gitlab.com/py3dtiles/py3dtiles/-/blob/${src.rev}/CHANGELOG.md";
    license = licenses.asl20;
    maintainers = with maintainers; [ ];
    mainProgram = "py3dtiles";
  };
}

And here’s my shell.nix file:

let
  pkgs = import <nixpkgs> {};

  python = pkgs.python3.override {
    self = python;
    packageOverrides = pyfinal: pyprev: {
      py3dtiles = pyfinal.callPackage ./py3dtiles.nix { };
    };
  };

in pkgs.mkShell {
  packages = [
    (python.withPackages (python-pkgs: [
      # select Python packages here
      python-pkgs.py3dtiles
      python-pkgs.laspy
      # python-pkgs.foobar
    ]))
  ];
}

Now, running nix-shell in my dev directory seems to work, as I can now see a Python version available with python --version (I don’t have any other on the system than the one declared on shell.nix). But trying to run py3dtiles in the terminal as described here (with or without parameters and options) triggers a command not found.

Where should I go from here? Any advice very welcome, thanks!

1 Like

Hi there! Maintainers of py3dtiles here! I’m also part of the nixpkgs geospatial team and I maintain a couple of other packages, even though I’m still very new to nixpkgs. Putting py3dtiles in nixpkgs has been a goal of mine since a long time, thanks for starting this!

From what I can gather (with my limited nixpkgs experience), your py3dtiles.nix seems ok. I think you should just open a MR to nixpkgs (renaming it to package.nix and putting it onto pkgs/by-name/py/py3dtiles) with it. Do you feel like doing it? Can you put teams.geospatial.members as maintainers in addition to yourself (if you want to maintain it of course)? That way, when you open the MR, I’ll be notified also.

As for the shell: for your information, we already have a shell.nix in the py3dtiles repo. That can help you get started? If I understand things correctly, the shell drops you in an env with the dependencies, but not the package itself. That being said, your shell.nix seems to include py3dtiles, so I don’t really know what’s going on… I’ll try to find time later to test.

Thanks again for that!