@@ -58,19 +58,10 @@ For vscode users you should write `settings.json`[^settings] like this:
5858 // settings for 'nixd' LSP
5959 "nixd": {
6060 "formatting": {
61- // This is the default if ommited.
62- "command": [ "nixfmt" ]
61+ // ...
6362 },
6463 "options": {
65- // By default, this entriy will be read from `import <nixpkgs> { }`
66- // You can write arbitary nix expression here, to produce valid "options" declaration result.
67- // Tip: for flake-based configuration, utilize `builtins.getFlake`
68- "nixos": {
69- "expr": "(builtins.getFlake \"/absolute/path/to/flake\").nixosConfigurations.<name>.options"
70- },
71- "home-manager": {
72- "expr": "(builtins.getFlake \"/absolute/path/to/flake\").homeConfigurations.<name>.options"
73- }
64+ // ...
7465 }
7566 }
7667 }
@@ -113,7 +104,7 @@ nvim_lsp.nixd.setup({
113104<details >
114105 <summary >Emacs</summary >
115106
116- Configuration via [ lsp-mode] ( https://github.com/emacs-lsp/lsp-mode ) plugin. As of Oct 24, 2024, lsp-mode master has support for nixd autocompletion and formatting options.
107+ Configuration via [ lsp-mode] ( https://github.com/emacs-lsp/lsp-mode ) plugin. As of Oct 24, 2024, lsp-mode master has support for nixd autocompletion and formatting options.
117108
118109 ``` elisp
119110(use-package nix-mode
@@ -162,15 +153,30 @@ nvim_lsp.nixd.setup({
162153 // Tell the language server your desired option set, for completion
163154 // This is lazily evaluated.
164155 " options" : { // Map of eval information
165- // If this is omitted, default search path (<nixpkgs>) will be used.
166- " nixos" : { // This name "nixos" could be arbitrary.
167- // The expression to eval, interpret it as option declarations.
168- " expr" : " (builtins.getFlake \" /home/lyc/flakes\" ).nixosConfigurations.adrastea.options"
169- },
156+ // By default, this entriy will be read from `import <nixpkgs> { }`
157+ // You can write arbitary nix expression here, to produce valid "options" declaration result.
158+ //
159+ // *NOTE*: Replace "<name>" below with your actual configuration name.
160+ // If you're unsure what to use, you can verify with `nix repl` by evaluating
161+ // the expression directly.
162+ //
163+ " nixos" : {
164+ " expr" : " (builtins.getFlake (builtins.toString ./.)).nixosConfigurations.<name>.options"
165+ },
170166
171- // By default there is no home-manager options completion, thus you can add this entry.
167+ // Before configuring Home Manager options, consider your setup:
168+ // Which command do you use for home-manager switching?
169+ //
170+ // A. home-manager switch --flake .#... (standalone Home Manager)
171+ // B. nixos-rebuild switch --flake .#... (NixOS with integrated Home Manager)
172+ //
173+ // Configuration examples for both approaches are shown below.
172174 " home-manager" : {
173- " expr" : " (builtins.getFlake \" /home/lyc/flakes\" ).homeConfigurations.\" lyc@adrastea\" .options"
175+ // A:
176+ " expr" : " (builtins.getFlake (builtins.toString ./.)).homeConfigurations.<name>.options"
177+
178+ // B:
179+ " expr" : " (builtins.getFlake (builtins.toString ./.)).nixosConfigurations.<name>.options.home-manager.users.type.getSubOptions []"
174180 }
175181 },
176182 // Control the diagnostic system
@@ -273,3 +279,41 @@ If you aren't a flakes user with standalone home-manager with a vanilla install
273279 }
274280}
275281```
282+
283+ ## Q & A
284+
285+ ### Home-manager options completion does not work. What is ` homeConfigurations ` ?
286+
287+ See [ configuration overview] ( #configuration-overview ) .
288+ If your home-manager is installed as part of a NixOS module,
289+ the options list can be retrieved like this:
290+
291+ ``` nix
292+ (builtins.getFlake (builtins.toString ./.)).nixosConfigurations.<name>.options.home-manager.users.type.getSubOptions []
293+ ```
294+
295+ ### Still not working?
296+
297+ Try testing your expression in ` nix repl ` . This will help you diagnose evaluation issues.
298+ For example:
299+
300+ ```
301+ nix-repl> (builtins.getFlake (builtins.toString ./.)).nixosConfigurations.<name>.options
302+ error: syntax error, unexpected SPATH, expecting ID or OR_KW or DOLLAR_CURLY or '"'
303+ at «string»:1:65:
304+ 1| (builtins.getFlake (builtins.toString ./.)).nixosConfigurations.<name>.options
305+ | ^
306+ ```
307+
308+ Replace ` <name> ` with your actual configuration name:
309+
310+ ```
311+ nix-repl> (builtins.getFlake (builtins.toString ./.)).nixosConfigurations.adrastea.options
312+ {
313+ _module = { ... };
314+ appstream = { ... };
315+ assertions = { ... };
316+ boot = { ... };
317+ # ... more options ..., this is expected.
318+ }
319+ ```
0 commit comments