Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] derivations cause infinite recursion in toLuaObject #1888

Closed
1 task done
SuperSandro2000 opened this issue Jul 18, 2024 · 4 comments · Fixed by #1912
Closed
1 task done

[BUG] derivations cause infinite recursion in toLuaObject #1888

SuperSandro2000 opened this issue Jul 18, 2024 · 4 comments · Fixed by #1912
Labels
bug Something isn't working

Comments

@SuperSandro2000
Copy link
Member

Field Description
Plugin typos-lsp
Nixpkgs nixos-unstable
Home Manager none
  • I have read the FAQ and my bug is not listed there.

Description

When adding a derivation inside of plugins.lsp.servers.typos-lsp.settings it is not automatically turned into a store path but an infinite recursion occurs.

The end of the errors is:

       error: stack overflow; max-call-depth exceeded
       at /nix/store/sxfqjpw542sjv2jmnx1fiqn9fg0v6s9m-source/lib/trivial.nix:277:13:
          276|     x:
          277|     y: x // y;
             |             ^
          278|

Minimal, Reproducible Example (MRE)

programs.nixvim = {
  plugins.lsp = {
    enable = true;
    servers = {
      typos-lsp = {
        enable = true;
        settings = {
          init_options.config = pkgs.writeText "typos-lsp-config" /* yaml */ ''
            default.extend-words:
              - mosquitto
          '';
        };
      };
    };
  };
}

Changing the config to :

programs.nixvim = {
  plugins.lsp = {
    enable = true;
    servers = {
      typos-lsp = {
        enable = true;
        settings = {
          init_options.config = toString (pkgs.writeText "typos-lsp-config" /* yaml */ ''
            default.extend-words:
              - mosquitto
          '');
        };
      };
    };
  };
}

works as expected and I would expect that this automatically happens.

Full log: https://gist.github.com/SuperSandro2000/ebe7af677a61337404703b3358f0f35a

@SuperSandro2000 SuperSandro2000 added the bug Something isn't working label Jul 18, 2024
@MattSturgeon
Copy link
Member

Wh as t would happen if we didn't have a init_options.config option and the definition instead relied on the freeformType?

I agree, the ideal thing would be for derivations to automatically be stringified to their store path, but I think it's also important for this kinda thing to behave consistently throughout nixvim.

For this specific option we could have type = coercedTo package toString str, but if we do this here how do we decide which other places should have similar coercion?

@SuperSandro2000
Copy link
Member Author

We could run mapAttrsRecursive and convert all derivations to strings. Not sure if all plugins use a some wrapper we could unite this under.

@MattSturgeon
Copy link
Member

Ah, I haven't studied the stack trace, but this is probably an edge case toLuaObject should be handling.

It's possible the error is happening when we try and print the attrs as a lua string.

@MattSturgeon
Copy link
Member

Yes, near the end of the trace it shows toLuaObject runs into infinite recursion within its removeEmptiesRecursive pre-processing helper.

@MattSturgeon MattSturgeon changed the title [BUG] need to stringify paths in plugins.lsp.servers.*.settings to avoid infinite recursion [BUG] derivations cause infinite recursion in toLuaObject Jul 18, 2024
MattSturgeon added a commit to MattSturgeon/nixvim that referenced this issue Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants