nixd icon indicating copy to clipboard operation
nixd copied to clipboard

`home-manager` options suggested in `nixosConfigurations` and vice-versa

Open shivaraj-bh opened this issue 1 year ago • 9 comments

To reproduce follow the getting started instructions for neovim.

Attaching the screenshot for clarity: Screenshot 2024-04-30 at 10 45 46 AM

shivaraj-bh avatar Apr 30 '24 06:04 shivaraj-bh

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.

inclyc avatar Apr 30 '24 14:04 inclyc

May I close this issue? @shivaraj-bh

inclyc avatar May 02 '24 03:05 inclyc

Alright, this can be closed for now then

shivaraj-bh avatar May 02 '24 06:05 shivaraj-bh

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!

emilazy avatar Jul 05 '24 09:07 emilazy

(Some more ecosystem support: flake-parts uses "flake" and "perSystem".)

emilazy avatar Jul 06 '24 05:07 emilazy

Would you be open to considering the _class module type‐checking attribute to narrow this down?

Yes, we can do, let's reopen this.

inclyc avatar Jul 07 '24 18:07 inclyc

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:

  1. Check if the current file is under a path that would make it only valid for home-manager options and if it is move to 2
  2. In the nixd configuration provide an invalid option set to the nixd.options.nixos.expr setting (something like {}, an empty attrset)
  3. Specify a valid home_manager option set
  4. Update the nixd configuration via workspace/configuration
  5. ???
  6. no more NixOS options for a home manager specific module in theory
  7. 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.

PriceHiller avatar Aug 31 '24 09:08 PriceHiller

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.

Lillecarl avatar Jul 22 '25 13:07 Lillecarl

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

nixos-discourse avatar Oct 25 '25 14:10 nixos-discourse