mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-03 07:31:03 +01:00
zsh: move oh-my-zsh to separate file
zsh is incredibly bloated, moving oh-my-zsh to separate file Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
392ddb642a
commit
9b76feafd0
2 changed files with 127 additions and 90 deletions
|
|
@ -15,13 +15,12 @@ let
|
|||
optionalString
|
||||
types
|
||||
;
|
||||
inherit (config.home) stateVersion;
|
||||
|
||||
cfg = config.programs.zsh;
|
||||
|
||||
relToDotDir = file: (optionalString (cfg.dotDir != null) (cfg.dotDir + "/")) + file;
|
||||
|
||||
stateVersion = config.home.stateVersion;
|
||||
|
||||
bindkeyCommands = {
|
||||
emacs = "bindkey -e";
|
||||
viins = "bindkey -v";
|
||||
|
|
@ -30,6 +29,7 @@ let
|
|||
in
|
||||
{
|
||||
imports = [
|
||||
./oh-my-zsh.nix
|
||||
./prezto.nix
|
||||
./zsh-abbr.nix
|
||||
(lib.mkRenamedOptionModule
|
||||
|
|
@ -208,57 +208,6 @@ in
|
|||
}
|
||||
);
|
||||
|
||||
ohMyZshModule = types.submodule {
|
||||
options = {
|
||||
enable = mkEnableOption "oh-my-zsh";
|
||||
|
||||
package = lib.mkPackageOption pkgs "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>
|
||||
for more information.
|
||||
'';
|
||||
};
|
||||
|
||||
theme = mkOption {
|
||||
default = "";
|
||||
example = "robbyrussell";
|
||||
type = types.str;
|
||||
description = ''
|
||||
Name of the theme to be used by oh-my-zsh.
|
||||
'';
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
default = "";
|
||||
example = ''
|
||||
zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github
|
||||
'';
|
||||
type = types.lines;
|
||||
description = ''
|
||||
Extra settings for plugins.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
historySubstringSearchModule = types.submodule {
|
||||
options = {
|
||||
enable = mkEnableOption "history substring search";
|
||||
|
|
@ -635,12 +584,6 @@ in
|
|||
description = "Plugins to source in {file}`.zshrc`.";
|
||||
};
|
||||
|
||||
oh-my-zsh = mkOption {
|
||||
type = ohMyZshModule;
|
||||
default = { };
|
||||
description = "Options to configure oh-my-zsh.";
|
||||
};
|
||||
|
||||
localVariables = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
|
|
@ -654,6 +597,22 @@ in
|
|||
Extra local variables defined at the top of {file}`.zshrc`.
|
||||
'';
|
||||
};
|
||||
|
||||
setOptions = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
example = [
|
||||
"EXTENDED_HISTORY"
|
||||
"RM_STAR_WAIT"
|
||||
"NO_BEEP"
|
||||
];
|
||||
description = ''
|
||||
Configure zsh options. See
|
||||
{manpage}`zshoptions(1)`.
|
||||
|
||||
To unset an option, prefix it with "NO_".
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -694,13 +653,6 @@ in
|
|||
home.file."${relToDotDir ".zlogout"}".text = cfg.logoutExtra;
|
||||
})
|
||||
|
||||
(mkIf cfg.oh-my-zsh.enable {
|
||||
home.file."${relToDotDir ".zshenv"}".text = ''
|
||||
ZSH="${cfg.oh-my-zsh.package}/share/oh-my-zsh";
|
||||
ZSH_CACHE_DIR="${config.xdg.cacheHome}/oh-my-zsh";
|
||||
'';
|
||||
})
|
||||
|
||||
(mkIf (cfg.dotDir != null) {
|
||||
home.file."${relToDotDir ".zshenv"}".text = ''
|
||||
export ZDOTDIR=${zdotdir}
|
||||
|
|
@ -729,10 +681,7 @@ in
|
|||
}
|
||||
|
||||
{
|
||||
home.packages =
|
||||
[ cfg.package ]
|
||||
++ lib.optional cfg.enableCompletion pkgs.nix-zsh-completions
|
||||
++ lib.optional cfg.oh-my-zsh.enable cfg.oh-my-zsh.package;
|
||||
home.packages = [ cfg.package ] ++ lib.optional cfg.enableCompletion pkgs.nix-zsh-completions;
|
||||
|
||||
programs.zsh.initContent = lib.mkMerge [
|
||||
# zprof must be loaded before everything else, since it
|
||||
|
|
@ -814,20 +763,6 @@ in
|
|||
''
|
||||
))
|
||||
|
||||
(lib.mkIf cfg.oh-my-zsh.enable (
|
||||
mkOrder 800 ''
|
||||
# oh-my-zsh extra settings for plugins
|
||||
${cfg.oh-my-zsh.extraConfig}
|
||||
# oh-my-zsh configuration generated by NixOS
|
||||
${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
|
||||
''
|
||||
))
|
||||
|
||||
(mkOrder 900 (
|
||||
(lib.concatStrings (
|
||||
map (plugin: ''
|
||||
|
|
@ -866,6 +801,12 @@ in
|
|||
''
|
||||
))
|
||||
|
||||
(lib.mkIf (cfg.setOptions != [ ]) (
|
||||
mkOrder 950 ''
|
||||
${concatStringsSep "\n" (map (option: "setopt ${option}") cfg.setOptions)}
|
||||
''
|
||||
))
|
||||
|
||||
(lib.mkIf (cfg.initExtra != "") cfg.initExtra)
|
||||
|
||||
(lib.mkIf (aliasesStr != "" || cfg.shellGlobalAliases != { }) (
|
||||
|
|
@ -930,12 +871,6 @@ in
|
|||
home.file."${relToDotDir ".zshrc"}".text = cfg.initContent;
|
||||
}
|
||||
|
||||
(mkIf cfg.oh-my-zsh.enable {
|
||||
# Make sure we create a cache directory since some plugins expect it to exist
|
||||
# See: https://github.com/nix-community/home-manager/issues/761
|
||||
home.file."${config.xdg.cacheHome}/oh-my-zsh/.keep".text = "";
|
||||
})
|
||||
|
||||
(mkIf (cfg.plugins != [ ]) {
|
||||
# Many plugins require compinit to be called
|
||||
# but allow the user to opt out.
|
||||
|
|
|
|||
102
modules/programs/zsh/oh-my-zsh.nix
Normal file
102
modules/programs/zsh/oh-my-zsh.nix
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib) mkOption optionalString types;
|
||||
|
||||
relToDotDir =
|
||||
file:
|
||||
(lib.optionalString (config.programs.zsh.dotDir != null) (config.programs.zsh.dotDir + "/")) + file;
|
||||
|
||||
cfg = config.programs.zsh;
|
||||
|
||||
ohMyZshModule = types.submodule {
|
||||
options = {
|
||||
enable = lib.mkEnableOption "oh-my-zsh";
|
||||
|
||||
package = lib.mkPackageOption pkgs "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>
|
||||
for more information.
|
||||
'';
|
||||
};
|
||||
|
||||
theme = mkOption {
|
||||
default = "";
|
||||
example = "robbyrussell";
|
||||
type = types.str;
|
||||
description = ''
|
||||
Name of the theme to be used by oh-my-zsh.
|
||||
'';
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
default = "";
|
||||
example = ''
|
||||
zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github
|
||||
'';
|
||||
type = types.lines;
|
||||
description = ''
|
||||
Extra settings for plugins.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.programs.zsh.oh-my-zsh = mkOption {
|
||||
type = ohMyZshModule;
|
||||
default = { };
|
||||
description = "Options to configure oh-my-zsh.";
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.oh-my-zsh.enable {
|
||||
home = {
|
||||
packages = [ cfg.oh-my-zsh.package ];
|
||||
|
||||
file = {
|
||||
"${relToDotDir ".zshenv"}".text = ''
|
||||
ZSH="${cfg.oh-my-zsh.package}/share/oh-my-zsh";
|
||||
ZSH_CACHE_DIR="${config.xdg.cacheHome}/oh-my-zsh";
|
||||
'';
|
||||
|
||||
# Make sure we create a cache directory since some plugins expect it to exist
|
||||
# See: https://github.com/nix-community/home-manager/issues/761
|
||||
"${config.xdg.cacheHome}/oh-my-zsh/.keep".text = "";
|
||||
};
|
||||
};
|
||||
|
||||
programs.zsh.initContent = lib.mkOrder 800 ''
|
||||
# oh-my-zsh extra settings for plugins
|
||||
${cfg.oh-my-zsh.extraConfig}
|
||||
# oh-my-zsh configuration generated by NixOS
|
||||
${optionalString (
|
||||
cfg.oh-my-zsh.plugins != [ ]
|
||||
) "plugins=(${lib.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
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue