Hello,
I am using NixOs on the unstable branch and use the Helix flake.
To edit my config I use nil as a language server which is able to show autocompletion for nixpkgs options, but not home-manager and my custom Options. Is there a way to configure it in Helix to look at the flake.nix file to get all the options like is possible in neovim? If not directly from helix options maybe importing nil with some overrides.
I couldn’t really find what i should configure to obtain this result.
If anybody has some ideas you’re welcome.
Thanks
In nixd I am pretty sure you can do it, but you have to modify the specific configuration file of nixd and point to your flake and home-manager, then it should be able to read the option from them. With nvim is doable but with helix I am not sure how declaratively in the helix config. But I guess there should be some parameters to override when the package is called to set this options? I dont know 
This is my setup as part of my home-manager config. It should be as easy as adapting the language
-setting according to nixd/nixd/docs/editor-setup.md at 590eccaa079929daa58316f5386dbcc150e2d50d · nix-community/nixd · GitHub
{
helix,
system,
...
}: {
nixpkgs.overlays = [
(final: previous: {
helix = helix.packages.${system}.default;
})
];
programs.helix = {
enable = true;
defaultEditor = true;
settings = {
editor = {
line-number = "relative";
mouse = false;
bufferline = "multiple";
rulers = [80];
lsp = {
display-inlay-hints = false;
};
cursor-shape = {
insert = "bar";
};
indent-guides = {
render = true;
};
};
keys.normal = {
esc = ["collapse_selection" "keep_primary_selection"];
};
};
languages = {
language = [
{
name = "nix";
auto-format = true;
formatter = {
command = "alejandra";
};
}
{
name = "go";
formatter = {command = "goimports";};
}
];
};
};
}
Yes, I didn’t see that helix had a config option for lsp servers… ops.
I tried different iterations with the reference to the flake or the absolute path or whatever, but I couldn t be able to make it work
. that s the “final” version
language-server.nixd = with pkgs; {
command = "${nixd}/bin/nixd";
auto-format = true;
config = {
nixpkgs = {
expr = "import <nixpkgs> { }";
};
options = {
nixos = {
expr = "(builtins.getFlake \"/etc/nixos/\").nixosConfigurations.${confname}.options";
};
home_manager = {
expr = "(builtins.getFlake \"/etc/nixos/\").homeConfigurations.${confname}.options";
};
};
};
};
At a first glance this doesn’t look wrong to me. Won’t be able to test this myself until the weekend. I suspect hx --health
does return that nixd
is available, right?
Is it just not working for home-manager options? Are you using home-manager stand-alone or as a module?
I am usingit as a module but also configuration custom options are not completed. I tried also referencing the flake with his nix path.
Could it be a problem on how helix for nix render the options? Because I am having trouble also setting the option use-grammar.only, helix keep downloading all the treesitter grammar at each restart, and the two settings have a similar syntax it seems.
Autocompletion works but only for the standard nixpkgs option
If you are using it as a module I don’t think this will work as you are referencing the flake output which you probably don’t have set when using it as a module. You probably have to reference it within your system config.
But shouldnt still get the option from the nixosConfiguration? That is where I imports all the options. I have option defined for the system as well but it is blind to those too
Does it work for nixpkgs? So we find out if it’s related to the whole $confname
part. Probably a stupid question but your flake is in /etc/nixos
, right?
And did you check if this helps? I think as you are using flakes you need to add the nix.nixPath
part. nixd/nixd/docs/configuration.md at 590eccaa079929daa58316f5386dbcc150e2d50d · nix-community/nixd · GitHub
okay, after a nice reboot it works,
I ll write what I have in the config here
language-server.nixd = with pkgs; {
command = "${nixd}/bin/nixd";
auto-format = true;
config.nixd = {
nixpkgs = {
# expr = "import <nixpkgs> { }";
expr = "import (builtins.getFlake \"/etc/nixos/\").inputs.nixpkgs { }";
};
options = {
nixos = {
expr = "(builtins.getFlake \"/etc/nixos/\").nixosConfigurations.${confname}.options";
};
home_manager = {
expr = "(builtins.getFlake \"/etc/nixos/\").homeConfigurations.${confname}.options";
};
};
};
};
It just started working
, let me know if it works for you as well
,
thanks!!
2 Likes
Thanks for keeping sharing your solution.I will try it this weekend.
1 Like