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

neovim: make the derivation more composable #344541

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

Conversation

teto
Copy link
Member

@teto teto commented Sep 25, 2024

Now that we have structured attributes enabled, it's easier than ever to
access the wrapper config from itself. Let's expose the plugins instead
of the packpathDir with which one can't do much.

With exposed plugins, one could tweak the current wrapper with more
plugins, e.g. neovim.withPlugins([fugitive]).withPlugins([plenary]) .
we could also add a boolean to autoadd the plugins passthru.initLua,
better handle the dependencies (runtime programs, python deps).

Description of changes

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@teto teto changed the title neovim: make the wrapper more evolvable neovim: make the derivation more composable Sep 25, 2024
Copy link
Contributor

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

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

(comments and questions only)

# TODO use (coercedTo package (v: { plugin = v; }) pluginWithConfigType);
map (x: defaultPlugin // (if (x ? plugin) then x else { plugin = x; })) plugins;
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: is there a module option somewhere that relates to this? I'm struggling to see how types.coercedTo is relevant otherwise

Copy link
Member Author

Choose a reason for hiding this comment

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

I have some local code that uses nixosModule to generate the neovim config. Sadly I cant ever seem to finish it. It's not releveant here I will remove the comment

assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";

# assert packpathDirs -> throw "Packpathdirs removed";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# assert packpathDirs -> throw "Packpathdirs removed";
assert lib.assertMsg (attrs ? packpathDirs) "packpathDirs removed";

I believe best practice though would be to remove the ... so that only supported args can be passed? Unless the args truly can be anything and will be passed on to another function.

Copy link
Member Author

Choose a reason for hiding this comment

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

funny I am of the opposite opinion ^^' it lets the package be forward and backward compatible (you can mix different versions of nixpkgs) and add warnings such as this one.

Copy link
Contributor

@MattSturgeon MattSturgeon Oct 3, 2024

Choose a reason for hiding this comment

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

I believe best practice though would be to remove the ... so that only supported args can be passed?

I believe I was advised this when contributing to /lib. EDIT: #315411 (comment)

IIRC the argument was something along the lines of: it's better for the function signature to not be forward/backward compatible in ways that the function itself is not.

e.g. if someone uses a feature of the function that is supported by a newer nixpkgs than they have, they would not know that the feature has no effect.

Backwards compatibility can still be achieved by keeping stub foo ? null, parameters in the signature, but forward compatibility is more difficult because we don't know what will be added in the future.

Either way, the ... isn't added by this PR, so this isn't feedback on the PR itself, just commenting on the existing code 🙃


finalPackdir = neovimUtils.packDir packpathDirs;

rcContent = ''
${luaRcContent}
'' + lib.optionalString (!isNull neovimRcContent) ''
vim.cmd.source "${writeText "init.vim" neovimRcContent}"
'' + lib.optionalString (!isNull neovimRcContent') ''
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC isNull is deprecated, if the line is being touched anyway we can migrate to != null?

Copy link
Member Author

Choose a reason for hiding this comment

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

didn't know about that: do you have a reference ? isNull is a builtins so I am surprised it gets removed. But yeah np problem for changing it to != null

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a warning on Noogle and nix.dev. Not a big deal but better to avoid usage if possible 🙂

++ (lib.concatMap (f: f ps) pluginPython3Packages));

packpathDirs.myNeovimPackages = myVimPackage;

wrapperArgsStr = if lib.isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be useful to also have a runtimeInputs or dependencies argument that prepends to PATH via the wrapper?

Copy link
Member Author

Choose a reason for hiding this comment

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

totally. This will be unblocked by this PR. I prefer it to be done as a follow up though since neovim is a touchy derivation: you quickly know when you break something xD and this has the potential to break configs already (at least for people using the "private/unstable" APIs)

@teto teto force-pushed the teto/neovim-move-plugins-to-wrapper branch from 4ba0a81 to 857dad5 Compare October 3, 2024 22:05
@teto teto marked this pull request as ready for review October 3, 2024 22:13
@teto teto requested a review from figsoda as a code owner October 3, 2024 22:13
, withNodeJs ? false
, withRuby ? true
/* the function you would have passed to lua.withPackages */
, extraLuaPackages ? (_: [ ])
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the new expected way of handling adding extraLuaPackages to a config? I didn't see this argument moved to the wrapper like extraPython3Packages was.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

you are absolutely correct. I would like to avoid adding them to the wrapper as extraLuaPackages was a workaround to specify plugin dependencies. Lua dependencies are now loaded correctly in the wrapper via shell hooks. A user could call the wrapper directly adding its own wrapper args to add externmal lua dependencies or convert a lua package with buildNeovimPlugin

Copy link
Member Author

Choose a reason for hiding this comment

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

if you could trigger the nnixvim job again, hopefully it is now fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, kicking off another build there

Now that we have structured attributes enabled, it's easier than ever to
access the wrapper config from itself. Let's expose the 'plugins'
derivations instead of the final 'packpathDir' with which one can't do much.

TLDR: the neovim wrapper accepts a list of neovim derivations in
`plugins` instead of the symlinkJoin of plugins in `packpathDir`.

With exposed plugins, one could tweak the current wrapper with more
plugins, e.g. neovim.withPlugins([fugitive]).withPlugins([plenary]) .
we could also add a boolean to autoadd the plugins passthru.initLua,
better handle the dependencies (runtime programs, python deps).
@teto teto force-pushed the teto/neovim-move-plugins-to-wrapper branch from 857dad5 to 4ebef43 Compare October 6, 2024 22:50
@@ -19,9 +23,12 @@ let
# should contain all args but the binary. Can be either a string or list
, wrapperArgs ? []
# a limited RC script used only to generate the manifest for remote plugins
, manifestRc ? null
# , manifestRc ? null
Copy link
Contributor

Choose a reason for hiding this comment

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

Was something meant to be noted here for commenting this out?

Copy link
Member Author

Choose a reason for hiding this comment

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

ty for spotting this, I removed it, it's generated a bit later in the wrapper.

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

Successfully merging this pull request may close these issues.

3 participants