-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
zsh: add plugins submodule #56
Conversation
b97069e
to
e20ff95
Compare
Thank you for PR! I have a couple of comments.
|
modules/programs/zsh.nix
Outdated
|
||
file = mkOption { | ||
type = types.str; | ||
default = "${config.name}.plugin.zsh"; |
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.
Like @uvNikita mentioned this will cause problems because Nix will attempt to expand this during evaluation even if the module is not used in the configuration, e.g., for generating the home-configuration.nix
man page.
Instead I think you can add a config
section:
pluginModule = types.submodule ({ config, ... }: {
options = {
…
};
config = {
file = mkDefault name;
};
};
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.
Right, I amended the fix.
2035f0a
to
11948c4
Compare
I believe I figured out the right way to do this:
EDIT: oh-my-zsh does it this way as well With this setup and no |
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've tried to test this with different configurations and here is results of a start-up time:
- plain
zsh
(emptyzsh.plugins
,zsh.oh-my-zsh
disabled): 0.05 - with empty
zsh.plugins
,oh-my-zsh
enabled, and one plugin inoh-my-zsh.plugins
: 0.17 - with one plugin in
zsh.plugins
andoh-my-zsh
disabled: 0.05 - with one plugin in
zsh.plugins
,oh-my-zsh
enabled, and one plugin inoh-my-zsh.plugins
: 0.41
Zsh was enabled only in a home environment (no /etc/zshrc
file), the testing was performed with this command: time zsh -i -c exit
.
So on my system in seems like two solutions work quite fast separately, but not together. I didn't find the reason of this for now, maybe you have any idea on why this is the case?
In any case, it seems like the problem is not in this solution particularly, but more in the combination of two, so I think we can add this changes as it is now.
I also think that we should add a news entry about a new parameter, that would be a good example on how to use this functionality. @rycee please correct me if I'm wrong.
modules/programs/zsh.nix
Outdated
plugins = mkOption { | ||
type = types.listOf pluginModule; | ||
default = []; | ||
example = [ |
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 in this case example = literalExample = ''...''
would be better since it produces a more readable message in man home-configuration.nix
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.
Sure, amened.
11948c4
to
c5b946a
Compare
Thanks for the benchmarks! The combination is probably slow because oh-my-zsh calls EDIT: I tried that and got 0.17s with loads of |
@uvNikita Yeah, if this is interesting for the general Zsh user then I think it would make sense to have a news entry saying that this option now is available. I guess it should be conditioned on |
I tested your branch and indeed it looks like it improved performance a bit, thank you for observation! I don't see a problem with combining these modules for optimization purposes since they both setup However, I performed more tests and was still experiencing a significant (by order of magnitude) increase in startup time when using both When we use I also figured out that it seems like not referencing So, as for now, I see three ways to go:
I personally think the second option would be the best, but I'm not sure how hard it is to implement such behavior in nix. @dermetfan what do you think about this? |
In case `compinit` is called from within oh-my-zsh, this passes the security check. see nix-community#56 (comment)
1f43598
to
76a1880
Compare
In case `compinit` is called from within oh-my-zsh, this passes the security check. Also allows us to call `compinit` without `-C` for vanilla plugins. see nix-community#56 (comment)
76a1880
to
ce065fa
Compare
In case `compinit` is called from within oh-my-zsh, this passes the security check. Also allows us to call `compinit` without `-C` for vanilla plugins. see nix-community#56 (comment)
Spot on, @uvNikita! Turns out the second option was not so hard to implement, and it did fix the slowdown as you described. I'm now at 0.07s with the same plugins as in my previous comment. I added the commits to this PR's branch so you can review. |
modules/programs/zsh.nix
Outdated
(mkIf (builtins.length cfg.plugins > 0) { | ||
programs.zsh.enableCompletion = mkDefault true; | ||
|
||
home.file = builtins.listToAttrs (map (plugin: { |
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.
You can avoid listToAttrs
here since home.file
accepts lists of sets (the path is in the target
attribute). Something like
home.file = map (plugin: {
target = ".zsh/plugins/${plugin.name}";
source = plugin.src;
}) cfg.plugins;
should work.
modules/programs/zsh.nix
Outdated
(mkIf cfg.oh-my-zsh.enable { | ||
programs.zsh.enableCompletion = mkForce false; | ||
}) | ||
(mkIf (builtins.length cfg.plugins > 0) { |
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 it is a bit more straight-forward to say cfg.plugins != []
, no biggie, though.
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.
Oh sure, I'm still used to conventional languages I guess.
ce065fa
to
37a7b92
Compare
In case `compinit` is called from within oh-my-zsh, this passes the security check. Also allows us to call `compinit` without `-C` for vanilla plugins. see nix-community#56 (comment)
37a7b92
to
00d9c04
Compare
In case `compinit` is called from within oh-my-zsh, this passes the security check. Also allows us to call `compinit` without `-C` for vanilla plugins. see nix-community#56 (comment)
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.
Tested new version -- the startup is fast and everything seems to work, great job! :)
I have just last few comments on the code. If you could fix them, merge the last and the first commit together (to have just zsh: add plugins submodule
and zsh: fix double compinit slowdown with oh-my-zsh
commits with expanded messages), and to add news entry, then I will be glad to merge the PR :)
modules/programs/zsh.nix
Outdated
); | ||
}) | ||
(mkIf cfg.oh-my-zsh.enable { | ||
programs.zsh.enableCompletion = mkForce false; |
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.
Would be nice to leave a comment here on why we disable this option since it might not be obvious to someone reading it in the future.
modules/programs/zsh.nix
Outdated
}; | ||
} | ||
{ | ||
file = "init.sh"; |
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.
Since plugin.name
is now required a parameter, this example is not working anymore. Should probably add something like name = "enhancd"
.
modules/programs/zsh.nix
Outdated
|
||
name = mkOption { | ||
type = types.str; | ||
description = "The name of the plugin. Don't forget to add <option>file</option> if the script name does not follow convention."; |
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.
Looks like these two descriptions are too long, would you mind to rewrite it using ''
quotes?
00d9c04
to
4dbddde
Compare
In case `compinit` is called from within oh-my-zsh, this passes the security check. Also allows us to call `compinit` without `-C` for vanilla plugins. see nix-community#56 (comment)
4dbddde
to
fdbc4ac
Compare
zsh: fix double compinit slowdown with oh-my-zsh Integrate the oh-my-zsh module into the zsh module in order to be able to control invocation order. zsh: link plugins in home directory In case `compinit` is called from within oh-my-zsh, this passes the security check. Also allows us to call `compinit` without `-C` for vanilla plugins. see nix-community#56 (comment)
I was thinking that it would be nicer to have two commits: one about adding |
Integrate the oh-my-zsh module into the zsh module in order to be able to control invocation order.
In case `compinit` is called from within oh-my-zsh, this passes the security check. Also allows us to call `compinit` without `-C` for vanilla plugins. see nix-community#56 (comment)
fdbc4ac
to
0d543cf
Compare
Integrate the oh-my-zsh module into the zsh module in order to be able to control invocation order. zsh: link plugins in home directory In case `compinit` is called from within oh-my-zsh, this passes the security check. Also allows us to call `compinit` without `-C` for vanilla plugins. see nix-community#56 (comment)
11a10b1
to
38dd49b
Compare
Added a news entry in a third commit. Do we agree like this? 😃 |
modules/misc/news.nix
Outdated
@@ -108,6 +108,14 @@ in | |||
config = { | |||
news.entries = [ | |||
{ | |||
time = "2017-09-10T00:15:19+02:00"; | |||
message = '' |
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.
Looking good but should have a field condition = config.programs.zsh.enable;
to limit the news to those that are using Zsh.
modules/misc/news.nix
Outdated
@@ -108,6 +108,14 @@ in | |||
config = { | |||
news.entries = [ | |||
{ | |||
time = "2017-09-10T00:15:19+02:00"; |
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.
Should be UTC, i.e., like the output of date --iso-8601=second --universal
.
Not that I understand much of Zsh but it looks like this PR has come a long way! Maybe should have a look at trying Zsh out ;-) Thanks to both of you for such productive and fruitful work! |
38dd49b
to
b975dad
Compare
I probably didn't explain properly what I mean. I was thinking to have two commits in the end: The first one, that contains both new parameter implementation (with plugins being linked into the home directory) and the news entry:
And the second one, that merges oh-my-zsh and zsh modules for even further optimizations:
Alternatively, I can restructure your commits in this way during rebase if you would prefer that :) |
@rycee I'm also very excited about these new changes and optimizations! With this PR merged and couple of small fixes that will be added soon our zsh module will be faster and more featureful even than the one from nixpkgs :) |
b975dad
to
ca6803a
Compare
@uvNikita Go ahead then, I pushed the original commits back up. My git-fu is ok but I don't see how I would rebase |
To pass compinit security checks, plugins are liked into ~/zsh/plugins folder. This also solves issues with a slow start up, see #56 (comment).
Rebased changes into master. Thank you for the contribution! |
To pass compinit security checks, plugins are liked into ~/zsh/plugins folder. This also solves issues with a slow start up, see nix-community#56 (comment).
See #55.
The plugins module does not have its own
compinit
. Instead it defaultsenableCompletion
to true.Users who cannot or do not want to disable
programs.zsh
in their system config can still disableenableCompletion
to avoid the slowdown. For example: