Infinite Recursion Encountered - Making a Python Package for nixpkgs

I’m trying to add the python module for ninja into nixpkgs, but I get the following error:

error: infinite recursion encountered

       at //builtin/derivation.nix:19:19:
       … while evaluating the attribute 'out.outPath'

       at /home/jonathan/NixBuilds/nixpkgs/lib/customisation.nix:215:13:

          214|             drvPath = assert condition; drv.${outputName}.drvPath;
          215|             outPath = assert condition; drv.${outputName}.outPath;
             |             ^
          216|           } //

       … while evaluating the attribute 'nativeBuildInputs' of the derivation 'python3.10-scikit-build-0.16.7'

       at /home/jonathan/NixBuilds/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:302:7:

          301|     // (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
          302|       name =
             |       ^
          303|         let

       … while evaluating the attribute 'out.outPath'

       at /home/jonathan/NixBuilds/nixpkgs/lib/customisation.nix:215:13:

          214|             drvPath = assert condition; drv.${outputName}.drvPath;
          215|             outPath = assert condition; drv.${outputName}.outPath;
             |             ^
          216|           } //

       … while evaluating the attribute 'nativeBuildInputs' of the derivation 'python3.10-ninja-1.11.1'

       at /home/jonathan/NixBuilds/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:302:7:

          301|     // (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
          302|       name =
             |       ^
          303|         let

       … while evaluating the attribute 'drvPath'

       at /home/jonathan/NixBuilds/nixpkgs/lib/customisation.nix:228:7:

          227|     in commonAttrs // {
          228|       drvPath = assert condition; drv.drvPath;
             |       ^
          229|       outPath = assert condition; drv.outPath;

       … while evaluating the attribute 'drvPath'

       at /home/jonathan/NixBuilds/nixpkgs/lib/customisation.nix:228:7:

          227|     in commonAttrs // {
          228|       drvPath = assert condition; drv.drvPath;
             |       ^
          229|       outPath = assert condition; drv.outPath;

My commit for my current attempt is here: python3Packages.ninja: init at 1.11.1 · JonBoyleCoding/nixpkgs@a4ca230 · GitHub

I believe it’s got something to do with the name “ninja” for the package in the python-packages.nix. Please excuse the extra argument - it was an attempt to fix that didn’t help and I plan to remove them.

Thanks for the help - I’ve spent way too many hours trying to solve this.

But you are passing the package that’s being built to itself as a build dependency?

What is the purpose of ninja-build?

No it’s not the same package (I understand it looks that way) - the CMake in the project was by default looking for the Ninja build tool executable to build the project, but the Ninja python package is a separate thing (made by the same project).

I tried using the ninja-build there as a way to get around this situation - in that the package being made on pypi has the same name as the compilation tool it is using. Unfortunately it didn’t work and the same infinite recursion error is happening as before.

Just to add, I have a working flake (which I’m using for my project). I just thought it would be worth trying to push something upstream as I’d put in some work for it already.

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };


  #https://github.com/Kitware/ninja/archive/v1.11.1.g95dee.kitware.jobserver-1.tar.gz'

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {inherit system;};

        python = pkgs.python310;

        ninja = python.pkgs.buildPythonPackage rec {
          pname = "ninja";
          version = "1.11.1";

          src = pkgs.fetchPypi {
            pname = "ninja";
            version = "1.11.1";
            sha256 = "sha256-yDOkfTmy0e7j+cqIb6FYHv1b5gaLgnNKwimWHuh0j5A=";
          };

          ninja-source = builtins.fetchTarball {
            # Comes from NinjaUrls.cmake in repo
            url = "https://github.com/Kitware/ninja/archive/v1.11.1.g95dee.kitware.jobserver-1.tar.gz";
            sha256 = "sha256:1iaf17j0fclzm71f2wl12klffni4c13x8i4qz378b5wcv474ys4g";
          };

          patches = [ ./patch-cmake-download.patch ];

          CMAKE_ARGS = "-DNinja_SOURCE_DIR=${ninja-source}";

          nativeBuildInputs = [
            python.pkgs.scikit-build
            python.pkgs.setuptools_scm
            python.pkgs.setuptools
            pkgs.cmake
            pkgs.ninja
          ];

          dontUseCmakeConfigure = true;
          format = "pyproject";
        };

        python-ninja = python.withPackages (ps: with ps; [ ninja ]);
    in
    {
      packages.default = ninja;

      devShells.default = pkgs.mkShell {
        buildTools = [ python-ninja ];
      };
    }
  );
}