poetry2nix icon indicating copy to clipboard operation
poetry2nix copied to clipboard

Provided template fails to build

Open steinerkelvin opened this issue 1 year ago • 7 comments

Describe the issue

Getting the template with

nix flake init --template github:nix-community/poetry2nix

then running:

nix build

gets me the following error:

error: builder for '/nix/store/bb8867hy0mqwxw2ab2bciygihl4s1wnm-python3.11-app-0.1.0.drv' failed with exit code 1;
       last 10 log lines:
       >                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/pvfrrm2wba6w76y4qbmmm7l2kmpbszbx-python3.11-poetry-core-1.7.0/lib/python3.11/site-packages/poetry/core/masonry/metadata.py", line 58, in from_package
       >     with readme.open(encoding="utf-8") as f:
       >          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/qp5zys77biz7imbk6yy85q5pdv7qk84j-python3-3.11.6/lib/python3.11/pathlib.py", line 1044, in open
       >     return io.open(self, mode, buffering, encoding, errors, newline)
       >            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       > FileNotFoundError: [Errno 2] No such file or directory: '/build/source/README.md'
       >
       > ERROR Backend subprocess exited when trying to invoke build_wheel
       For full logs, run 'nix log /nix/store/bb8867hy0mqwxw2ab2bciygihl4s1wnm-python3.11-app-0.1.0.drv'.

Additional context

flake.nix:

{
  description = "Application packaged using poetry2nix";

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

  outputs = { self, nixpkgs, flake-utils, poetry2nix }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        # see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
        pkgs = nixpkgs.legacyPackages.${system};
        inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication;
      in
      {
        packages = {
          myapp = mkPoetryApplication { projectDir = self; };
          default = self.packages.${system}.myapp;
        };

        devShells.default = pkgs.mkShell {
          inputsFrom = [ self.packages.${system}.myapp ];
          packages = [ pkgs.poetry ];
        };
      });
}

pyproject.toml:

[tool.poetry]
name = "app"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"

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


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

poetry.lock:

[tool.poetry]
name = "app"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"

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


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

steinerkelvin avatar Nov 30 '23 21:11 steinerkelvin

Ok, just realized that touching a README.md solves it. I guess we should add a README.md to the template.

steinerkelvin avatar Nov 30 '23 21:11 steinerkelvin

Aside from a README, I have other issues straight out of the box:

$ pushd $(mktemp -d)

$ nix flake init --template github:nix-community/poetry2nix
wrote: /private/var/folders/tc/rq67x3pj0l3_8wp74fv_4vl80000gn/T/tmp.1UisMXt6/app/__init__.py
wrote: /private/var/folders/tc/rq67x3pj0l3_8wp74fv_4vl80000gn/T/tmp.1UisMXt6/app
wrote: /private/var/folders/tc/rq67x3pj0l3_8wp74fv_4vl80000gn/T/tmp.1UisMXt6/pyproject.toml
wrote: /private/var/folders/tc/rq67x3pj0l3_8wp74fv_4vl80000gn/T/tmp.1UisMXt6/flake.nix
wrote: /private/var/folders/tc/rq67x3pj0l3_8wp74fv_4vl80000gn/T/tmp.1UisMXt6/poetry.lock

$ nix develop
warning: creating lock file '/private/var/folders/tc/rq67x3pj0l3_8wp74fv_4vl80000gn/T/tmp.1UisMXt6/flake.lock'
error: builder for '/nix/store/6rr9j6abzkk86fvdbvaqq0y0xy7ln7fa-python3.11-poetry-1.7.1.drv' failed with exit code 1;
       last 10 log lines:
       > OK
       > /private/tmp/nix-build-python3.11-poetry-1.7.1.drv-0/source
       > Finished executing pypaBuildPhase
       > buildPhase completed in 36 seconds
       > Running phase: pythonRuntimeDepsCheckHook
       > Executing pythonRuntimeDepsCheck
       > Checking runtime dependencies for poetry-1.7.1-py3-none-any.whl
       >   - fastjsonschema not installed
       >   - platformdirs<4.0.0,>=3.0.0 not satisfied by version 4.0.0
       >   - xattr<0.11.0,>=0.10.0 not satisfied by version 1.0.0
       For full logs, run 'nix log /nix/store/6rr9j6abzkk86fvdbvaqq0y0xy7ln7fa-python3.11-poetry-1.7.1.drv'.
