From fec81c89087f2ddc153cdb7dcdd2ed2c89b03b0b Mon Sep 17 00:00:00 2001 From: Sam Grayson Date: Fri, 7 Apr 2023 10:15:47 -0600 Subject: [PATCH 1/2] Add edgecases --- docs/edgecases.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/edgecases.md b/docs/edgecases.md index 0ef8750..e195462 100644 --- a/docs/edgecases.md +++ b/docs/edgecases.md @@ -192,3 +192,24 @@ Resulting override: ); } ``` + +#### Nix evaluation errors + +1. Enable `--show-trace`. +2. Remove packages from the `pyproject.toml`, `rm poetry.lock && nix shell nixpkgs#poetry --command poetry lock`. +3. Try running poetry2nix again. + +By these means, one can bisect the package-set to find the problematic package. + +One error you might run into is an "infinite recursion encountered." If this error indicates this happens happens `while evaluating the attribute 'propagatedBuildInputs' of the derivation 'python${version}-${pkg_name}'`, then it is possible `${pkg_name}` has a recursive dependency. + +For example, this is the abbreviated error message if I try to install `dask[distributed]`: + +``` +error: infinite recursion encountered + … while evaluating the attribute 'propagatedBuildInputs' of the derivation 'python3.11-distributed-2023.3.2' + … while evaluating the attribute 'propagatedBuildInputs' of the derivation 'python3.11-dask-2023.3.2' + … while evaluating the attribute 'propagatedBuildInputs' of the derivation 'python3.11-main-0.1.0' +``` + +This is because `dask[distributed]` depends on `distributed` which depends on `dask`. The solution is to install `dask` (no extras) and `distributed` separately. \ No newline at end of file From df434f193afc467f06183465804d1d9d9f602b8a Mon Sep 17 00:00:00 2001 From: Sam Grayson Date: Fri, 7 Apr 2023 10:38:47 -0600 Subject: [PATCH 2/2] Add Nix expression for multiple overrides --- docs/edgecases.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/edgecases.md b/docs/edgecases.md index e195462..e49f278 100644 --- a/docs/edgecases.md +++ b/docs/edgecases.md @@ -167,6 +167,33 @@ poetry2nix.mkPoetryApplication { } ``` +If you need very many of these overrides or you need to use them twice, consider using something like this. It has less repetition: + +```nix +let + pypkgs-build-requirements = { + tox = [ "hatchling" "hatch-vcs" ]; + universal-pathlib = [ "flit-core" ]; + pygithub = [ "setuptools-scm" ]; + beautifulsoup4 = [ "hatchling" ]; + xyzservices = [ "setuptools" ]; + simpervisor = [ "setuptools" ]; + pandas = [ "versioneer" ]; + }; + p2n-overrides = p2n.defaultPoetryOverrides.extend (self: super: + builtins.mapAttrs (package: build-requirements: + (builtins.getAttr package super).overridePythonAttrs (old: { + buildInputs = (old.buildInputs or [ ]) ++ (builtins.map (pkg: if builtins.isString pkg then builtins.getAttr pkg super else pkg) build-requirements); + }) + ) pypkgs-build-requirements + ); +in + poetry2nix.mkPoetryApplication { + projectDir = ./.; + overrides = p2n-overrides; + } +``` + We recommend that you contribute your changes to `poetry2nix` so that other users can profit from them as well. The specific file with the upstream overrides is [build-systems.json](https://github.com/nix-community/poetry2nix/blob/master/overrides/build-systems.json). It is a simple JSON file which contains the overrides in an array and sorted in alphabetical order.