nixd
nixd copied to clipboard
`home-manager` options suggested in `nixosConfigurations` and vice-versa
To reproduce follow the getting started instructions for neovim.
Attaching the screenshot for clarity:
Works as expected.
There is no decent way to determine whether the attribute name will be used as hm, or nixos. Thus I'd like to pop two items for you, and let the user choose proper one.
May I close this issue? @shivaraj-bh
Alright, this can be closed for now then
Would you be open to considering the _class module type‐checking attribute to narrow this down? nix-darwin uses the class "darwin", NixOS uses "nixos", and Home Manager uses "homeManager". (There’s also "nixosTest".) When class is specified to evalModules, any module with a non‐matching _class causes an error.
You could look up options from options.‹_class› according to one of two conditions. The easier one is to use the _class value directly specified in a module, if present. The more general but potentially harder approach is to look at all the modules imported by the current module and inherit the _class if any of them define it.
I’d start declaring the _class in my modules and configurations if this feature was added!
(Some more ecosystem support: flake-parts uses "flake" and "perSystem".)
Would you be open to considering the _class module type‐checking attribute to narrow this down?
Yes, we can do, let's reopen this.
I think a potentially sketchy way of handling this in the short-term is to have a given editor specify the options for nixd based on the current file.
For instance, in a given editor's configuration for home-manager (this would have to be dynamic AFAIK) it could take the following steps:
- Check if the current file is under a path that would make it only valid for
home-manageroptions and if it is move to 2 - In the
nixdconfiguration provide an invalid option set to thenixd.options.nixos.exprsetting (something like{}, an empty attrset) - Specify a valid
home_manageroption set - Update the
nixdconfiguration viaworkspace/configuration - ???
- no more NixOS options for a home manager specific module in theory
- profit
This, of course, wouldn't work if a user is defining home-manager and NixOS options within the top level flake.
Checking the options.<_class> is almost certainly a better solution, but the above may work as a hack now.
Have you considered what other language servers do: support source "annotations" in comments / a comment header. Pythons famous # type: ignore for example, and Vim supports things like sorting arrays automatically based on comments.
# nixdscope: home-manager
# nixdscope: nixos
https://github.com/water-sucks/optnix?tab=readme-ov-file#config-schema This is how optnix supports searching multiple module systems which is very handy and simple.
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/nixd-home-manager-completion-and-standalone-home-manager-outputs/55610/13