What does HackerNews think of poetry2nix?

Convert poetry projects to nix automagically [maintainer=@adisbladis]

Language: Nix

#79 in Python
I briefly considered it, but there are some big problems:

- The new replacement package, syncserver-rs, has already been added to Nixpkgs, along with a NixOS module [0]

- Python 2 and the package itself are no longer supported, meaning...

- support in Nixpkgs is pretty rough - dependencies have been updated such that they no longer support Python 2, or have been removed outright, meaning...

- syncserver has already been removed from Nixpkgs

- in order to avoid the problem of unsupported dependencies, I delegated dependency resolution to a community project, poetry2nix[1]. Even so, it was a nightmare to get working, lots of hacks and workarounds were needed

Of course, my repo is public, so anyone is welcome to use the Flake within. If they do, I'd suggest dropping me a line so I don't do anything drastic to the package or module.

[0] https://github.com/NixOS/nixpkgs/pull/176835

[1] https://github.com/nix-community/poetry2nix

There are some different/new tools for creating your own Python packages these days. It's still not truly solved in the sense of having a single clear winner , but one of these new package generation tools might serve you better:

poetry2nix: https://github.com/nix-community/poetry2nix

mach-nix: https://github.com/DavHau/mach-nix

dream2nix: https://nix-community.github.io/dream2nix/guides/getting-sta...

pynixify: https://github.com/cript0nauta/pynixify

pip2nix: https://github.com/nix-community/pip2nix

The tools available to you at the time (pypi2nix and maybe python2nix, if it was a long time ago) have been abandoned in favor of the newer tools, I think chiefly poetry2nix but I'm not sure.

There's still the Nixpkgs buildPythonPackage stuff, I think, if your goal is to upstream a lib into Nixpkgs. But if you just want to build your own Python applications and vendorize the deps (e.g., for work), you might try one of the tools above, which weren't available 3+ years ago.

dream2nix is by the author of mach-nix IIRC and has the goal of establishing a unified standard and codebase for ${proglang}2nix type package generators. But mach-nix is still maintained and might be the more feature-complete choice between them.

Maybe Nix-y Python users and developers can reply with some of their experiences using those tools for real projects :)

Poetry2nix[1] is good for that. A lot of packages unfortunately require overrides to work, but poetry2nix ships with a bunch of these by default.

[1] https://github.com/nix-community/poetry2nix

There are multiple ways of doing it. The obvious one (updating nixpkgs) you already mentioned.

Second way is to override[1], in documentation they are showing how to change compilation parameters, but you can also use this to change version of dependencies or source tarball for the package. As you use Nix you will eventually need to do it as sometimes package was not updated, or perhaps you need to use older version, or enable compilation option.

Third way is to use overlay[2]. In previous way an existing package was modified. Overlay allows to completely replace or add a new one.

For example there is a tool called poetry2nix[3], which on the fly translates python poetry lock file to Nix so nix can build them. Nixpkgs includes it and generally is frequently updated, but maybe there was a fix yesterday that hadn't made it there yet and it fixes an important bug. You can fetch that repo independently and attach it to nixpkgs (or you can use it directly).

Nix also has upcoming feature flakes which to my understanding takes this to a new level. So you can easily compose multiple repos like this in your application.

> Theres clearly more to Nix than just setting up language environments, which I'm guessing is where its usefuleness really kicks in. But purely for lang env set up, I'm not sure I see a point over other tooling...

I use it this way and the killer feature for myself is that for a project all I need to have installed is Nix and I can have exact environment the dev used.

It's not mentioned often, but I think a demo of it would be the repo for Nix program[4]. Typically when you want to compile some open source program, after you check out the repo, a hunt starts for the building tools and libraries needed. With nix you just issue build command or enter build shell[5] and things just work with no errors (or at least I did not get them when trying it a while ago. Everything worked on first try).

[1] https://nixos.org/manual/nixpkgs/stable/#chap-overrides

[2] https://nixos.org/manual/nixpkgs/stable/#chap-overlays

[3] https://github.com/nix-community/poetry2nix

[4] https://github.com/nixos/nix

[5] https://hydra.nixos.org/build/153568733/download/1/manual/co...

    nix-env -i -f '' -E 'f: (f {}).python3.withPackages (ps: with ps; [pyyaml requests])'
But you don't want to install globally. One of major strengths (for me at least) is that when combined with nix-shell you have something like virtualenv, but for all packages, not just the ones from python.

This means that someone else who checks out your project can get the same environment you had for the development.

If this is combined with direnv, then you don't even need to invoke nix-shell you just enter the project directory and everything is there.

If you use something like poetry2nix[1] it will automatically have the dependencies your project has.

[1] https://github.com/nix-community/poetry2nix