Packaging an application with Python bindings in NUR

I’d like to package an application (astrochem) with Python bindings. So far I’ve been able to package it within a fork of nixpkgs:

Note that it is declared in python-packages.nix with the toPythonModule so that the binding are available in Python.

The user base for this application is rather small, so it would probably better to have in NUR rather than in nixpkgs. How can I use the toPythonModule() function in NUR ? I could not find any example of this in NUR.

Try something like pythonPackages.toPythonModule or pkgs.pythonPackages.toPythonModule

I’ve tried to put the following lines in the default.nix of a nur-packages-templates fork:

astrochem = pkgs.pythonPackages.toPythonModule ((pkgs.callPackage ./pkgs/astrochem {pythonPackages = self; }).override { });

but then I get the following error:

nix-build -I . -A python27Packages.astrochem
error: undefined variable 'self' at /Users/smaret/Documents/Software/nur-packages/default.nix:18:103

I’ve also tried this:

astrochem = pkgs.pythonPackages.toPythonModule ((pkgs.callPackage ./pkgs/astrochem { }).override { });

but then I get a different error:

% nix-build -I . -A python27Packages.astrochem
error: attribute 'python27Packages' in selection path 'python27Packages.astrochem' not found

For reference, this can be done as follows:

astrochem = pkgs.pythonPackages.toPythonModule (
  (pkgs.callPackage ./pkgs/astrochem { inherit (pkgs) pythonPackages; }).override { }

Sse this issue on GitHub for details.