Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions modules/lsp/servers/custom/hls.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
lib,
pkgs,
config,
options,
...
}:
{
options = {
installGhc = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = "Whether to install `ghc`.";
};

ghcPackage = lib.mkPackageOption pkgs "ghc" { };
};

config = lib.mkIf config.enable {
warnings = lib.nixvim.mkWarnings "lsp.servers.hls" {
when = options.installGhc.highestPrio == 1500;
message = ''
`hls` relies on `ghc` (the Glasgow Haskell Compiler).
- Set `${options.installGhc} = true` to install it automatically with Nixvim.
You can customize which package to install by changing `${options.ghcPackage}`.
- Set `${options.installGhc} = false` to not have it install through Nixvim.
By doing so, you will dismiss this warning.
'';
};

packages = lib.mkIf config.installGhc {
${if config.packageFallback then "suffix" else "prefix"} = [
config.ghcPackage
];
};
};
}
40 changes: 22 additions & 18 deletions plugins/lsp/language-servers/hls.nix
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
{
config,
lib,
pkgs,
config,
options,
...
}:
let
cfg = config.plugins.lsp.servers.hls;
inherit (lib) types;
opts = options.plugins.lsp.servers.hls;
enabled = config.plugins.lsp.enable && cfg.enable;

ghcPackage = lib.optional (cfg.installGhc == true) cfg.ghcPackage;
# The new `installGhc` option doesn't support null values, so check how the old value is defined
installGhcValue =
lib.modules.mergeDefinitions opts.installGhc.loc opts.installGhc.type
opts.installGhc.definitionsWithLocations;
useInstallGhcValue = installGhcValue.optionalValue.value or null != null;
in
{
options.plugins.lsp.servers.hls = {
installGhc = lib.mkOption {
type = with types; nullOr bool;
type = lib.types.nullOr lib.types.bool;
default = null;
example = true;
description = "Whether to install `ghc`.";
apply = v: if enabled then config.lsp.servers.hls.installGhc else v;
};

ghcPackage = lib.mkPackageOption pkgs "ghc" { };
ghcPackage = lib.mkPackageOption pkgs "ghc" { } // {
apply = v: if enabled then config.lsp.servers.hls.ghcPackage else v;
};
};

config = lib.mkIf cfg.enable {
warnings = lib.nixvim.mkWarnings "plugins.lsp.servers.hls" {
when = cfg.installGhc == null;
message = ''
`hls` relies on `ghc` (the Glasgow Haskell Compiler).
- Set `plugins.lsp.servers.hls.installGhc = true` to install it automatically with Nixvim.
You can customize which package to install by changing `plugins.lsp.servers.hls.ghcPackage`.
- Set `plugins.lsp.servers.hls.installGhc = false` to not have it install through Nixvim.
By doing so, you will dismiss this warning.
'';
config = lib.mkIf enabled {
lsp.servers.hls = {
installGhc = lib.mkIf useInstallGhcValue (
lib.modules.mkAliasAndWrapDefsWithPriority lib.id opts.installGhc
);
ghcPackage = lib.mkIf (opts.ghcPackage.highestPrio < 1500) (
lib.modules.mkAliasAndWrapDefsWithPriority lib.id opts.ghcPackage
);
};

extraPackages = lib.optionals (!cfg.packageFallback) ghcPackage;
extraPackagesAfter = lib.optionals cfg.packageFallback ghcPackage;
};
}
2 changes: 2 additions & 0 deletions tests/test-sources/modules/lsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
hls = {
enable = true;
packageFallback = true;
installGhc = true;
};
};
};
Expand Down Expand Up @@ -219,6 +220,7 @@
assertPrefix "nil" nil_ls.package
++ assertSuffix "rust-analyzer" rust_analyzer.package
++ assertSuffix "haskell-language-server" hls.package
++ assertSuffix "ghc" hls.ghcPackage
);
};
}