nix-community / pip2nix

Freeze pip-installable packages into Nix expressions [maintainer=@datakurre]
171 stars 26 forks source link

Flake, python overlay support #70

Open mikepurvis opened 3 years ago

mikepurvis commented 3 years ago

Hey, thanks for this tool— it does exactly what I needed, in just the way I was hoping. I did find that what worked best for me was to create a wrapper on the generated file to merge the packages into the "native" python3Packages set, eg:

final: prev: let
  generatedPackages = final.callPackage ./python-packages.nix {};
  overrides = import ./overrides.nix;

in {
  # Composable Python3 override to add additional packages.
  python3 = final.lib.fix (py:
    prev.python3.override (old: {
      self = prev.python3;
      packageOverrides = final.lib.composeManyExtensions [
        old.packageOverrides
        generatedPackages
        overrides
      ];
    })
  );
}

I don't know that pip2nix should necessarily include something like this itself, but it could be valuable as a documentation item for other users who aren't sure how to integrate pip2nix packages in with other Python packages from nixpkgs.

My second question is, would it be possible to make pip2nix installable/usable as a flake? As a relatively new Nix user, I have found the flake system to be very ergonomic and a sufficiently good fit for my expectations that I haven't actually had to learn much of how to work with non-flakes, so it's always a bit of a speed-bump encountering tools which don't directly support it!

datakurre commented 3 years ago

Thanks for the nice current usage example. pip2nix does contain some scaffolds, which are outdated due to age of the tool.

Flake support is a great idea, because pip2nix depends on specific pip versions and that could be enforced with flake.

PS. What made you prefer pip2nix over the other alternatives like poetry2nix? Asking, because unsure if it still makes sense to upgrade pip2nix for the latest pip now that there are many alternatives. (That said, I have not even started yet to migrate my projects to alternatives.)

mikepurvis commented 1 year ago

@datakurre I do use poetry2nix for a number of my other projects, and I quite like it— likely I will eventually switch my pip2nix use-case to use it as well. However, I find poetry2nix is a bit more invasive in terms of wanting to generate whole environments and roll everything itself from scratch, where pip2nix is nice for just having a single requirements.txt specifying exact versions of select packages, and then being able to generate an overlay that supplies just those precise things with a bare minimum of magic.

datakurre commented 1 year ago

Thanks again. I try to use poetry2nix when it works, but too still fallback to pip2nix every now and then. And because running it with nixpkgs-20.1x has still been working, I have not touched it 😬

Lately I have been using pip2nix with a pattern where I default to nixpkgs versions and only use missing packages and specific versions from pip2nix like at https://github.com/datakurre/meggie-nix/blob/main/meggie.nix