Skip to content

Include expressions for all dependencies of a package #581

@syedmoizurrehman

Description

@syedmoizurrehman

When generating a nix expression for a Python package whose dependencies are not available in nixpkgs, I need to run nix-init for each of the missing dependency and then combine the nix expressions manually in a single nix expression to be able to build the package.

Is there a way to have nix-init recursively invoke itself on all dependencies and generate a single nix expression for the entire package?

For example, running nix-init for pydoc-markdown with buildPythonPackage will generate a nix expression for pydoc-markdown and its dependencies.

$ nix-init -u https://pypi.org/project/pydoc-markdown
{
  lib,
  buildPythonPackage,
  fetchPypi,
  poetry-core,
  click,
  databind-core,
  databind-json,
  docspec,
  docspec-python,
  docstring-parser,
  jinja2,
  nr-util,
  pyyaml,
  requests,
  tomli,
  tomli-w,
  watchdog,
  yapf,
}:

buildPythonPackage rec {
  pname = "pydoc-markdown";
  version = "4.8.2";
  pyproject = true;

  src = fetchPypi {
    ...
  };

  build-system = [
    poetry-core
  ];

  dependencies = [
    click
    databind-core
    databind-json
    docspec
    docspec-python
    docstring-parser
    jinja2
    nr-util
    pyyaml
    requests
    tomli
    tomli-w
    watchdog
    yapf
  ];

  pythonImportsCheck = [
    "pydoc_markdown"
  ];

  meta = {
    ...
  };
}

This expression requires the dependencies as arguments but some packages (such as databind-core) are not available in nixpkgs.

Once the feature is implemented, the generated expression will include the nix expression for all the dependencies such as following:

{
  lib,
  buildPythonPackage,
  fetchPypi,
  poetry-core,
}:

buildPythonPackage rec {
  pname = "pydoc-markdown";
  version = "4.8.2";
  pyproject = true;

  click = buildPythonPackage rec { ... };
  databind-core = buildPythonPackage rec { ... };
  databind-json = buildPythonPackage rec { ... };
  docspec = buildPythonPackage rec { ... };
  docspec-python = buildPythonPackage rec { ... };
  docstring-parser = buildPythonPackage rec { ... };
  jinja2 = buildPythonPackage rec { ... };
  nr-util = buildPythonPackage rec { ... };
  pyyaml = buildPythonPackage rec { ... };
  requests = buildPythonPackage rec { ... };
  tomli = buildPythonPackage rec { ... };
  tomli-w = buildPythonPackage rec { ... };
  watchdog = buildPythonPackage rec { ... };
  yapf = buildPythonPackage rec { ... };

  src = fetchPypi {
    ...
  };

  build-system = [
    poetry-core
  ];

  dependencies = [
    click
    databind-core
    databind-json
    docspec
    docspec-python
    docstring-parser
    jinja2
    nr-util
    pyyaml
    requests
    tomli
    tomli-w
    watchdog
    yapf
  ];

  pythonImportsCheck = [
    "pydoc_markdown"
  ];

  meta = {
    ...
  };
}

This behavior would be turned off by default. Passing a flag (such as -r for recursive) to nix-init would enable it.

If this or an equivalent feature is already available, please let me know how I can use it.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions