Skip to content

Commit 67c1a2d

Browse files
committed
wip - package defaults
1 parent 9caeb51 commit 67c1a2d

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
lines changed

modules/lsp/default.nix

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,67 @@
22
lib,
33
config,
44
options,
5+
pkgs,
56
...
67
}:
78
let
89
inherit (lib) types;
910
inherit (lib.nixvim) toLuaObject;
1011

1112
cfg = config.lsp;
13+
14+
mkServerSubmodule =
15+
{
16+
name ? null,
17+
package ? null,
18+
}:
19+
types.submodule [
20+
./server.nix
21+
{
22+
options.package =
23+
let
24+
extraDescription = ''
25+
26+
27+
Alternatively, the language server should be available on your `$PATH`.
28+
'';
29+
in
30+
if package == null then
31+
lib.mkOption {
32+
type = types.nullOr types.package;
33+
default = null;
34+
description = ''
35+
Package to use for this language server.
36+
${extraDescription}
37+
'';
38+
}
39+
else if lib.isOption package then
40+
package
41+
else
42+
lib.mkPackageOption pkgs name {
43+
nullable = true;
44+
default = package;
45+
inherit extraDescription;
46+
};
47+
}
48+
];
49+
50+
mkServerOption =
51+
name:
52+
{
53+
package ? null,
54+
description ? "The ${name} language server.",
55+
}:
56+
lib.mkOption {
57+
type = mkServerSubmodule { inherit name package; };
58+
inherit description;
59+
default = { };
60+
};
61+
62+
# TODO: generate package defaults from lsp-packages.nix
63+
serverSpecs = {
64+
nixd.package = "nixd";
65+
};
1266
in
1367
{
1468
options.lsp = {
@@ -25,7 +79,11 @@ in
2579
};
2680

2781
servers = lib.mkOption {
28-
type = types.attrsOf (types.submodule ./server.nix);
82+
type = types.submodule {
83+
freeformType = types.attrsOf (mkServerSubmodule { });
84+
options = builtins.mapAttrs mkServerOption serverSpecs;
85+
};
86+
2987
description = ''
3088
LSP servers to enable and/or configure.
3189

modules/lsp/server.nix

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ in
2424
example = false;
2525
};
2626

27-
package = lib.mkOption {
28-
type = with types; nullOr package;
29-
default = null;
30-
description = ''
31-
Package to use for this language server.
32-
33-
Alternatively, the language server should be available on your `$PATH`.
34-
'';
35-
};
36-
3727
config = lib.mkOption {
3828
type = with types; attrsOf anything;
3929
description = ''

0 commit comments

Comments
 (0)