oxalica/nil

Allow for annotating types.

Opened this issue · 2 comments

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

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

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.