nix-community / poetry2nix

Convert poetry projects to nix automagically [maintainer=]
MIT License
892 stars 451 forks source link

Inconsistent behaviours using nix-shell with poetry2nix #1226

Open bigluck opened 1 year ago

bigluck commented 1 year ago

Describe the issue

I'm trying to replace my docker-base development environment in favor of nix, and it looks poetry2nix does what I'm looking for.

But still, after a few days of work, I cannot connect all the dots.

I would like to:

The last 2 points don't work as I hoped, and I can't understand why; in particular if I run python in interactive mode I can import my Python scripts, but passing them to the Python interpreter fails.

Additional context

Even if it's a basic project, I've committed my code here: bigluck/poetry2nix-venv.

But in general this is my pyproject.toml file:

[tool.poetry]
name = "my-python-nix-test"
version = "0.0.1"
description = "Test"
authors = ["BigLuck"]
readme = "README.md"
packages = [{include = "my_python_nix_test"}]

[tool.poetry.dependencies]
python = "^3.11"
requests = "^2.31.0"

[tool.poetry.scripts]
my-python-nix-test = "my_python_nix_test.a:main"

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

and this is the shell.nix file that uses poetry2nix:

{ pkgs ? import <nixpkgs> {} }:

let
  myAppEnv = pkgs.poetry2nix.mkPoetryEnv {
    python = pkgs.python311;
    projectDir = ./.;
    editablePackageSources = {
      my_python_nix_test = ./my_python_nix_test;
    };
    preferWheels = true;
  };
in myAppEnv.env.overrideAttrs (oldAttrs: {
  buildInputs = [
    # pkgs.poetry
    # (pkgs.poetry.override { python = pkgs.python311; })
  ];
  shellHook =
    ''
    ln -sfT $nativeBuildInputs ./venv
    '';
})

Still, you can find all the details on my git repo: bigluck/poetry2nix-venv.

Can anybody help me understand what's going on and how I can fix it? Thanks

Pegasust commented 1 year ago

Surprisingly, python -m a works as expected. I'm sure it's the little details where Nix patches are available only on something like an interactive mode (unsure).