Help with poetry2nix

I’m trying to set up a python development environment with poetry2nix and nix flakes. I need a cli tool called pros-cli not packaged for nixos, and this seems like this best way to do it. Here is my flake.nix:

{
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.poetry2nix.url = "github:nix-community/poetry2nix";

  outputs = { self, nixpkgs, flake-utils, poetry2nix }:
    (flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
        };
        pythonEnv = poetry2nix.mkPoetryEnv {
        projectDir = ./.;
        };
      in
      rec {
        devShell = pkgs.mkShell {
          buildInputs = [
            pythonEnv
          ];
        };
      }));
}

However when direnv try to run the nix-shell it throws this error:

error: attribute 'mkPoetryEnv' missing

       at /nix/store/a9cfqjap3jl7h6x9magnr433rm6vwr26-source/flake.nix:12:21:

           11|         };
           12|         pythonEnv = poetry2nix.mkPoetryEnv {
             |                     ^
           13|         projectDir = ./.;

My pyproject.toml file looks like this:

[tool.poetry]
name = "prosTest"
version = "0.1.0"
description = "a test env for vex robotics development"
authors = ["BattleCh1cken <BattleCh1cken@Larkov.de>"]
license = "gpl"

[tool.poetry.dependencies]
python = "^3.10"
pros-cli = "^3.3.3"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
111

I’m not sure why this doesn’t work. This shell.nix for qmk seems to do something similar and it works just fine for me:

1 Like

Here’s the template that is recommended in the poetey2nix readme. They are using an overlay. I cannot say if that is required, but it seems to be recommended.

Hope that’s helpful

As far as I can tell the overlay is only there so they can refer to the app as pkgs.app. Regardless, the qmk example works without overlay.

How about something like this:

instead of

        pkgs = import nixpkgs {
          inherit system;
        };
        pythonEnv = poetry2nix.mkPoetryEnv ...

try

        pkgs = import nixpkgs {
          inherit system;
          overlays = [ poetry2nix.overlay ];
        };
        pythonEnv = pkgs.poetry2nix.mkPoetryEnv ...
1 Like