10 cfg = config.programs.zsh.ohMyZsh;
16 name = "zsh-${name}-env";
17 paths = cfg.customPkgs;
18 pathsToLink = "/share/zsh/${dir}";
23 path = "${env}/share/zsh/${dir}";
26 mkLinkFarmEntry' = name: mkLinkFarmEntry name name;
29 if cfg.custom != null then
31 else if builtins.length cfg.customPkgs == 0 then
34 pkgs.linkFarm "oh-my-zsh-custom" [
35 (mkLinkFarmEntry' "themes")
36 (mkLinkFarmEntry "completions" "site-functions")
37 (mkLinkFarmEntry' "plugins")
43 (lib.mkRenamedOptionModule
44 [ "programs" "zsh" "oh-my-zsh" "enable" ]
45 [ "programs" "zsh" "ohMyZsh" "enable" ]
47 (lib.mkRenamedOptionModule
48 [ "programs" "zsh" "oh-my-zsh" "theme" ]
49 [ "programs" "zsh" "ohMyZsh" "theme" ]
51 (lib.mkRenamedOptionModule
52 [ "programs" "zsh" "oh-my-zsh" "custom" ]
53 [ "programs" "zsh" "ohMyZsh" "custom" ]
55 (lib.mkRenamedOptionModule
56 [ "programs" "zsh" "oh-my-zsh" "plugins" ]
57 [ "programs" "zsh" "ohMyZsh" "plugins" ]
62 programs.zsh.ohMyZsh = {
63 enable = lib.mkOption {
64 type = lib.types.bool;
71 package = lib.mkPackageOption pkgs "oh-my-zsh" { };
73 plugins = lib.mkOption {
75 type = lib.types.listOf (lib.types.str);
77 List of oh-my-zsh plugins
81 custom = lib.mkOption {
83 type = with lib.types; nullOr str;
85 Path to a custom oh-my-zsh package to override config of oh-my-zsh.
86 (Can't be used along with `customPkgs`).
90 customPkgs = lib.mkOption {
92 type = lib.types.listOf lib.types.package;
94 List of custom packages that should be loaded into `oh-my-zsh`.
98 theme = lib.mkOption {
100 type = lib.types.str;
102 Name of the theme to be used by oh-my-zsh.
106 cacheDir = lib.mkOption {
107 default = "$HOME/.cache/oh-my-zsh";
108 type = lib.types.str;
110 Cache directory to be used by `oh-my-zsh`.
111 Without this option it would default to the read-only nix store.
115 preLoaded = lib.mkOption {
116 type = lib.types.lines;
119 Shell commands executed before the `oh-my-zsh` is loaded.
120 For example, to disable async git prompt write `zstyle ':omz:alpha:lib:git' async-prompt no` (more information https://github.com/ohmyzsh/ohmyzsh?tab=readme-ov-file#async-git-prompt)
126 config = lib.mkIf cfg.enable {
128 # Prevent zsh from overwriting oh-my-zsh's prompt
129 programs.zsh.promptInit = lib.mkDefault "";
131 environment.systemPackages = [ cfg.package ];
133 programs.zsh.interactiveShellInit = ''
134 # oh-my-zsh configuration generated by NixOS
135 export ZSH=${cfg.package}/share/oh-my-zsh
137 ${lib.optionalString (
138 builtins.length (cfg.plugins) > 0
139 ) "plugins=(${builtins.concatStringsSep " " cfg.plugins})"}
141 ${lib.optionalString (custom != null) "ZSH_CUSTOM=\"${custom}\""}
143 ${lib.optionalString (builtins.stringLength (cfg.theme) > 0) "ZSH_THEME=\"${cfg.theme}\""}
145 ${lib.optionalString (cfg.cacheDir != null) ''
146 if [[ ! -d "${cfg.cacheDir}" ]]; then
147 mkdir -p "${cfg.cacheDir}"
149 ZSH_CACHE_DIR=${cfg.cacheDir}
153 source $ZSH/oh-my-zsh.sh
158 assertion = cfg.custom != null -> cfg.customPkgs == [ ];
159 message = "If `cfg.custom` is set for `ZSH_CUSTOM`, `customPkgs` can't be used!";
165 meta.doc = ./oh-my-zsh.md;