nixd
nixd copied to clipboard
Document how to setup for home-manager's NixOS module
Is your feature request related to a problem? Please describe. I read the documentation and I understood how to setup completion for NixOS and home-manager options when Home-Manager is installed in it's standalone mode, but I cannot make the options show up when using the NixOS Module
Describe the solution you'd like I'd like to make the options to show up. Is it even possible? If so, I believe it should be documented alongside the other examples.
Describe alternatives you've considered N/A
Additional context N/A
Thanks in advance!
I'd like to make the options to show up. Is it even possible?
Yes, it is possible. You can refer to https://github.com/nix-community/nixd/issues/615#issue-2647914685 for a simple solution, (i.e. use getSuboptions).
If so, I believe it should be documented alongside the other examples.
Yes, we can add it to the documentation, or if you figured it out, feel free to make PRs.
Great, that worked perfectly. I'll make a PR to add it to the documentation. Thanks!
For some reason it doesn't work for me. I get this error whenever nixd starts evaluates through LSP:
home-manager eval expr: -32001: The option `<name>.home.stateVersion' was accessed but has no value defined. Try setting the option.
I have the home.stateVersion set in my home-manager configuration.
Here's how I tried to configure nixd:
options = rec {
nixos.expr = "${flake}.nixosConfigurations.${hostname}.options";
home-manager.expr = "${nixos.expr}.home-manager.users.type.getSubOptions []";
};
For some reason it doesn't work for me. I get this error whenever nixd starts evaluates through LSP:
Same here. but it doesn't seem to be a nixd problem...
Nix 2.24.12
Type :? for help.
Loading installable 'git+file:///Users/louis/.config/nix-darwin#'...
Added 2 variables.
nix-repl> darwinConfigurations.nixos.options.home-manager.users.type.getSubOptions []
error:
… in the left operand of the update (//) operator
at /nix/store/n5zhvsrwjrlyaimd3cp7s70j401iycx5-source/lib/types.nix:1027:40:
1026| getSubOptions = prefix: (base.extendModules
1027| { inherit prefix; }).options // optionalAttrs (freeformType != null) {
| ^
1028| # Expose the sub options of the freeform type. Note that the option
… while evaluating the attribute 'options'
at /nix/store/n5zhvsrwjrlyaimd3cp7s70j401iycx5-source/lib/modules.nix:335:9:
334| _type = "configuration";
335| options = checked options;
| ^
336| config = checked (removeAttrs config [ "_module" ]);
… while evaluating the option `<name>.home.stateVersion':
(stack trace truncated; use '--show-trace' to show the full, detailed trace)
error: The option `<name>.home.stateVersion' was accessed but has no value defined. Try setting the option.
I'm certain this exact same eval worked a couple of months back :confused: Same error on both darwin and nixos. I've pinned home-manager to various releases and I still get same error.
@wvffle I found a workaround; If you declare a standalone homeManagerConfiguration (handy to have anyway so that you can port your dotfiles to a non-nixos/darwin system), you can target those options instead:
# flake.nix
homeConfigurations.<hostname> = home-manager.lib.homeManagerConfiguration {
pkgs = import nixpkgs { system = <system>; };
modules = [
./home
];
};
# home/default.nix
home.username = lib.mkDefault <username>;
home.homeDirectory = lib.mkDefault <absPathToHomeDir>;
# home/editor.nix
options = {
nixos.expr = "${flake}.darwinConfigurations.${host}.options";
home-manager.expr = "${flake}.homeConfigurations.${host}.options";
};
@louisdutton that's exactly what I did to workaround the issue. However I'd rather it would be fixed than adding one more configuration just for the sake of nixd working
I've tracked down this problem and found that in my case, stylix along with how I set home.stateVersion was causing it.
You can read more about the specifics of the problem here, but the gist is that stylix tries to access home.stateVersion while declaring an option, which fails if home.stateVersion isn't defined in a module defined by home-manager.sharedModules.
A simple workaround for this is either not to use stylix, or to define home.stateVersion inside of a shared home manager module like this:
home-manager.sharedModules = [{home.stateVersion = "<value>";}];
I am sure that there are other similar causes of this problem.
Until recently, I was also using the homeConfigurations output just for HM completions as mentioned above^1, because following the instructions added in https://github.com/nix-community/nixd/pull/686 didn't show all HM options. Specifically, completions for my own custom modules as well as modules provided by third-party projects (e.g. homeModules.catppuccin from https://github.com/catppuccin/nix) were not showing using the getSubOptions method.
Turns out, the solution was to move those modules from the imports section in my Home Manager config to home-manager.sharedModules. Now there's no need for creating a homeConfigurations flake output.