Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib,lsp,none-ls: Add a standard way to handle automatic installation of packages that may not exist in nixpkgs #2852

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

traxys
Copy link
Member

@traxys traxys commented Jan 17, 2025

If such a package is used by an end user an error will be raised with a message of the form:

       error: Nixvim (plugins.none-ls.sources.formatting.textlint.package): No package is known for textlint, install externally and set this option to null

I'm open to changing that to a warning and returning null instead, though this would complicate the implementation as we would now need to check the priorities

…ages

For example for lsp it can generate the following kind of messages:

 error: Nixvim (plugins.lsp.servers.ziggy_schema.package): No package is known for ziggy_schema, install externally and set this option to null
};

useOptionalPackage =
options: config: opt:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
options: config: opt:
options: config: loc:

or

Suggested change
options: config: opt:
options: config: path:

(not sure we really need config either, because we have opt.value available)

useOptionalPackage =
options: config: opt:
let
def = lib.getAttrFromPath opt options;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def = lib.getAttrFromPath opt options;
opt = lib.getAttrFromPath loc options;

in
if !def.isDefined && def ? _unpackaged then
throw ''
Nixvim (${lib.concatStringsSep "." opt}): No package is known for ${def._packageName}, install externally and set this option to null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Nixvim (${lib.concatStringsSep "." opt}): No package is known for ${def._packageName}, install externally and set this option to null
Nixvim (${opt}): No package is known for ${opt._packageName}, install externally and set this option to null

options have a __toString which uses showOption opt.loc, which is a bit nicer than using the loc we have passed in, because it also gets things like the prefix (programs.nixvim).

Not sure where opt._packageName comes from?

Nixvim (${lib.concatStringsSep "." opt}): No package is known for ${def._packageName}, install externally and set this option to null
''
else
lib.getAttrFromPath opt config;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lib.getAttrFromPath opt config;
opt.value;

Comment on lines +410 to +413
// {
_unpackaged = true;
_packageName = name;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this survive the module system? I'm pretty sure particular parts of the module system that elaborate options will only inherit known attrs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I tested it does (as I managed to trigger the warnkngs

@@ -391,6 +391,39 @@ rec {
);
};

mkOptionalPackage =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initial impression: this feels like an anti-pattern. Can we find a way to "use" an optional package without having to declare the option in a special way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants