-
-
Notifications
You must be signed in to change notification settings - Fork 326
lib/*-plugins: initial support for lib.mkPackageOption
#2139
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/*-plugins: initial support for lib.mkPackageOption
#2139
Conversation
246e128
to
72d04a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would have been nice to remove completly the defaultPackage
in this PR, it would simplify a bit the helpers, though I think I saw there are around 150 occurences, it may be some work...
Maybe a regex could replace them all? Not sure
4d4f56a
to
22c2ac1
Compare
I agree it'd be nice, however I don't want to rush to replace all A treewide substitution of |
Indeed, it would be nice to leave the |
So this gives us clearer documentation and nullable packages for plugins, which are big wins to resolve #1970 and #1950. Does it also have the benefit of the lazy package evaluation to prevent pkg errors being thrown from unused options or is that still an issue that requires a a different solution? |
I think because we include the man page by default it will never be lazy, whatever we do. We may need to reconsider the man page inclusion by default |
I have some gripes with how we build the man docs too; they will always use our flake's pkgs rather than the pkgs used in module eval. To achieve laziness, I think we need to either ditch the man pages being included by default, and/or remove automatically getting the |
Did you wanna add a test to verify how it responds to null packages with the new functionality? |
We already have some |
Sorry, was in the mindset of top level package option. These were already nullable. |
@khaneliman just to clarify, this does not introduce nullable package options, unless a maintainer chooses to explicitly pass |
bdaefb1
to
cecffb2
Compare
@traxys this now migrates all call-sites for I've also verified that the docs still link to the correct option-declaration file (i.e. the file that used mk*Plugin) even when the options are declared in an imported module. I don't want to remove After merging this PR, there's still 89 matches for |
Instead of maintainers providing an actual `defaultPackage`, they should specify the pkg name which we'll use when calling `lib.mkPackageOption`. This makes `mkVimPlugin` and `mkNeovimPlugin` compliant with nix-community#1950.
cecffb2
to
439c01a
Compare
Migrate all users of `mkVimPlugin` and `mkNeovimPlugin` to use the new `package` argument instead of the old `defaultPackage` argument.
439c01a
to
9c11b54
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I very much appreciate the direction of this PR.
@@ -29,6 +29,8 @@ The [nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/#managing-plugins-w | |||
|
|||
When using NixVim it is possible to encounter an error of the type `attribute 'name' missing`, for example it could look like: | |||
|
|||
<!-- TODO: Update example now that we use `mkPackageOption` --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we want to handle this in this PR or follow up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll leave it for later. Next time a user reports a mismatched nixpkgs error we can use the error message they report in the example here.
@Mergifyio queue |
✅ The pull request has been merged automaticallyThe pull request has been merged automatically at 9c11b54 |
Summary
Adds initial support for receiving a package option instead of a package derivation in
mkVimPlugin
andmkNeovimPlugin
. This is done to enable the use oflib.mkPackageOption
as discussed in #1950.This soft-deprecates our current helpers,
lib.nixvim.mkPluginPackageOption
andlib.nixvim.mkPackageOption
.Also implemented this for the plugin TEMPLATE, cmp sources, telescope extensions, and lsp language-servers.
Why
An option with a package default, will be rendered using
lib.generators.toPretty
as (e.g.)<derivation vimplugin-cmp-ai-2024-08-01>
.We could specify a
defaultText
for all our package options, e.g.defaultText = lib.literalExpression "pkgs.cmp-ai"
, howeverlib.mkPackageOption
automates this by setting bothdefault
anddefaultText
based on an attr-path.Screenshots
Before+after screenshots
Before
After
Alternative/future approach
It would be possible to have
mk*Plugin
handle callinglib.mkPackageOption
internally, however it'd have to do so within an imported module in order to gain access to the (correct)pkgs
arg1.We may need to do this anyway to also gain access to
options
andconfig
without having to pass them into the helpers, but that is out of scope for this PR...See this POC:
Proof of concept
Footnotes
As part of
helpers
, we do have access to apkgs
, but it may not be the correct one configured for use within the module eval. Incidentally, this is making me think we should separate out all helper functions that rely onpkgs
and put them somewhere else so thathelpers
doesn't need apkgs
. ↩