Can someone provide an example of a Python package in a flake, with a GitHub dependency?

I’m trying to package a single Python script. I feel like it shouldn’t take longer to write the package than it took to write the Python script. The thing is, the script has two dependencies: (1) libgen-api, which is not in nixpkgs, (2) tabulate, which is in nixpkgs. So I’m banging my head against a wall trying to get this to work, but solving one problem only creates another.

I know I have to do pkgs.python3.withPackages somewhere. And I know I have to do a fetchFromGitHub somewhere to get the libgen-api from GitHub. But it’s totally opaque to me what needs to be a function, and what needs to be an attribute set, and what a self-calling function is, or when and why I need to provide default values, or when I use paretheses or curly braces.

I just need an example so that I can plug in the values for my package. Or better yet, some kind of tool that automatically takes a pipenv file and produces a nix file from it.

I don’t have an example but if libgen-api is not packaged, you’d need to “package” it with something like:

  libgen-api = python.pkgs.buildPythonPackage {
  myPyEnv = python.pkgs.withPackages(ps: with ps; [

I recommend you to use Mach-Nix. I was able to get a python with libgen-api using nix-shell with this shell.nix:

  mach-nix = import (builtins.fetchGit {
    url = "";
    ref = "refs/tags/3.1.1";
  }) {};
mach-nix.mkPythonShell {
  requirements = ''

Inside requirements you put every other python lib you need. It’s possible to use it with flakes too Usage with Nix Flakes · Issue #153 · DavHau/mach-nix · GitHub

1 Like