1 { config, lib, pkgs, ... }:
5 cfg = config.programs.zsh.ohMyZsh;
7 mkLinkFarmEntry = name: dir:
10 name = "zsh-${name}-env";
11 paths = cfg.customPkgs;
12 pathsToLink = "/share/zsh/${dir}";
15 { inherit name; path = "${env}/share/zsh/${dir}"; };
17 mkLinkFarmEntry' = name: mkLinkFarmEntry name name;
20 if cfg.custom != null then cfg.custom
21 else if builtins.length cfg.customPkgs == 0 then null
22 else pkgs.linkFarm "oh-my-zsh-custom" [
23 (mkLinkFarmEntry' "themes")
24 (mkLinkFarmEntry "completions" "site-functions")
25 (mkLinkFarmEntry' "plugins")
31 (lib.mkRenamedOptionModule [ "programs" "zsh" "oh-my-zsh" "enable" ] [ "programs" "zsh" "ohMyZsh" "enable" ])
32 (lib.mkRenamedOptionModule [ "programs" "zsh" "oh-my-zsh" "theme" ] [ "programs" "zsh" "ohMyZsh" "theme" ])
33 (lib.mkRenamedOptionModule [ "programs" "zsh" "oh-my-zsh" "custom" ] [ "programs" "zsh" "ohMyZsh" "custom" ])
34 (lib.mkRenamedOptionModule [ "programs" "zsh" "oh-my-zsh" "plugins" ] [ "programs" "zsh" "ohMyZsh" "plugins" ])
38 programs.zsh.ohMyZsh = {
39 enable = lib.mkOption {
40 type = lib.types.bool;
47 package = lib.mkPackageOption pkgs "oh-my-zsh" { };
49 plugins = lib.mkOption {
51 type = lib.types.listOf(lib.types.str);
53 List of oh-my-zsh plugins
57 custom = lib.mkOption {
59 type = with lib.types; nullOr str;
61 Path to a custom oh-my-zsh package to override config of oh-my-zsh.
62 (Can't be used along with `customPkgs`).
66 customPkgs = lib.mkOption {
68 type = lib.types.listOf lib.types.package;
70 List of custom packages that should be loaded into `oh-my-zsh`.
74 theme = lib.mkOption {
78 Name of the theme to be used by oh-my-zsh.
82 cacheDir = lib.mkOption {
83 default = "$HOME/.cache/oh-my-zsh";
86 Cache directory to be used by `oh-my-zsh`.
87 Without this option it would default to the read-only nix store.
93 config = lib.mkIf cfg.enable {
95 # Prevent zsh from overwriting oh-my-zsh's prompt
96 programs.zsh.promptInit = lib.mkDefault "";
98 environment.systemPackages = [ cfg.package ];
100 programs.zsh.interactiveShellInit = ''
101 # oh-my-zsh configuration generated by NixOS
102 export ZSH=${cfg.package}/share/oh-my-zsh
104 ${lib.optionalString (builtins.length(cfg.plugins) > 0)
105 "plugins=(${builtins.concatStringsSep " " cfg.plugins})"
108 ${lib.optionalString (custom != null)
109 "ZSH_CUSTOM=\"${custom}\""
112 ${lib.optionalString (builtins.stringLength(cfg.theme) > 0)
113 "ZSH_THEME=\"${cfg.theme}\""
116 ${lib.optionalString (cfg.cacheDir != null) ''
117 if [[ ! -d "${cfg.cacheDir}" ]]; then
118 mkdir -p "${cfg.cacheDir}"
120 ZSH_CACHE_DIR=${cfg.cacheDir}
123 source $ZSH/oh-my-zsh.sh
128 assertion = cfg.custom != null -> cfg.customPkgs == [];
129 message = "If `cfg.custom` is set for `ZSH_CUSTOM`, `customPkgs` can't be used!";
135 meta.doc = ./oh-my-zsh.md;