nix-community / dream2nix

Simplified nix packaging for various programming language ecosystems [maintainer=@DavHau]
https://dream2nix.dev
MIT License
988 stars 122 forks source link

`nix build` fails for a Python project if `click` dependency is installed from a wheel #1008

Open akaihola opened 3 months ago

akaihola commented 3 months ago

In examples/packages/languages/python-local-development/pyproject.toml, the dependencies are:

dependencies = [
  "requests",
  "click @ git+https://github.com/pallets/click.git@main"
]

This builds just fine, and also this seems to work:

dependencies = [
  "requests",
  "click @ git+https://github.com/pallets/click.git@8.1.7"
]

But if I change the click dependency to e.g. "click==8.1.7", "click<8" or just "click", I get this:

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/rhg90jpryc286xn9xjy6qjiaap6pjgdc-source/pkgs/stdenv/generic/make-derivation.nix:331:7

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

         at /nix/store/rhg90jpryc286xn9xjy6qjiaap6pjgdc-source/pkgs/stdenv/generic/make-derivation.nix:378:7:

          377|       depsHostHost                = elemAt (elemAt dependencies 1) 0;
          378|       buildInputs                 = elemAt (elemAt dependencies 1) 1;
             |       ^
          379|       depsTargetTarget            = elemAt (elemAt dependencies 2) 0;

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

       error: assertion '((pyproject != null) -> (format == null))' failed

       at /nix/store/rhg90jpryc286xn9xjy6qjiaap6pjgdc-source/pkgs/development/interpreters/python/mk-python-derivation.nix:156:1:

          155|
          156| assert (pyproject != null) -> (format == null);
             | ^
          157|

Other dependencies from PyPI that I have tried seem to work fine with and without a version specifier.

DavHau commented 3 months ago

I think that issue was fixed by @phaer recently. Can you update your dream2nix version an check again?

akaihola commented 3 months ago

I think that issue was fixed by @phaer recently.

I guess you mean the fix in PR #1001? I actually was already running a version from two days after the fix. Updating to today's main didn't seem to help either:

dream2nix/examples/packages/languages/python-local-development/flake.nix ```nix { description = "Dream2nix example flake"; inputs = { dream2nix.url = "github:nix-community/dream2nix/main"; nixpkgs.follows = "dream2nix/nixpkgs"; }; # ... } ```
dream2nix/examples/packages/languages/python-local-development/pyproject.toml ```toml # ... dependencies = [ "requests", "click" ] # ... ```
$ nix run '.#default.lock' && nix develop ```nix warning: Git tree '/home/akaihola/dream2nix' is dirty warning: updating lock file '/home/akaihola/dream2nix/examples/packages/languages/python-local-development/flake.lock': • Updated input 'dream2nix': 'github:nix-community/dream2nix/1b5e01219a32324c8f6889fe1f4db933ec7932f6' (2024-06-29) → 'github:nix-community/dream2nix/46b6ee6b0bf6e601a0765bffbbd5af9006caa2dc' (2024-07-04) warning: Git tree '/home/akaihola/repos/os/nixos/dream2nix' is dirty Collecting pip==23.1 Using cached pip-23.1-py3-none-any.whl.metadata (4.1 kB) Collecting wheel==0.40.0 Using cached wheel-0.40.0-py3-none-any.whl.metadata (2.1 kB) Using cached pip-23.1-py3-none-any.whl (2.1 MB) Using cached wheel-0.40.0-py3-none-any.whl (64 kB) Installing collected packages: wheel, pip Attempting uninstall: pip Found existing installation: pip 24.0 Uninstalling pip-24.0: Successfully uninstalled pip-24.0 Successfully installed pip-23.1 wheel-0.40.0 [notice] A new release of pip is available: 23.1 -> 24.1.1 [notice] To update, run: python -m pip install --upgrade pip Collecting pdm-backend Using cached pdm_backend-2.3.1-py3-none-any.whl (104 kB) Collecting requests Using cached requests-2.32.3-py3-none-any.whl (64 kB) Collecting click Using cached click-8.1.7-py3-none-any.whl (97 kB) Collecting charset-normalizer<4,>=2 (from requests) Using cached charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (140 kB) Collecting idna<4,>=2.5 (from requests) Using cached idna-3.7-py3-none-any.whl (66 kB) Collecting urllib3<3,>=1.21.1 (from requests) Using cached urllib3-2.2.2-py3-none-any.whl (121 kB) Collecting certifi>=2017.4.17 (from requests) Using cached certifi-2024.7.4-py3-none-any.whl (162 kB) Would install certifi-2024.7.4 charset-normalizer-3.3.2 click-8.1.7 idna-3.7 pdm-backend-2.3.1 requests-2.32.3 urllib3-2.2.2 WARNING: There was an error checking the latest version of pip. lock file written to /home/akaihola/dream2nix/examples/packages/languages/python-local-development/lock.json Add this file to git if flakes is used. warning: Git tree '/home/akaihola/dream2nix' is dirty 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/rhg90jpryc286xn9xjy6qjiaap6pjgdc-source/pkgs/stdenv/generic/make-derivation.nix:331:7 … while evaluating attribute 'buildInputs' of derivation 'nix-shell' at /nix/store/rhg90jpryc286xn9xjy6qjiaap6pjgdc-source/pkgs/stdenv/generic/make-derivation.nix:378:7: 377| depsHostHost = elemAt (elemAt dependencies 1) 0; 378| buildInputs = elemAt (elemAt dependencies 1) 1; | ^ 379| depsTargetTarget = elemAt (elemAt dependencies 2) 0; (stack trace truncated; use '--show-trace' to show the full trace) error: assertion '((pyproject != null) -> (format == null))' failed at /nix/store/rhg90jpryc286xn9xjy6qjiaap6pjgdc-source/pkgs/development/interpreters/python/mk-python-derivation.nix:156:1: 155| 156| assert (pyproject != null) -> (format == null); | ^ 157| ```
phaer commented 3 months ago

$ nix run '.#default.lock' && nix develop

I think using && here isn't ideal. Most of the log comes from nix run .#default.lock which succeeds and correctly locks the latest version of click.

The error is triggered by the second command, while trying to evaluate the devshell. We probably could use an assertion to trigger better errors here or at least include it in the docs but the reason is:

overrides.click.buildPythonPackage.pyproject = true; in default.nix, if you remove that line it should work. This is because using a VCS url like in the example builds from a git clone which includes a pyproject.toml. Using a released version like you do, locks a .whl feel from pypi which does not include a pyproject.toml (and format = "wheel" in the buildPythonpackage arguments)