neovim: expose sideloadInitLua option to control the generation of init.lua#9028
neovim: expose sideloadInitLua option to control the generation of init.lua#9028veselyn wants to merge 15 commits intonix-community:masterfrom
sideloadInitLua option to control the generation of init.lua#9028Conversation
|
thanks for trying to tackle this. This wont work depending on the plugins you install that might pull some premade config. What I think would be clearer for everyone, users and maintainers is an option (not sure how to name it: There is another issue I welcome input as well: how to load the generated config ? The following enum would cover all bases IMO:
Now the annoying bit would be to test all those. what do you think ? |
Are you thinking of writing it at
I don't have all the context to provide an opinion. Where does the generated config come from? Does it come purely from the user by, for example, overriding plugin derivations to include custom config? Another possibility is to use the |
that's what I had in mind. Until #8933 gets merged, it might trigger issues so we can reference the /nix store directly for now.
In a nutshell, having an heuristic for wrapping neovim or not confuses users (and maintainers) as users do a change, and all of a sudden neovim is not wrapped anymore and an init.lua tries to be created. And wrapping is nasty because then you have to wrap all your neovim variants (GUIs/wrappers etc).
That's an interesting idea worth exploring. I fear there might be loading order issues etc. In the short term to fix your usecase as well as the linked issue, we can do the simple immediate fix of explicit option to toggle wrapping instead of writing init.lua If you want to explore loading the config as a plugin in another PR later, that could be interesting as well. |
… via args" This reverts commit 669baa7.
…onfigs are loaded
|
@teto, I made changes following your suggestion. Could you take a quick look before I write a description for the option and test cases? |
modules/programs/neovim.nix
Outdated
| ''; | ||
| }; | ||
|
|
||
| wrapGeneratedConfigs = mkOption { |
There was a problem hiding this comment.
we might want to avoid engraving "wrap" in the option name if it turns out later we can create a "fake" hm plugin to load the config. I kinda like sideload or sideloadInit.
I know I mentioned "preload", "postload" etc but I would prefer if we kept things simple as starter. We can change it if need arises.
The goal of this PR is already doable without upstream changes, we just need a setting (maybe boolean for now ? we can migrate to an enum when needed) to make it easier for everyone but we dont need to support every scenario.
For instance a user could already set extraMakeWrapperArgs = [ "--cmd 'lua require(${writeText "init.lua" config.programs.neovim.initLua} ] .
| ++ [ | ||
| { | ||
| "nvim/init.lua" = mkIf (cfg.initLua != "") { | ||
| text = cfg.initLua; |
There was a problem hiding this comment.
I would just add enable = !cfg.wrapGeneratedConfigs or in your case (builtins.elem cfg.wrapGeneratedConfigs [ false "user" ] . This way the user can still see the generated config and use it somewhere else but the actual init.lua wont be created.
modules/programs/neovim.nix
Outdated
| ''--cmd 'lua require("hm-generated")' '' | ||
| ] | ||
| ++ lib.optionals (cfg.wrapGeneratedConfigs == "postload") [ | ||
| "--add-flags" |
There was a problem hiding this comment.
keep only this one and reference lua require ${writeText config.programs.initLua}
There was a problem hiding this comment.
Wouldn't it make more sense to load it before the rest of the files from the runtime path with --cmd instead of -c? That way the load order is closer to what it would be with a regular init.lua file.
|
ty for taking care of this. I've added some comments. Basically:
|
|
The tests are still failing and require some more work. I'll pick it up again in the following days. |
|
looks good. As for the tests |
…-to-wrapper-as-args
sideloadInitLua option to control the generation of init.lua
|
I added an extra test case for the sideloading, configured |
Description
This pull request tries to resolve #8938.
Checklist
Change is backwards compatible.
Code formatted with
nix fmtornix-shell -p treefmt nixfmt deadnix keep-sorted nixf-diagnose --run treefmt.Code tested through
nix run .#tests -- test-allornix-shell --pure tests -A run.all.Test cases updated/added. See example.
Commit messages are formatted like
See CONTRIBUTING for more information and recent commit messages for examples.
If this PR adds a new module
If this PR adds an exciting new feature or contains a breaking change.