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
nixos/ohMyZsh: allow multiple derivations in ZSH_CUSTOM
#43282
Conversation
Success on x86_64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
1d8d157
to
c643292
Compare
Success on x86_64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
cp _* $out/share/zsh/site-functions | ||
installPhase = let | ||
pluginDir = if ohMyZsh then "plugins/nix" else "share/zsh/site-functions"; | ||
compDir = if ohMyZsh then "completions" else "share/zsh/site-functions"; |
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.
Is this way of packaging ohMyZsh plugins documented somewhere? I can't find anything else in nixpkgs using this, and it feels like that shouldn't be part of the package declaration, but rather of the code that wants to use the package (by wrapping the paths how ohmyzsh expects them or so).
default = null; | ||
type = with types; nullOr str; | ||
description = '' | ||
List of custom packages that should be loaded into `oh-my-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.
The description is the same here as the new option below.
@@ -60,23 +68,32 @@ in | |||
}; | |||
}; | |||
|
|||
config = mkIf cfg.enable { | |||
config = with builtins; mkIf cfg.enable (let |
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.
with builtins;
can be removed, length
and head
are in lib
.
|
||
custom = if cfg.custom != null then cfg.custom else | ||
if length (cfg.customPkgs) == 0 then null else | ||
if length (cfg.customPkgs) == 1 then head cfg.customPkgs else pkgs.buildEnv { |
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.
Nit: Parens can be removed
140480b
to
8ea9867
Compare
@infinisil thanks a lot for your review! I fixed all of it and solved theproblem with oh-my-zsh packages by adjusting an attr set in the |
Thanks, but I still don't think that's quiet right. (Asking because I'm not entirely sure:) So oh-my-zsh expects If that's the case, then I suggest to dedicate a new folder linkFarm "oh-my-zsh-custom" [
{
name = "themes";
path = "${buildEnv {
name = "oh-my-zsh-themes";
paths = [ customPkgs ];
pathsToLink = "/share/zsh/themes";
}}/share/zsh/themes";
}
{
name = "completions";
path = "${buildEnv {
name = "oh-my-zsh-completions";
paths = [ customPkgs ];
pathsToLink = "/share/zsh/site-functions";
}}/share/zsh/site-functions";
}
] And a thing about the current state: |
Thanks for the review and the detailed feedback! I mostly agree with you, but now I have to catch some sleep, will have a deeper look at this tomorrow %) |
8ea9867
to
5b11908
Compare
@infinisil fixed, thanks a lot for your feedback! |
Success on x86_64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
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 much better! With this PR, these /share/zsh/{themes,site-functions,plugins/*}
directories will probably become a convention for how to package zsh stuff on Nix, so I think it deserves an entry in the docs. Would you mind adding such an entry? Would be somewhere in the Nixpkgs manual. This would then be something we can link people to if they want to package zsh stuff and have it work with nixpkgs' conventions.
cp _* $out/share/zsh/site-functions | ||
cp *.zsh $out/share/zsh/plugins/nix | ||
|
||
runHook postInstall |
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.
As previously mentioned, don't run these hooks manually here (for both derivations).
|
||
chmod +x lambda-mod.zsh-theme # only executable scripts are found by `patchShebangs` | ||
patchShebangs . | ||
chmod -x lambda-mod.zsh-theme |
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's okay to let it stay executable, it is executable after all, especially since the shebang was patched.
5b11908
to
0794507
Compare
Success on x86_64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
These files feature simple aliases and a nix-shell detector when using `nix-shell --run zsh`. The package itself contains the completion scripts in `$out/share/zsh/site-functions` (to keep it compatible with ZSH-only setups) and the plugins in `$out/share/zsh/plugins` for oh-my-zsh.
This ensures that no impurity exists due to implicitly depending on`/usr/bin/env`. It stores the theme into `$out/share/zsh/themes` to make it possible to find theme using `buildEnv` and remain consistent with other ZSH extensions.
…s for `ZSH_CUSTOM` If multiple third-party modules shall be used for `oh-my-zsh` it has to be possible to create another env which composes all the packages. Now it can be done like this: ``` { pkgs, ... }: { programs.zsh.enable = true; programs.zsh.ohMyZsh = { enable = true; customPkgs = with pkgs; [ lambda-mod-zsh-theme nix-zsh-completions ]; theme = "lambda-mod"; plugins = [ "nix" ]; }; } ``` Please keep in mind that this is not compatible with `programs.zsh.ohMyZsh.custom`, only one of these options can be used ATM. Each package should store its outputs into `$out/share/zsh/<output-name>`. Completions (and ZSH-only) extensions should live in the `fpath` (`$out/share/zsh/site-functions`), plugins in `.../plugins` and themes in `.../themes` (please refer to fdb6bf6ed68c2f089ae6c729dfeaa3eddea2ce6a and 406d64aad162b3a4881747be4e24705fb5182573). All scripts in `customPkgs` will be linked together using `linkFarm` to provide a single directory for all scripts from all derivations in `customPkgs` as suggested in NixOS#43282 (comment).
0794507
to
39b8545
Compare
Success on x86_64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
cc @infinisil, are the latest changes better? |
Yeah looking good now! Only thing that would be nice is some docs, documenting Adding docs should prevent anybody else trying to define some directory as a convention for themes/plugins. I think this may be the reason we currently need to support multiple of those for completions: nixpkgs/nixos/modules/programs/zsh/zsh.nix Lines 157 to 160 in a2f499e
|
great! You're absolutely right, it could use some documentation, please give me some time to think how and where to write it, I'll report back, when it's done. And thanks for your patience and feedback! :) |
In the last year `programs.oh-my-zsh` gained more complexity and since the introduction of features like `customPkgs` which builds a `ZSH_CUSTOM` path from a sequence of derivation a documentation may be fairly helpful to make the knowledge how to use the module and how to package new ZSH plugins visible. See NixOS#43282 (comment)
@infinisil I added a docbook entry (using |
Success on aarch64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
Success on x86_64-linux (full log) Attempted: lambda-mod-zsh-theme, nix-zsh-completions Partial log (click to expand)
|
Neat! 2 things about the docs: It would be nice for them to be built into the nixpkgs docs, so it should probably be in Thanks for doing all this work :) |
Care to elaborate? I just followed the convention to use
Well, plugins are mostly oh-my-zsh specific and many (third-party) themes explicirtly depend on oh-my-zsh. I mentioned that packages should be kept compatible with zsh-only setups (if possible), but I'll re-read the paragraphs and think where we can make this more explicit. However I'll wait with this until we have decided whether or not to move the docs to |
Oh I see, yeah I didn't know about |
@infinisil any chance to get this merged?:) |
Motivation for this change
For third-party scripts
oh-my-zsh
providesZSH_THEME
. However this can be set to only one directory. However the module should be able to support multiple third-party scripts packaged as derivations using nix's composability features (namelybuildEnv
).Now a config like this is possible:
The support for
ohMyZsh.custom
has been retained as it's possible thatZSH_CUSTOM
should point to a personal directory (e.g. a scripts dir in$HOME
). An assertion ensures that no collisions between these features happens.The commits are structured like this:
nix-zsh-completions
package (add hooks, cleanup meta, add plugin script, allow (optionally) an oh-my-zsh like structure (withthemes/
,plugins/
etc rather thanshare/zsh
)lambda-mod-zsh-theme
(only usable withoh-my-zsh
, drops usage of$out/share
, instead$out/themes
is used)Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)