nix-community / poetry2nix

Convert poetry projects to nix automagically [maintainer=@adisbladis,@cpcloud]
MIT License
795 stars 410 forks source link

Building the template project with `--impure` leads to stack overflow #1471

Open KiruyaMomochi opened 7 months ago

KiruyaMomochi commented 7 months ago

Describe the issue

The following code will cause a stack overflow

nix flake new --template github:nix-community/poetry2nix poetry2nix-test
cd poetry2nix-test
touch README.md

nix build --no-link ".#myapp" # will success

nix build --no-link ".#myapp" --impure # will fail
# evaluating derivation 'path:/home/kyaru/Projects/netbox-hwspec/wtf3/poetry2nix-test#myapp'error: stack overflow (possible infinite recursion)

Additional context

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": 1702151865,
        "narHash": "sha256-9VAt19t6yQa7pHZLDbil/QctAgVsA66DLnzdRGqDisg=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "666fc80e7b2afb570462423cb0e1cf1a3a34fedd",
        "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": 1702365004,
        "narHash": "sha256-IRFvmyP1uk1hchRVxaXTqu6YoZCvMM/NVtUf2hD2Tag=",
        "owner": "nix-community",
        "repo": "poetry2nix",
        "rev": "c12ac880114d52a3cad5fa02b00f2e2090e89982",
        "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
}
iwinux commented 7 months ago

I've encountered something similar.

nix eval --impure --debug --show-trace --trace-function-calls shows me this:

function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456440872563
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456440946738
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:95 at 1703265456440954032
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:5 at 1703265456440960798
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456440967343
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456441069469
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456441076935
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456441096449
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456441103568
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456441179796
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:95 at 1703265456441187306
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:5 at 1703265456441199265
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456441206160
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456441282257
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456441290068
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456441306191
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456441313115
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456441398640
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:95 at 1703265456441409378
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:5 at 1703265456441429714
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456441439923
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456441597035
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456441610554
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456441637580
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456441650788
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456441876004
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:95 at 1703265456441889492
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:5 at 1703265456441902334
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456441914641
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456442162359
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456442175228
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456442218411
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456442232762
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456442359550
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:95 at 1703265456442379811
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:5 at 1703265456442400564
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456442409505
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456442692067
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456442705107
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456442743292
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456442755318
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456443023764
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:95 at 1703265456443034688
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:5 at 1703265456443044074
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456443052842
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456443326743
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456443337792
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456443356274
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456443365799
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:188:19 at 1703265456443639703
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:95 at 1703265456443649965
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:5 at 1703265456443659081
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456443667829
function-trace exited /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:20 at 1703265456443956018
function-trace entered /nix/store/sd160y3xyy80h9y1kdy7566fnw4pn5f3-source/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix:192:48 at 1703265456443967684
voidus commented 6 months ago

I had this problem because I was passing a filtered fileset to projectDir. I fixed it by passing the full folder to projectDir and the filtered fileset to src, not sure about the caching implications.

The template project passes the flake self to projectDir, which seems weird to me.

The problem is that this function from lib.nix doesn't have a base case if there is no .git, it just keeps adding /../ to the path forever:

  # Find gitignore files recursively in parent directory stopping with .git
  findGitIgnores = path:
    let
      parent = builtins.trace path (path + "/..");
      gitIgnore = path + "/.gitignore";
      isGitRoot = builtins.pathExists (path + "/.git");
      hasGitIgnore = builtins.pathExists gitIgnore;
      gitIgnores = if hasGitIgnore then [ gitIgnore ] else [ ];
    in
    lib.optionals (builtins.pathExists path && builtins.toString path != "/" && ! isGitRoot) (findGitIgnores parent) ++ gitIgnores;
Kiskae commented 4 months ago

Ran into the same issue @voidus described with a filtered fileset as an input to projectDir. Making things more complicated is that it sometimes works just fine, but has a stack overflow on CI.

leonardp commented 4 months ago

I also ran into this issue. Adding a README.md didn't help, however replacing projectDir = self; with projectDir = ./.; in the template flake.nix fixed this issue for me.