1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-12-10 11:01:09 +01:00

modules/lsp: fix mkServerOption homepage tryEval evaluation

`lib.pipe` strictly evaluates intermediate steps using `foldl'`. As a
result, piping `(opts: opts.package.default or null)` →
`(package: (tryEval package).value)` is ineffective because
`opts.package.default` is evaluated before `tryEval` can catch exceptions.

Instead, inline `opts.package.default` directly into the `tryEval`
expression, ensuring missing package errors caught correctly.

Resolves errors when building NixOS or nix-darwin docs that include
Nixvim options.

Adds a regression test.
This commit is contained in:
Matt Sturgeon 2025-12-08 07:25:56 +00:00 committed by Gaétan Lepage
parent 6ab2b305da
commit 463fb0ad5d
2 changed files with 52 additions and 4 deletions

View file

@ -40,10 +40,10 @@ let
# Get suboptions of `lsp.servers.<name>`
(opts: opts.${name}.type.getSubOptions opts.${name}.loc)
# Get the default package
(opts: opts.package.default or null)
# The default throws if mkPackageOption can't find the package
# E.g. mismatched nixpkgs revision
(package: (builtins.tryEval package).value)
#
# Use tryEval to catch throws when mkPackageOption can't find the package,
# e.g., due to a mismatched nixpkgs revision
(opts: (builtins.tryEval (opts.package.default or null)).value)
# Get package's homepage
(package: package.meta.homepage or null)
];

View file

@ -1,3 +1,4 @@
{ pkgs }:
{
example = {
lsp.servers = {
@ -254,4 +255,51 @@
}
];
};
# Regression test for mkServerOption:
# Ensures tryEval catches missing packages when evaluating the description.
# See https://github.com/nix-community/nixvim/issues/4033
missing-package =
{ lib, options, ... }:
let
# `lsp.servers.lua_ls` option
serverOpt = lib.pipe options.lsp.servers [
(opt: opt.type.getSubOptions opt.loc)
(opts: opts.lua_ls)
];
# `lsp.servers.lua_ls.package` option
packageOpt = (serverOpt.type.getSubOptions serverOpt.loc).package;
# The lua_ls package attr to remove from pkgs
packageName = lib.pipe ../../../plugins/lsp/lsp-packages.nix [
import
(lib.getAttr "packages")
(lib.getAttr "lua_ls")
lib.toList
lib.head
];
in
{
# Remove lua_ls's package
_module.args.pkgs = lib.mkOverride 0 (lib.removeAttrs pkgs [ packageName ]);
assertions = [
{
# Expect the lua_ls description to evaluate without a link
assertion = serverOpt.description == "The lua_ls language server.\n";
message = ''
Wrong description for `${serverOpt}`. Found:
${serverOpt.description}
'';
}
{
# Expect the package default to throw
assertion = !(builtins.tryEval packageOpt.default).success;
message = "Expected `${packageOpt}`'s default to throw.";
}
];
test.buildNixvim = false;
};
}