oxalica / nil

NIx Language server, an incremental analysis assistant for writing in Nix.
Apache License 2.0
1.32k stars 39 forks source link

Allow for annotating types. #87

Open ehllie opened 1 year ago

ehllie commented 1 year ago

I've noticed that in recent versions of nil, there is now inference for attributes inside module arguments like config:

image

It's definitely very convenient when writing NixOS modules, but they don't exactly align with the the config options when writing something like a home-manager or nix-darwin module. Trying to dynamically infer it might be possible, but I think it might be more difficult, and not always possible. That's why I suggest an introduction of a type comment syntax/system for annotating these things manually. That way one could write something along the lines of:

# @type home-manager.module
{ config, pkgs, ... }:
{
...
}

This would obviously not be a small feature, since it would probably require a syntax for defining types, and also a method for flakes to export them, but in my opinion it would be a very useful feature.

bew commented 1 year ago

Might be related: Since https://github.com/NixOS/nixpkgs/pull/197547 evalModules function has a class parameter which can be used to give a type to modules.

oxalica commented 1 year ago

but they don't exactly align with the the config options when writing something like a home-manager or nix-darwin module.

Currently NixOS options are extracted using a handcrafted Nix here and it's coupling with nixpkgs. I'm not sure if we could somehow extract options from the home-manager module in a similar way.

Might be related: Since NixOS/nixpkgs#197547 evalModules function has a class parameter which can be used to give a type to modules.

It is just a string identifier. It cannot help with types.