Removing tedious nature of creating new python nixpkgs derivations

Wanted to share a quick tool that I wrote to remove the tedious nature of creating python derivations for packages that will be submitted to nixos/nixpkgs. Was wondering of other such tools that exist? I have seen pip2nix and pypi2nix but they seem more oriented toward developing outside of nixpkgs.

It is at https://github.com/costrouc/nixpkgs-dev-tools/blob/master/python/python-package-init.py python-package-init.py will create a default.nix in the current directory. It parses the pypi json api along with mock running setup.py to get all of the dependencies. It gets 80-90% of the work done for you and removes the boring tedious stuff.

For a simple example python-package-init.py filterpy will grab the latest filterpy release from pypi.

{ pkgs
, buildPythonPackage
, fetchPypi
, numpy
, scipy
, matplotlib
}:

buildPythonPackage rec {
  pname = "filterpy";
  version = "1.4.5";
  
  src = fetchPypi {
    inherit pname version;
    sha256 = "4f2a4d39e4ea601b9ab42b2db08b5918a9538c168cff1c6895ae26646f3d73b1";
  };
  
  buildInputs = [ ];
  checkInputs = [ ];
  propagatedBuildInputs = [ numpy scipy matplotlib ];

  meta = with pkgs.lib; {
    description = "Kalman filtering and optimal estimation library";
    homepage = https://github.com/rlabbe/filterpy;
    license = licenses.MIT;
    # maintainers = [ maintainers. ];
  };
}

It also handles complex examples well too. python-package-init.py hacking --version 1.0.0

{ pkgs
, buildPythonPackage
, fetchPypi
, six
, flake8
, pbr
}:

buildPythonPackage rec {
  pname = "hacking";
  version = "1.0.0";
  
  src = fetchPypi {
    inherit pname version;
    sha256 = "132c728fdf939576836bff112bcfd241c4b628fd90288744dd5e4b62744a3469";
  };
  
  # # Package conditions to handle
  # # might have to sed setup.py and egg.info in patchPhase
  # # sed -i "s/<package>.../<package>/"
  # six (>=1.10.0)
  # flake8 (<2.7.0,>=2.6.0)
  # pbr (!=2.1.0,>=2.0.0)
  
  # # Extra packages (may not be necissary)
  # reno (>=2.5.0); extra == 'test'
  # eventlet (!=0.18.3,!=0.20.1,>=0.18.2); extra == 'test'
  # testtools (>=2.2.0); extra == 'test'
  # testscenarios (>=0.4); extra == 'test'
  # testrepository (>=0.0.18); extra == 'test'
  # openstackdocstheme (>=1.18.1); extra == 'test'
  # sphinx (!=1.6.6,!=1.6.7,>=1.6.2); extra == 'test'
  # python-subunit (>=1.0.0); extra == 'test'
  # mock (>=2.0.0); extra == 'test'
  # fixtures (>=3.0.0); extra == 'test'
  # coverage (!=4.4,>=4.0); extra == 'test'
  # flake8-docstrings (==0.2.1.post1); extra == 'pep257'
  
  buildInputs = [ ];
  checkInputs = [ ];
  propagatedBuildInputs = [ six flake8 pbr ];

  meta = with pkgs.lib; {
    description = "OpenStack Hacking Guideline Enforcement";
    homepage = https://docs.openstack.org/hacking/latest/;
    license = licenses.;
    # maintainers = [ maintainers. ];
  };
}
5 Likes

Looks useful. You can also add it here for people to discover: Language-specific package helpers - NixOS Wiki

Thanks. I’ve been wanting to try it with mocking setup for quite some time now, and I see it is indeed working just fine.

Do replace pkgs by just lib.

The old link is is no longer working. But we can still find the package at