Skip to content

Include expressions for all dependencies of a package #581

Open

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.

Activity

  1. changed the title [-]Generate derivations of all dependencies[/-] [+]Include expressions for all dependencies of a package[/+] on Dec 28, 2024
  2. added
    enhancement
    on Jan 22, 2026
  3. figsoda commented on Jan 22, 2026

    @figsoda
    Member

    This would be particularly useful with python, though I'm not sure if there is a good way for nix-init itself to do this that is suitable for nixpkgs contributions until NixOS/nixpkgs#393981 is resolved (NixOS/nixpkgs#449896 seems pretty promising). Trying to touch top-level/python-packages.nix seems like a bad idea, and inlining the dependencies like that wouldn't be suitable for contributing to nixpkgs, which is the primary goal of nix-init.

    Hacking up a script using headless mode (#665) and by parsing Nix error messages might do the trick for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions