Really weird. I use coc.nvim :
~/.config/nvim/coc-settings.json
:
"languageserver": {
"nix": {
"command": "nixd",
"filetypes": ["nix"]
}
}
However, in /etc/nixos/configuration.nix
, press n
will get some completions like nix
, nixpkgs
. press nix.
will get not any completion. Does it need any configuration?
{ config, pkgs, ... }:
rec {
...
}
inclyc
July 8, 2023, 8:00pm
22
I have read and git clone the example code and try to edit. There are some comments in the example code like press . will complete XXX
but they does not work for me. I donāt know what something I miss
TLATER
July 9, 2023, 10:16am
24
You do need to configure it for your repository: https://github.com/nix-community/nixd/blob/96cc1f7290902caefbc2bf265540279f4543ea66/docs/user-guide.md#options
<flakeref>
and <name>
are not literal, thatās supposed to be the specific nixosConfigurations
attribute you want to evaluate. For a non-flake setup presumably you just point it at configuration.nix
(some clarification @inclyc ?).
There are some other settings that look like they need to be set as well, the docs arenāt particularly clear on what is required for which use cases (and donāt cover use cases like multi-output flakes - though I suspect thatās just setting multiple installables).
Iāve yet to get a config working too, wasnāt trying too hard. Gave up for now when it started segfaulting and freezing my editor.
The following example comes from https://github.com/nix-community/nixd/blob/96cc1f7290902caefbc2bf265540279f4543ea66/docs/user-guide.md#evaluation .
$ cat .nixd.json
{
"eval": {
"target": {
"args": [
"--expr",
"with import <nixpkgs> { }; callPackage ./some-package.nix { } "
],
"installable": ""
}
}
}
$ cat some-package.nix
{ stdenv
, lib
}:
stdenv.mkDerivation {
pname = "...";
version = "...";
}
$ jq '.languageserver.nix' ~/.config/nvim/coc-settings.json
{
"command": "nixd",
"filetypes": [
"nix"
]
}
$ vi some-package.nix
Press 2ji, p
, the result is
I hope it can complete some package started with p
like python
, but it complete some weird placeholder
.
1 Like
And this is output of nixd:
$ nixd
Please file an issue at https://github.com/nix-community/nixd/issues/
nixd version: 1.1.0
Previous run crashed:
0# nixd::sigHandler(int) in nixd
1# 0x00007F231A052D30
2# 0x00007F231A0A1A8C
3# 0x00007F231A052C86
4# 0x00007F231A03C8BA
5# 0x00007F231A2A9A89
6# 0x00007F231A2B4F8A
7# 0x00007F231A2B3FF9
8# 0x00007F231A2B4716
9# 0x00007F2323262864
10# 0x00007F2323262F21
11# 0x00007F231A2B523A
12# 0x00007F231A2AC713
13# 0x00007F231A2E067E
14# nixd::Server::~Server() in nixd
15# main in nixd
16# 0x00007F231A03DACE
17# 0x00007F231A03DB89
18# _start in nixd
I[03:13:50.021] 3860865: nixd 1.1.0 started
E[03:13:50.023] 3860882: created child worker process 3860882
E[03:13:50.025] 3860884: created child worker process 3860884
warning: unknown setting 'allowed-users'
warning: unknown setting 'trusted-users'
E[03:13:50.027] 3860887: created child worker process 3860887
warning: unknown setting 'allowed-users'
warning: unknown setting 'trusted-users'
warning: unknown setting 'allowed-users'
warning: unknown setting 'trusted-users'
I[03:13:50.032] 3860884: --> notify nixd/ipc/diagnostic
I[03:13:50.032] 3860884: --> notify nixd/ipc/diagnostic
I[03:13:50.033] 3860884: --> notify nixd/ipc/finished
I[03:13:50.033] 3860865: <-- nixd/ipc/diagnostic
I[03:13:50.033] 3860865: received diagnostic from worker: 2
I[03:13:50.033] 3860865: <-- nixd/ipc/diagnostic
I[03:13:50.033] 3860865: received diagnostic from worker: 2
I[03:13:50.033] 3860865: <-- nixd/ipc/finished
I[03:13:50.034] 3860887: --> notify nixd/ipc/diagnostic
I[03:13:50.034] 3860887: evaluation on installable , requested depth: 0
I[03:13:50.034] 3860865: <-- nixd/ipc/diagnostic
I[03:13:50.034] 3860865: received diagnostic from worker: 2
I[03:13:50.458] 3860887: evaluation done on worspace version: 2
I[03:13:50.458] 3860887: --> notify nixd/ipc/diagnostic
I[03:13:50.458] 3860887: --> notify nixd/ipc/finished
I[03:13:50.458] 3860865: <-- nixd/ipc/diagnostic
I[03:13:50.459] 3860865: received diagnostic from worker: 2
I[03:13:50.459] 3860865: <-- nixd/ipc/finished
To tell the truth, I like the name of nixd which recall me the good experience from clangd. However, I really cannot make it work for me
inclyc
July 10, 2023, 3:29am
27
You are writing a lambda which has some formal args, and these formals are not required to be a package name for callPackage
. Actually it can be anything. Can you try some completion task from the examples?
Join our matrix group so that you can get real-time technical support.
And looks like the server crashed for some reason. How about compiling the main brach from source?
inclyc
July 10, 2023, 3:45am
28
v1.1.0 has some known bugs in the option system (missing error handling) and the nix library itself.
I have known what happened:
The following can work for me:
git clone --depth=1 https://github.com/nix-community/nixd
cd nixd/docs/examples/options/nixos
vi module.nix
The following cannot work:
git clone --depth=1 https://github.com/nix-community/nixd
vi nixd/docs/examples/options/nixos/module.nix
.nixd.json
only work when it exist current working directory. Is it right?
Sometimes nixd-backtrace.dump
will be generated. Why not put them to ~/.cache/nixd
to avoid users git add
them accidentally?
1 Like
inclyc
July 10, 2023, 6:43am
30
mark.c
August 15, 2023, 6:47am
31
Thank you @inclyc for this excellent project.
I canāt find a way in vscode to disable this popup:
It happens often - for example when I open a new (unsaved) file and vscode assumes that itāll have Nix code in it.
I understand reason for the failure but I have no way to mute the warnings and it happens too often - itās really annoying. Could you please help?
inclyc
August 15, 2023, 6:50am
32
Submit an issue in the repo? It should be suppressed I guess.
mark.c
August 15, 2023, 7:18am
33
mark.c
June 9, 2024, 9:44am
34
Hi @inclyc ,
I recently upgraded to 24.05 and also upgraded nixd, vscodium and jnoortheen.nix-ide and the most visible update is definitely nixd . Great new features, thank you!
Could you please advise how to disable unused binding warning?
Iām getting a lot of:
definition `config` is not used
nixf(sema-def-not-used) [Ln 67, Col 22]
Iāll eventually fix it but at this moment I get too many warnings and itās overwhelming.
I figured out that I need to pass some flag into my VSCodium config but I canāt figure out howā¦
{
// ...
"[nix]": {
"editor.tabSize": 4,
"editor.formatOnPaste": false,
"editor.hover.enabled": false
},
"nix.enableLanguageServer": true,
// "rnix-lsp", "nil", "nixd"
"nix.serverPath": "nixd",
"nix.serverSettings": {
// settings for 'nixd' LSP
"nixd": {
"eval": {
// stuff
},
"formatting": {
"command": "nixpkgs-fmt"
},
"options": {
"enable": true,
"target": {
// tweak arguments here
"args": []
// NixOS options
// "installable": "<flakeref>#nixosConfigurations.<name>.options"
// Flake-parts options
// "installable": "<flakeref>#debug.options"
// Home-manager options
// "installable": "<flakeref>#homeConfigurations.<name>.options"
}
}
}
}
// ...
}
inclyc
June 9, 2024, 1:49pm
35
Just read the docs about diagnostic control, it is available since 2.2.0
## Configuration
We support LSP standard `workspace/configuration` for server configurations.
### Default configuration & Who needs configuration
Most important part of package/options features is the path of "nixpkgs".
By default, this is search via standard nix search path.
That is, find nixpkgs via `<nixpkgs>`.
For nix-channels users: nixos option & package features shall work out of box, without any extra effort.
For nix-flake users: (suggestion) you can set $NIX_PATH env to your flake input. e.g.
```nix
{ inputs, ... }:
{
# NixOS configuration.
nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
This file has been truncated. show original
mark.c
June 10, 2024, 10:42am
36
Thank you. I changed my settings but I donāt see any effect.
"nix.serverSettings": {
"nixd": {
"eval": {},
"formatting": {
"command": "nixpkgs-fmt"
},
"diagnostic": {
"suppress": [
"sema-def-not-used"
]
},
"options": {
"enable": true,
"target": {}
}
}
},
inclyc
June 10, 2024, 5:20pm
37
Maybe you are using some outdated releases. Also the configuration basically changed in version 2.0, and not backward-compatible. Please read the docs on github
I have the same problem - the config has no effect.
I copy/pasted the config from the readme:
{
"nix.enableLanguageServer": true,
"nix.serverPath": "nixd",
"nix.serverSettings": {
"nixd": {
"eval": {},
"formatting": {
"command": "nixpkgs-fmt"
},
"diagnostic": {
"suppress": [
"sema-escaping-with",
"sema-unused-rec",
"sema-def-not-used"
]
},
"options": {
"enable": true,
"target": {}
}
}
}
}
and all my packages are from flaked NixOS 24.05 so everything is up-to-date.
inclyc
June 11, 2024, 10:30am
39
The config you pasted here is apparently outdated. Please read nixd/nixd/docs/configuration.md at be5ad5ec113595e2900e6391a08cf0e4784a9cfe Ā· nix-community/nixd Ā· GitHub
VSCode extensions usually have long release cycle and you may read some outdated docs on the marketplace.
Specifically eval
should be removed at all. Then formatting
command is an array.
2 Likes
Thank you. I can see the difference now. To make it as simple as possible, I copy/pasted it without options
and I added diagnostic
from Neovim
example (missing in VSCode example):
{
"nix.enableLanguageServer": true,
"nix.serverPath": "nixd",
// https://github.com/nix-community/nixd/blob/6811dcf03ac055752a3f28cbabf90bd0b0cee417/nixd/docs/configuration.md
"nix.serverSettings": {
"nixd": {
"formatting": {
"command": [
"nixpkgs-fmt"
]
},
"diagnostic": {
"suppress": [
"sema-def-not-used"
]
}
}
}
}
I restarted VSCode and: