at 18.09-beta 3.4 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.programs.zsh.ohMyZsh; 8 9 mkLinkFarmEntry = name: dir: 10 let 11 env = pkgs.buildEnv { 12 name = "zsh-${name}-env"; 13 paths = cfg.customPkgs; 14 pathsToLink = "/share/zsh/${dir}"; 15 }; 16 in 17 { inherit name; path = "${env}/share/zsh/${dir}"; }; 18 19 mkLinkFarmEntry' = name: mkLinkFarmEntry name name; 20 21 custom = 22 if cfg.custom != null then cfg.custom 23 else if length cfg.customPkgs == 0 then null 24 else pkgs.linkFarm "oh-my-zsh-custom" [ 25 (mkLinkFarmEntry' "themes") 26 (mkLinkFarmEntry "completions" "site-functions") 27 (mkLinkFarmEntry' "plugins") 28 ]; 29 30in 31 { 32 options = { 33 programs.zsh.ohMyZsh = { 34 enable = mkOption { 35 default = false; 36 description = '' 37 Enable oh-my-zsh. 38 ''; 39 }; 40 41 package = mkOption { 42 default = pkgs.oh-my-zsh; 43 defaultText = "pkgs.oh-my-zsh"; 44 description = '' 45 Package to install for `oh-my-zsh` usage. 46 ''; 47 48 type = types.package; 49 }; 50 51 plugins = mkOption { 52 default = []; 53 type = types.listOf(types.str); 54 description = '' 55 List of oh-my-zsh plugins 56 ''; 57 }; 58 59 custom = mkOption { 60 default = null; 61 type = with types; nullOr str; 62 description = '' 63 Path to a custom oh-my-zsh package to override config of oh-my-zsh. 64 (Can't be used along with `customPkgs`). 65 ''; 66 }; 67 68 customPkgs = mkOption { 69 default = []; 70 type = types.listOf types.package; 71 description = '' 72 List of custom packages that should be loaded into `oh-my-zsh`. 73 ''; 74 }; 75 76 theme = mkOption { 77 default = ""; 78 type = types.str; 79 description = '' 80 Name of the theme to be used by oh-my-zsh. 81 ''; 82 }; 83 84 cacheDir = mkOption { 85 default = "$HOME/.cache/oh-my-zsh"; 86 type = types.str; 87 description = '' 88 Cache directory to be used by `oh-my-zsh`. 89 Without this option it would default to the read-only nix store. 90 ''; 91 }; 92 }; 93 }; 94 95 config = mkIf cfg.enable { 96 97 # Prevent zsh from overwriting oh-my-zsh's prompt 98 programs.zsh.promptInit = mkDefault ""; 99 100 environment.systemPackages = [ cfg.package ]; 101 102 programs.zsh.interactiveShellInit = '' 103 # oh-my-zsh configuration generated by NixOS 104 export ZSH=${cfg.package}/share/oh-my-zsh 105 106 ${optionalString (length(cfg.plugins) > 0) 107 "plugins=(${concatStringsSep " " cfg.plugins})" 108 } 109 110 ${optionalString (custom != null) 111 "ZSH_CUSTOM=\"${custom}\"" 112 } 113 114 ${optionalString (stringLength(cfg.theme) > 0) 115 "ZSH_THEME=\"${cfg.theme}\"" 116 } 117 118 ${optionalString (cfg.cacheDir != null) '' 119 if [[ ! -d "${cfg.cacheDir}" ]]; then 120 mkdir -p "${cfg.cacheDir}" 121 fi 122 ZSH_CACHE_DIR=${cfg.cacheDir} 123 ''} 124 125 source $ZSH/oh-my-zsh.sh 126 ''; 127 128 assertions = [ 129 { 130 assertion = cfg.custom != null -> cfg.customPkgs == []; 131 message = "If `cfg.custom` is set for `ZSH_CUSTOM`, `customPkgs` can't be used!"; 132 } 133 ]; 134 135 }; 136 137 meta.doc = ./oh-my-zsh.xml; 138 }