Skip to content
Merged
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
2 changes: 2 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ lib.makeExtensible (
mkCompositeOption
mkCompositeOption'
mkLazyLoadOption
mkMaybeUnpackagedOption
mkNullOrLua
mkNullOrLua'
mkNullOrLuaFn
Expand All @@ -69,6 +70,7 @@ lib.makeExtensible (
mkPackageOption
mkPluginPackageOption
mkSettingsOption
mkUnpackagedOption
pluginDefaultText
;

Expand Down
38 changes: 38 additions & 0 deletions lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,43 @@ rec {
if cfg ? lazyLoad then lib.literalMD "`false` when lazy-loading is enabled." else true;
example = false;
};

/**
Create an option for a package not currently available in nixpkgs.

The option will throw an error if a value is not explicitly set by the end user.
*/
mkUnpackagedOption =
optionName: packageName:
lib.mkOption {
type = types.nullOr types.package;
description = ''
Package to use for ${packageName}.
Nixpkgs does not include this package, and as such an external derivation or null must be provided.
'';
default = throw ''
Nixvim (${optionName}): No package is known for ${packageName}, to resolve this either:
- install externally and set this option to `null`
- or provide a derviation to install this package
'';
defaultText = lib.literalMD "No package, throws when undefined";
};

/**
Create an option for a package that may not be currently available in nixpkgs.

See `mkUnpackagedOption`
*/
mkMaybeUnpackagedOption =
optionName: pkgs: packageName: package:
if lib.isOption package then
package
else if package != null then
lib.mkPackageOption pkgs packageName {
nullable = true;
default = package;
}
else
mkUnpackagedOption optionName packageName;
}
// removed
27 changes: 5 additions & 22 deletions plugins/by-name/none-ls/_mk-source-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ sourceType: sourceName:
let
inherit (import ./packages.nix lib) packaged;
pkg = packaged.${sourceName};
loc = lib.toList pkg;

cfg = config.plugins.none-ls;
cfg' = config.plugins.none-ls.sources.${sourceType}.${sourceName};
Expand Down Expand Up @@ -41,27 +40,11 @@ in
}
# Only declare a package option if a package is required
// lib.optionalAttrs (packaged ? ${sourceName}) {
package = lib.mkOption (
{
type = lib.types.nullOr lib.types.package;
description =
"Package to use for ${sourceName}."
+ (lib.optionalString (pkg == null) (
"\n\n"
+ ''
Currently not packaged in nixpkgs.
Either set this to `null` and install ${sourceName} outside of nix,
or set this to a custom nix package.
''
));
}
// lib.optionalAttrs (pkg != null) {
default =
lib.attrByPath loc (lib.warn "${lib.concatStringsSep "." loc} cannot be found in pkgs!" null)
pkgs;
defaultText = lib.literalExpression "pkgs.${lib.concatStringsSep "." loc}";
}
);
package =
lib.nixvim.mkMaybeUnpackagedOption "plugins.none-ls.sources.${sourceType}.${sourceName}.package"
pkgs
sourceName
pkg;
};

# TODO: Added 2024-07-16; remove after 24.11
Expand Down
20 changes: 4 additions & 16 deletions plugins/lsp/language-servers/_mk-lsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ in
{
meta.nixvimInfo = {
# TODO: description
url = args.url or opts.package.default.meta.homepage or null;
# The package default can throw when the server is unpackaged, so use tryEval
url = args.url or (builtins.tryEval opts.package.default).value.meta.homepage or null;
path = [
"plugins"
"lsp"
Expand All @@ -51,21 +52,8 @@ in
enable = lib.mkEnableOption description;

package =
if lib.isOption package then
package
else if args ? package then
lib.mkPackageOption pkgs name {
nullable = true;
default = package;
}
else
# If we're not provided a package, we should provide a no-default option
lib.mkOption {
type = types.nullOr types.package;
description = ''
The package to use for ${name}. Has no default, but can be set to null.
'';
};
lib.nixvim.mkMaybeUnpackagedOption "plugins.lsp.servers.${name}.package" pkgs name
package;

cmd = mkOption {
type = with types; nullOr (listOf str);
Expand Down
5 changes: 4 additions & 1 deletion tests/lsp-servers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ let
{
enable = !(lib.elem server disabled);
}
// lib.optionalAttrs (opts ? package && !(opts.package ? default)) { package = null; }
# Some servers are defined using mkUnpackagedOption whose default will throw
// lib.optionalAttrs (opts ? package && !(builtins.tryEval opts.package.default).success) {
package = null;
}
))
(lib.filterAttrs (server: _: !(lib.elem server renamed)))
];
Expand Down
7 changes: 4 additions & 3 deletions tests/test-sources/plugins/by-name/none-ls/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@

with-sources =
{
config,
options,
lib,
pkgs,
Expand Down Expand Up @@ -158,8 +157,10 @@
# Enable unless disabled above
enable = !(lib.elem sourceName disabled);
}
# Some sources have a package option with no default
// lib.optionalAttrs (opts ? package && !(opts.package ? default)) { package = null; }
# Some sources are defined using mkUnpackagedOption whose default will throw
// lib.optionalAttrs (opts ? package && !(builtins.tryEval opts.package.default).success) {
package = null;
}
)
) options.plugins.none-ls.sources;
};
Expand Down