zsh: fix double compinit slowdown with oh-my-zsh
Integrate oh-my-zsh into zsh module to be able to control invocation order.
This commit is contained in:
parent
258bc85b9c
commit
29d5f5d760
|
@ -29,7 +29,6 @@ let
|
||||||
./programs/htop.nix
|
./programs/htop.nix
|
||||||
./programs/info.nix
|
./programs/info.nix
|
||||||
./programs/lesspipe.nix
|
./programs/lesspipe.nix
|
||||||
./programs/oh-my-zsh.nix
|
|
||||||
./programs/ssh.nix
|
./programs/ssh.nix
|
||||||
./programs/termite.nix
|
./programs/termite.nix
|
||||||
./programs/texlive.nix
|
./programs/texlive.nix
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
{ config, lib, pkgs, ... }:
|
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
|
||||||
|
|
||||||
cfg = config.programs.zsh.oh-my-zsh;
|
|
||||||
|
|
||||||
in
|
|
||||||
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
programs.zsh.oh-my-zsh = {
|
|
||||||
enable = mkEnableOption "oh-my-zsh";
|
|
||||||
|
|
||||||
plugins = mkOption {
|
|
||||||
default = [];
|
|
||||||
example = [ "git" "sudo" ];
|
|
||||||
type = types.listOf types.str;
|
|
||||||
description = ''
|
|
||||||
List of oh-my-zsh plugins
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
custom = mkOption {
|
|
||||||
default = "";
|
|
||||||
type = types.str;
|
|
||||||
example = "$HOME/my_customizations";
|
|
||||||
description = ''
|
|
||||||
Path to a custom oh-my-zsh package to override config of oh-my-zsh.
|
|
||||||
See: https://github.com/robbyrussell/oh-my-zsh/wiki/Customization
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
theme = mkOption {
|
|
||||||
default = "";
|
|
||||||
example = "robbyrussell";
|
|
||||||
type = types.str;
|
|
||||||
description = ''
|
|
||||||
Name of the theme to be used by oh-my-zsh.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
home.packages = [ pkgs.oh-my-zsh ];
|
|
||||||
|
|
||||||
programs.zsh.initExtra = with pkgs; ''
|
|
||||||
# oh-my-zsh configuration generated by NixOS
|
|
||||||
export ZSH=${oh-my-zsh}/share/oh-my-zsh
|
|
||||||
export ZSH_CACHE_DIR=''${XDG_CACHE_HOME:-$HOME/.cache}/oh-my-zsh
|
|
||||||
|
|
||||||
${optionalString (cfg.plugins != [])
|
|
||||||
"plugins=(${concatStringsSep " " cfg.plugins})"
|
|
||||||
}
|
|
||||||
${optionalString (cfg.custom != "")
|
|
||||||
"ZSH_CUSTOM=\"${cfg.custom}\""
|
|
||||||
}
|
|
||||||
${optionalString (cfg.theme != "")
|
|
||||||
"ZSH_THEME=\"${cfg.theme}\""
|
|
||||||
}
|
|
||||||
source $ZSH/oh-my-zsh.sh
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -67,6 +67,40 @@ let
|
||||||
config.file = mkDefault "${config.name}.plugin.zsh";
|
config.file = mkDefault "${config.name}.plugin.zsh";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ohMyZshModule = types.submodule {
|
||||||
|
options = {
|
||||||
|
enable = mkEnableOption "oh-my-zsh";
|
||||||
|
|
||||||
|
plugins = mkOption {
|
||||||
|
default = [];
|
||||||
|
example = [ "git" "sudo" ];
|
||||||
|
type = types.listOf types.str;
|
||||||
|
description = ''
|
||||||
|
List of oh-my-zsh plugins
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
custom = mkOption {
|
||||||
|
default = "";
|
||||||
|
type = types.str;
|
||||||
|
example = "$HOME/my_customizations";
|
||||||
|
description = ''
|
||||||
|
Path to a custom oh-my-zsh package to override config of oh-my-zsh.
|
||||||
|
See: https://github.com/robbyrussell/oh-my-zsh/wiki/Customization
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
theme = mkOption {
|
||||||
|
default = "";
|
||||||
|
example = "robbyrussell";
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
Name of the theme to be used by oh-my-zsh.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -136,6 +170,12 @@ in
|
||||||
'';
|
'';
|
||||||
description = "Plugins to source in <filename>.zshrc</filename>.";
|
description = "Plugins to source in <filename>.zshrc</filename>.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
oh-my-zsh = mkOption {
|
||||||
|
type = ohMyZshModule;
|
||||||
|
default = {};
|
||||||
|
description = "Options to configure oh-my-zsh.";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -151,8 +191,9 @@ in
|
||||||
mapAttrsToList export config.home.sessionVariables
|
mapAttrsToList export config.home.sessionVariables
|
||||||
);
|
);
|
||||||
in mkIf cfg.enable {
|
in mkIf cfg.enable {
|
||||||
home.packages = [ pkgs.zsh ]
|
home.packages = with pkgs; [ zsh ]
|
||||||
++ optional cfg.enableCompletion pkgs.nix-zsh-completions;
|
++ optional cfg.enableCompletion nix-zsh-completions
|
||||||
|
++ optional cfg.oh-my-zsh.enable oh-my-zsh;
|
||||||
|
|
||||||
home.file.".zshenv".text = ''
|
home.file.".zshenv".text = ''
|
||||||
${optionalString (config.home.sessionVariableSetter == "zsh")
|
${optionalString (config.home.sessionVariableSetter == "zsh")
|
||||||
|
@ -179,6 +220,23 @@ in
|
||||||
"source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
|
"source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
${optionalString cfg.oh-my-zsh.enable ''
|
||||||
|
# oh-my-zsh configuration generated by NixOS
|
||||||
|
export ZSH=${pkgs.oh-my-zsh}/share/oh-my-zsh
|
||||||
|
export ZSH_CACHE_DIR=''${XDG_CACHE_HOME:-$HOME/.cache}/oh-my-zsh
|
||||||
|
|
||||||
|
${optionalString (cfg.oh-my-zsh.plugins != [])
|
||||||
|
"plugins=(${concatStringsSep " " cfg.oh-my-zsh.plugins})"
|
||||||
|
}
|
||||||
|
${optionalString (cfg.oh-my-zsh.custom != "")
|
||||||
|
"ZSH_CUSTOM=\"${cfg.oh-my-zsh.custom}\""
|
||||||
|
}
|
||||||
|
${optionalString (cfg.oh-my-zsh.theme != "")
|
||||||
|
"ZSH_THEME=\"${cfg.oh-my-zsh.theme}\""
|
||||||
|
}
|
||||||
|
source $ZSH/oh-my-zsh.sh
|
||||||
|
''}
|
||||||
|
|
||||||
${concatStrings (map (plugin: ''
|
${concatStrings (map (plugin: ''
|
||||||
source "$HOME/.zsh/plugins/${plugin.name}/${plugin.file}"
|
source "$HOME/.zsh/plugins/${plugin.name}/${plugin.file}"
|
||||||
'') cfg.plugins)}
|
'') cfg.plugins)}
|
||||||
|
@ -188,6 +246,12 @@ in
|
||||||
${cfg.initExtra}
|
${cfg.initExtra}
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
(mkIf cfg.oh-my-zsh.enable {
|
||||||
|
# Oh-My-Zsh calls compinit during initialization,
|
||||||
|
# calling it twice causes sight start up slowdown
|
||||||
|
# as all $fpath entries will be traversed again.
|
||||||
|
programs.zsh.enableCompletion = mkForce false;
|
||||||
|
})
|
||||||
(mkIf (cfg.plugins != []) {
|
(mkIf (cfg.plugins != []) {
|
||||||
# Many plugins require compinit to be called
|
# Many plugins require compinit to be called
|
||||||
# but allow the user to opt out.
|
# but allow the user to opt out.
|
||||||
|
|
Loading…
Reference in a new issue