error: 1 dependencies of derivation '/nix/store/6j24d8gdhb8nqm1p2snyqa39qpdjzrkq-nix-shell-env.drv' failed to build
flake.lock
{
  "nodes": {
    "flake-utils": {
      "inputs": {
        "systems": "systems"
      },
      "locked": {
        "lastModified": 1701680307,
        "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "flake-utils_2": {
      "inputs": {
        "systems": "systems_2"
      },
      "locked": {
        "lastModified": 1694529238,
        "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "nix-github-actions": {
      "inputs": {
        "nixpkgs": [
          "poetry2nix",
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1698974481,
        "narHash": "sha256-yPncV9Ohdz1zPZxYHQf47S8S0VrnhV7nNhCawY46hDA=",
        "owner": "nix-community",
        "repo": "nix-github-actions",
        "rev": "4bb5e752616262457bc7ca5882192a564c0472d2",
        "type": "github"
      },
      "original": {
        "owner": "nix-community",
        "repo": "nix-github-actions",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1705133751,
        "narHash": "sha256-rCIsyE80jgiOU78gCWN3A0wE0tR2GI5nH6MlS+HaaSQ=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "9b19f5e77dd906cb52dade0b7bd280339d2a1f3d",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixos-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "poetry2nix": {
      "inputs": {
        "flake-utils": "flake-utils_2",
        "nix-github-actions": "nix-github-actions",
        "nixpkgs": [
          "nixpkgs"
        ],
        "systems": "systems_3",
        "treefmt-nix": "treefmt-nix"
      },
      "locked": {
        "lastModified": 1705060653,
        "narHash": "sha256-puYyylgrBS4AFAHeyVRTjTUVD8DZdecJfymWJe7H438=",
        "owner": "nix-community",
        "repo": "poetry2nix",
        "rev": "e0b44e9e2d3aa855d1dd77b06f067cd0e0c3860d",
        "type": "github"
      },
      "original": {
        "owner": "nix-community",
        "repo": "poetry2nix",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "flake-utils": "flake-utils",
        "nixpkgs": "nixpkgs",
        "poetry2nix": "poetry2nix"
      }
    },
    "systems": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "owner": "nix-systems",
        "repo": "default",
        "type": "github"
      }
    },
    "systems_2": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "owner": "nix-systems",
        "repo": "default",
        "type": "github"
      }
    },
    "systems_3": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "id": "systems",
        "type": "indirect"
      }
    },
    "treefmt-nix": {
      "inputs": {
        "nixpkgs": [
          "poetry2nix",
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1699786194,
        "narHash": "sha256-3h3EH1FXQkIeAuzaWB+nK0XK54uSD46pp+dMD3gAcB4=",
        "owner": "numtide",
        "repo": "treefmt-nix",
        "rev": "e82f32aa7f06bbbd56d7b12186d555223dc399d1",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "treefmt-nix",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}

ches avatar Jan 14 '24 09:01 ches

@ches This obviously isn't a proper fix, but I just ran into this same problem and found that pinning nixpkgs to 23.11 instead of unstable made my devshell build properly

ciarandg avatar Jan 14 '24 19:01 ciarandg

Note the timestamps, above. First there was activity in November, and then there was three of us here within 12 hours. I think there was a recent change that made this suddenly more relevant. Personally, I'm here because I'm running into the error that @ches has shared above (xattr<0.11.0,>=0.10.0 not satisfied by version 1.0.0)

MatrixManAtYrService avatar Jan 14 '24 20:01 MatrixManAtYrService

Indeed, the addition of the pythonRuntimeDepsCheck hook was merged to nixpkgs master around Dec. 20th:

https://github.com/NixOS/nixpkgs/commit/8f3162f83fcccf26bf50c55ff960fd2dee5264b2

Not in a stable release yet as of now, hence @ciarandg's observation for pinning stable.

ches avatar Jan 15 '24 04:01 ches

The old behavior can be restored by adding dontCheckRuntimeDeps = true to your derivation, disabling the check. This might be indicative of an underlying issue, though, so it's a temporary fix.

More details at NixOS/nixpkgs#250865. This went in with the last staging merge, which was three days ago.

DeeUnderscore avatar Jan 15 '24 05:01 DeeUnderscore

FWIW: For Poetry fastjsonschema and platformdirs dep checks now fixed on nixpkgs master:

https://github.com/NixOS/nixpkgs/issues/281034#issuecomment-1891113369

xattr still seems overlooked as a Darwin-specific dependency.

Anyway we can probably conclude that these issues are upstream, and scope this issue back down to the OP's suggestion: include a dummy README.md in the template, or perhaps the problem can be avoided by removing readme = "README.md" from the generated pyproject.toml.

Apologies for the detour.

ches avatar Jan 15 '24 08:01 ches