NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.49k stars 1.5k forks source link

Adding package to devShell causes `error: stack overflow (possible infinite recursion)` #3821

Open colemickens opened 4 years ago

colemickens commented 4 years ago

Describe the bug With this minimal flake.nix:

{
  description = "test";

  inputs = {
    nixpkgs = { url = "github:nixos/nixpkgs/nixos-unstable"; };
  };

  outputs = inputs: let
     pkgsFor = pkgs: system: includeOverlay:
        import pkgs {
          inherit system;
          config.allowUnfree = true;
        };
    in {
    devShell."x86_64-linux" =(
        let
            nixpkgs_ = (pkgsFor inputs.nixpkgs "x86_64-linux" false);
        in
            nixpkgs_.mkShell {
                nativeBuildInputs = with nixpkgs_; [
                    bash cacert
                    azure-cli
                ];
            }
    );
};
}

Note that azure-cli is uncommented. This is not an issue if azure-cli is not present.

If you try to nix --experimental-features 'nix-command flakes' develop, then:

> /tmp/nixFlakes/bin/nix \
  --experimental-features 'nix-command flakes' \
    develop
warning: Git tree '/home/cole/small_repro' is dirty
[1 built, 0.0 MiB DL] error: stack overflow (possible infinite recursion)

Before I made this minimal repro, it was doing this:

querying info about missing pathserror: stack overflow (possible infinite recursion)

Info

[cole@xeep:~/small_repro]$ /tmp/nixFlakes/bin/nix --version
nix (Nix) 2.4pre20200622_334e26b
zimbatm commented 4 years ago

I can reproduce the issue with nixpkgs commit ID c71518e75bf067fb639d44264fdd8cf80f53d75a.

The issue can also be reproduced in the nixpkgs repo when running nix dev-shell .#azure-cli. nix build and nix shell work fine though.

It looks like the issue is on the nixpkgs side. The actionable issue for Nix itself is that there is no feedback about what is causing the stack overflow so it makes it hard to debug.

edolstra commented 4 years ago

The problem is that it's hard to give a useful error message in case of a stack overflow. You can't throw an exception and clean up normally...

FRidh commented 4 years ago

Had this also in case of a Python environment. Using pythonEnv.env "solved" the issue. Note the env is not supposed to be built. Then again, in another case I was able to use the pythonEnv directly with nix develop. Note azure-cli is a Python application.

FRidh commented 4 years ago
  1. Throwing out all propagatedBuildInputs the issue does not show up.
  2. Throwing out only the azure-cli-* propagatedBuildInputs the issue does not show up.
  3. Adding back one of the azure-cli* inputs (azure-batch) the issue does not show up.

Both buildPython* and python.buildEnv call the function requiredPythonModules to traverse all propagatedBuildInputs to select only Python packages of interest. It's all I can think of without any trace.

dasJ commented 4 years ago

I have the same issue with node and it seems like the error is the same as in #3462

0x450x6c commented 3 years ago

I had same issue with nix-shell and unstable version of nix 2.4pre20201102_550e11f.

Found workaround here, but setting ulimit in console didn't help in my case. Then I tried set ulimit for nix-daemon, and it helped: systemd.services.nix-daemon.serviceConfig.LimitSTACKSoft = "infinity";

nixos-discourse commented 3 years ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/to-flake-or-not-to-flake/10047/4

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

roberth commented 1 year ago

The problem is that it's hard to give a useful error message in case of a stack overflow. You can't throw an exception and clean up normally...

We'd have to check for stack overflows in C++ rather than through page mappings. "Prevention is better than cure" kind of situation. If we detect it in C++ we can throw a proper exception and print a trace.