Assistance needed in packaging python program

Hey there!

I am trying to package my first application for nixpkgs right now, but for some reason there is an error that appears. Unfortunately it is quite cryptic, so I could not figure out how I would go about fixing. I already tried a few different things, but none of them helped.

When running the command nix-build -A xenon, I get the following error:

error:
       … while calling the 'abort' builtin

         at /home/thiloho/dev/nixpkgs/lib/customisation.nix:173:65:

          172|
          173|     in if missingArgs == [] then makeOverridable f allArgs else abort error;
             |                                                                 ^
          174|

       error: evaluation aborted with the following error message: 'Function called without required argument "buildPythonPackage" at /home/thiloho/dev/nixpkgs/pkgs/by-name/xe/xenon/package.nix:2'

And this is my code for pkgs/by-name/xe/xenon/package.nix:

{ lib
, buildPythonPackage
, fetchFromGitHub
}:

buildPythonPackage {
  pname = "xenon";
  version = "0.9.1";

  src = fetchFromGitHub {
    owner = "rubik";
    repo = "xenon";
    rev = "9d06d21515d9956d4c270aa04b05d4f1751f9516";
    hash = "sha256-ui6dCjn4Xt+QqPoQoe/2OwfR+1DDW3dziLjSPsimQUs=";
  };

  meta = with lib; {
    homepage = "https://xenon.readthedocs.io";
    description = "Code complexity monitoring tool based on radon";
    license = licenses.mit;
    maintainers = with maintainers; [ thiloho ];
  };
}

I would very much appreciate your help! Thank you in advance!

The error is quite clear:

evaluation aborted with the following error message: 'Function called without required argument "buildPythonPackage" at /home/thiloho/dev/nixpkgs/pkgs/by-name/xe/xenon/package.nix:2'

Your nix file contain a function that expects three arguments: lib, buildPythonPackage, fetchFromGitHub and you provided none. The same question (with a a different package) was asked and answered here: Need help on failing build - packaging onedriver for nixos

1 Like

I have exactly the same problem right now, the same issue with a python package I want to build.

I am trying to adapt the following stagnant PR from nixpkgs to my local setup: nerd-dictation: init at unstable-2022-07-12 by jtojnar · Pull Request #185148 · NixOS/nixpkgs · GitHub

It includes a python package for interacting with the vosk-api.

My attempt to package the python vosk API looks like this. This is basically just a copy-paste from the PR.

{ buildPythonPackage
, fetchPypi
, cffi
, srt
, tqdm
, requests
, websockets
, substituteAll
, vosk-api
, lib
}:

buildPythonPackage rec {
  pname = "vosk";
  version = "0.3.45";
  # inherit (vosk-api) src version;
  src = fetchPypi {
    inherit pname version;
    sha256 = "";
  };

  patches = [
    (substituteAll {
      src = ./fix-paths.patch;
      vosk_api = vosk-api;
    })
  ];

  propagatedBuildInputs = [
    cffi
    srt
    tqdm
    requests
    websockets
  ];

  # No tests.
  doCheck = false;

  pythonImportsCheck = [
    "vosk"
  ];

  postPatch = ''
    cd python
  '';

  meta = with lib; {
    description = "Python bindings for VOSK API";
    homepage = "https://github.com/alphacep/vosk-api";
    license = licenses.asl20;
    maintainers = with maintainers; [ ];
    platforms = platforms.linux;
  };
}

However I run into the same problem when trying to use this,

I find the solution to be non-obvious to say the least. Why does nix complain here that buildPythonPackage is not provided?

What was the solution you went for, @thiloho ?

What command are you running in the terminal to build this? What is the exact error message?

Did you try to use the command with callPackage from this post that was linked above?

The buildPythonPackage attribute is only consumable like that in the python package set.

If you are packaging an application you’ll want python3Packages.buildPythonApplication.

1 Like

I am trying to get nerd-dictation to run from the PR mentioned. I use it via my system flake where I try to create an overlay which I then try to use in my home-manager config.

The nerd-dication derivation from the PR depends on three other things, the vosk api, the python binding for the vosk api, and kaldi with some patches as it seems. I try to overlay these over my nixpkgs like so:

In my flake.nix I define an overlay

overlay-nerd-dictation = import ./packages/nerd-dictation-vosk;

Which is then later used for home manager:

nixpkgs.overlays = [ overlay-nerd-dictation ];

For the imported ./packages/nerd-dictation-vosk I have a default.nix like so:

self: { pkgs, lib, stdenv, python3Packages, ... }@super:
{
  nerd-dictation = pkgs.callPackage (import ./pkgs/nerd-dictation) { };
  vosk-api = pkgs.callPackage (import ./pkgs/vosk-api) { };
  vosk-python = pkgs.callPackage (import ./pkgs/python-vosk) { };
  kaldi = pkgs.callPackage (import ./pkgs/kaldi) { };
}

I then try to nix build the activation package for home manager.

When it gets to vosk-python I get this error, which is basically the same error as mentioned in this topic in the beginning:

error: evaluation aborted with the following error message: 'Function called without required argument "buildPythonPackage" at /nix/store/96dahjacx03lazjkrf9ra0aim4f0vyzb-source/packages/nerd-dictation-vosk/pkgs/python-vosk/default.nix:1'

So…

I try to create an overlay for a package which is then used in nerd-dictation.

The original PR had for nerd-dictation in default.nix:

  propagatedBuildInputs = with python3.pkgs; [
    vosk-python
  ];

but I was unsure if I was actually creating a pythonPackage here, so I changed it to

  propagatedBuildInputs = with pkgs; [
    vosk-python
  ];

At this point I got the error, before it would just not find the package. But here I might just be unsure at this point how to define the overlay for this python package properly.

Any further help is appreciated…