lib: Harmonize package options which may not exist in nixpkgs

This commit is contained in:
Quentin Boyer 2025-01-30 22:53:55 +01:00 committed by nix-infra-bot
parent eb611349a7
commit a2f01876f7
6 changed files with 57 additions and 42 deletions

View file

@ -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};
@ -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

View file

@ -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"
@ -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);