Packaging Python for nixpkgs w/ Dependency from GitHub

Description

I’ve written a program in Python called html2nix that converts bookmarks exported as HTML by browsers to Nix syntax as accepted by Home Manager’s programs.firefox.profile.<name>.bookmarks. I’d like to package it and add it to nixpkgs.

I’ve never packaged any program for any distro, have little/no experience with packing Python in general, and am relatively new to Nix.

What I Have Now

I’ve gotten to the point where I have a package.nix that successfully builds a wheel, however, a dependency can’t be found. Specifically one that is pulled from GitHub called Netscape-Bookmarks-File-Parser. This dependency is not on PyPi or in nixpkgs.

Bellow is my current package.nix. For my current working one, see my fork of nixpkgs.

{ fetchFromGitHub, lib, python3Packages }: python3Packages.buildPythonApplication rec {
  pname = "html2nix";
  version = "0.0.1";
  # Set python build type.
  pyproject = true;

  src = fetchFromGitHub {
    owner = "ReedClanton";
    repo = "${pname}";
    rev = "v${version}";
    hash = "sha256-J0qEBS2I/h1zwf790AvZG0Bqe44YIgc1tgiFm8U41nk=";
  };

  # Build time dependencies.
  nativeBuildInputs = with python3Packages; [
    setuptools
  ];

  # Run time dependencies.
  buildInputs = with python3Packages; [
    # Using my fork.
    (buildPythonPackage rec {
      pname = "NetscapeBookmarksFileParser";
      version = "1.2";
      src = fetchFromGitHub {
        owner = "ReedClanton";
        repo = "Netscape-Bookmarks-File-Parser";
        rev = "v${version}";
        hash = "sha256-b4AFTHNMv0aMy25URe22cIAZvAL3pkP0oas//SMWCHY=";
      };
    })
  ];

  # Un-comment once tests are written.
  doCheck = false;

  meta = with lib; {
    changelog = "https://github.com/ReedClanton/html2nix/blob/${version}/CHANGELOG.md";
    description = "Converts HTML files containing bookmarks to Nix syntax.";
    longDescritpion = ''
      Converts HTML files that contain bookmarks to Nix syntax. The HTML files are exported by
      browsers and should follow the Netscape Bookmarks "standard". The resulting Nix syntax is
      accepted by Home Manager via `programs.firefox.profiles.<profileName>.bookmarks`.
    '';
    homepage = "https://github.com/ReedClanton/html2nix";
    license = licenses.mit;
    mainProgram = "html2nix";
    maintainers = with maintainers; [
      ReedClanton
    ];
    # When `platforms` isn't provided it's set to the same value as the interpreter.
    #platforms = platforms.unix;
  };
}

The Error

Bellow is the error I get when when I run my system install that include my package.nix.

these 10 derivations will be built:
  /nix/store/rx6sl7rsrz6b3784wd9hmizsdhps0pfa-html2nix-0.0.1.drv
  /nix/store/xwnq2bafr135s6kngkd0ixmpsqlw845s-home-manager-path.drv
  /nix/store/icy2jf6z3sbrc6g1dkvn7xzz9c7564xm-hm_fontconfigconf.d10hmfonts.conf.drv
  /nix/store/q98b57b3g5rxqqczh8bc55mwq5blqjil-home-manager-files.drv
  /nix/store/13l9ryi456cxmislvscn4vdsiaw90lfj-home-manager-generation.drv
  /nix/store/a602g9kybk70ndz0n13ycpc2nw4kvxm6-user-environment.drv
  /nix/store/8l0vj6m0z6w10vafwnzc94fsrdiigwx8-unit-home-manager-reedclanton.service.drv
  /nix/store/x67pk2mgryldyg9jxzdvnbdq69xwbl42-system-units.drv
  /nix/store/4wacblmpw1lqryd5dwk8h0kqx5fxmfg4-etc.drv
  /nix/store/cqg2zrj6k4dfh4gs72nbhyi8fqqcd5pw-nixos-system-nixos-desktop-gnome-23.11.20240225.5bf1cad.drv
building '/nix/store/rx6sl7rsrz6b3784wd9hmizsdhps0pfa-html2nix-0.0.1.drv'...
error: builder for '/nix/store/rx6sl7rsrz6b3784wd9hmizsdhps0pfa-html2nix-0.0.1.drv' failed with exit code 1;
       last 10 log lines:
       > adding 'html2nix-0.0.1.dist-info/top_level.txt'
       > adding 'html2nix-0.0.1.dist-info/RECORD'
       > removing build/bdist.linux-x86_64/wheel
       > Successfully built html2nix-0.0.1-py3-none-any.whl
       > Finished creating a wheel...
       > Finished executing pypaBuildPhase
       > Running phase: pythonRuntimeDepsCheckHook
       > Executing pythonRuntimeDepsCheck
       > Checking runtime dependencies for html2nix-0.0.1-py3-none-any.whl
       >   - netscapebookmarksfileparser not installed
       For full logs, run 'nix log /nix/store/rx6sl7rsrz6b3784wd9hmizsdhps0pfa-html2nix-0.0.1.drv'.
error: 1 dependencies of derivation '/nix/store/xwnq2bafr135s6kngkd0ixmpsqlw845s-home-manager-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/13l9ryi456cxmislvscn4vdsiaw90lfj-home-manager-generation.drv' failed to build
error: 1 dependencies of derivation '/nix/store/a602g9kybk70ndz0n13ycpc2nw4kvxm6-user-environment.drv' failed to build
error: 1 dependencies of derivation '/nix/store/4wacblmpw1lqryd5dwk8h0kqx5fxmfg4-etc.drv' failed to build
error: 1 dependencies of derivation '/nix/store/cqg2zrj6k4dfh4gs72nbhyi8fqqcd5pw-nixos-system-nixos-desktop-gnome-23.11.20240225.5bf1cad.drv' failed to build

Other Resources

Not only am I sure the answer is likely obvious, but I’m pretty sure I’ve seen it but don’t realize it. The bellow seem/are related, but wasn’t able to figure out if/how they applied:

Possible Solution(s)

Maybe I have to have a setup.py even when using pyproject, but I tried that to no avail.

This looks like nixpkgs#285234? You can disable this check with dontCheckRuntimeDeps = true;

I tried using pythonRelaxDepsHook but that seems to not work in this case. Also switched buildInputs to propagatedBuildInputs because otherwise it seems like the dependency was not available at runtime.

2 Likes

Wahoo! The system build works now!