Poetry2nix: error: attribute 'dev' missing

I’m new to poetry2nix and the error I got does not help me that much to figurate what is going on. Here is my flake.nix:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url  = "github:numtide/flake-utils";
    poetry2nix = {
      url  = "github:nix-community/poetry2nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
  outputs = {self, nixpkgs, flake-utils, poetry2nix, ...}:
    flake-utils.lib.eachDefaultSystem (system:
      let
        # overlays = [ poetry2nix.overlay ];
        # pkgs = import nixpkgs { inherit system overlays; };
        pkgs = import nixpkgs { inherit system; };
        inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryEnv;
        pythonEnv = mkPoetryEnv {
          python = pkgs.python311;
          projectDir = ./.;
        };
      in
      {
        devShells.default = pkgs.mkShell {
          packages = with pkgs; [
            poetry
            pythonEnv
          ];
        };
      }
    );
}

and here is the output:

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nix-shell'
         whose name attribute is located at /nix/store/2p9qcybzmx1rfayjw866rz8xljbw45g9-source/pkgs/stdenv/generic/make-derivation.nix:353:7

       … while evaluating attribute 'nativeBuildInputs' of derivation 'nix-shell'

         at /nix/store/2p9qcybzmx1rfayjw866rz8xljbw45g9-source/pkgs/stdenv/generic/make-derivation.nix:397:7:

          396|       depsBuildBuild              = elemAt (elemAt dependencies 0) 0;
          397|       nativeBuildInputs           = elemAt (elemAt dependencies 0) 1;
             |       ^
          398|       depsBuildTarget             = elemAt (elemAt dependencies 0) 2;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'dev' missing

       at /nix/store/187phwwr5c87bnnvyac8lf69gz3yibn2-source/default.nix:86:45:

           85|           if pyProject.tool.poetry.group or { } != { }
           86|           then lib.flatten (map (g: getDeps pyProject.tool.poetry.group.${g}.dependencies) groups)
             |                                             ^
           87|           else [ ]

I tried to use previous commits of poetry2nix in case this was a bug but I got the exact same error. I’m out of idea, any help would be appreciated :slight_smile:

Can you share your pyproject.toml and the version of Poetry you have been using? I suspect you have been using a version prior to 1.2.0, which is when dependency groups were added and the dev-dependencies section was deprecated.

Here is the pyproject.toml

[tool.poetry]
name = "myproject"
version = "0.3.0"
description = "MyProject"
authors = ["Me me <me@me.com>"]

[tool.poetry.dependencies]
python = "^3.10"
click = "^8.1.7"
rich = "^13.7.0"
anytree = "^2.12.1"
tqdm = "^4.66.1"
d3graph = "^2.5.0"
aiohttp = "^3.9.1"
scikit-learn = "^1.3.2"

[tool.poetry.scripts]
myscript = "tools.myscript:cli"

[tool.poetry.group.lint.dependencies]
ruff = "^0.1.7"

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

[tool.ruff.lint]
select = [
    # pycodestyle
    "E",
    # Pyflakes
    "F",
    # isort
    "I",
]

The poetry version used is 1.7.0 on my nixos machine

What happens if you rename the lint group to dev? Your config should work AFAICT, but I’m curious if poetry2nix expects that specific dependency group name.

It seems to work, I’m not sure why it’s compiling numpy form source however but why not :smiley:

After running for a while it stopped with the following error:

error: builder for '/nix/store/ivh0gwwk637p08mybq3c4azzmaka220k-python3.11-ismember-1.0.2.drv' failed with exit code 2;
       last 10 log lines:
       >   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
       >   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
       >   File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
       >   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
       >   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
       >   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
       >   File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
       > ModuleNotFoundError: No module named 'setuptools'

I tried to use the documentation to fix the problem but it does not seems to work:

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nix-shell'
         whose name attribute is located at /nix/store/gzf4zwcakda1nykn6h0avh45xhjhvsz4-source/pkgs/stdenv/generic/make-derivation.nix:353:7

       … while evaluating attribute 'nativeBuildInputs' of derivation 'nix-shell'

         at /nix/store/gzf4zwcakda1nykn6h0avh45xhjhvsz4-source/pkgs/stdenv/generic/make-derivation.nix:397:7:

          396|       depsBuildBuild              = elemAt (elemAt dependencies 0) 0;
          397|       nativeBuildInputs           = elemAt (elemAt dependencies 0) 1;
             |       ^
          398|       depsBuildTarget             = elemAt (elemAt dependencies 0) 2;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'defaultPoetryOverrides' missing

       at /nix/store/v7zclrv4srqq3q9fnx0vj56lyp8bfynm-source/flake.nix:20:23:

           19|           projectDir = ./.;
           20|           overrides = poetry2nix.lib.defaultPoetryOverrides.extend
             |                       ^
           21|             (self: super: {

The current flake.nix looks like this:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url  = "github:numtide/flake-utils";
    poetry2nix = {
      url  = "github:nix-community/poetry2nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
  outputs = {self, nixpkgs, flake-utils, poetry2nix, ...}:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };
        inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryEnv;
        pythonEnv = mkPoetryEnv {
          python = pkgs.python3Full;
          projectDir = ./.;
          overrides = poetry2nix.defaultPoetryOverrides.extend
            (self: super: {
              ismember = super.ismember.overridePythonAttrs
              (
                old: {
                  buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools ];
                }
              );
            });
        };
      in
      {
        devShells.default = pkgs.mkShell {
          packages = with pkgs; [
            poetry
            pythonEnv
          ];
        };
      }
    );
}

FYI, I use a slightly different way to inject those overrides that works well for me, something like (sorry, I cannot include a real, stripped down example right now):

  ...
  inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; })
    defaultPoetryOverrides,
    mkPoetryEnv;

  myOverrides = defaultPoetryOverrides.overrideOverlay (
    self: super: {
      ismember = super.ismember.overridePythonAttrs (
        old: {
          nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ super.setuptools ];
        }
      );
    }
  );

  myEnv = mkPoetryEnv {
    ...
    overrides = myOverrides;
  };
  ...

In particular, I extend the nativeBuildInputs attribute, not buildInputs.

Hope this helps.