2017-04-23 12:58:07 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2018-07-10 14:52:30 +01:00
|
|
|
|
2017-05-25 09:51:26 +01:00
|
|
|
cfg = config.programs.zsh.ohMyZsh;
|
2018-07-10 14:52:30 +01:00
|
|
|
|
|
|
|
mkLinkFarmEntry = name: dir:
|
|
|
|
let
|
|
|
|
env = pkgs.buildEnv {
|
|
|
|
name = "zsh-${name}-env";
|
|
|
|
paths = cfg.customPkgs;
|
|
|
|
pathsToLink = "/share/zsh/${dir}";
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{ inherit name; path = "${env}/share/zsh/${dir}"; };
|
|
|
|
|
|
|
|
mkLinkFarmEntry' = name: mkLinkFarmEntry name name;
|
|
|
|
|
|
|
|
custom =
|
|
|
|
if cfg.custom != null then cfg.custom
|
|
|
|
else if length cfg.customPkgs == 0 then null
|
|
|
|
else pkgs.linkFarm "oh-my-zsh-custom" [
|
|
|
|
(mkLinkFarmEntry' "themes")
|
|
|
|
(mkLinkFarmEntry "completions" "site-functions")
|
|
|
|
(mkLinkFarmEntry' "plugins")
|
|
|
|
];
|
|
|
|
|
2017-04-23 12:58:07 +01:00
|
|
|
in
|
|
|
|
{
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "programs" "zsh" "oh-my-zsh" "enable" ] [ "programs" "zsh" "ohMyZsh" "enable" ])
|
|
|
|
(mkRenamedOptionModule [ "programs" "zsh" "oh-my-zsh" "theme" ] [ "programs" "zsh" "ohMyZsh" "theme" ])
|
|
|
|
(mkRenamedOptionModule [ "programs" "zsh" "oh-my-zsh" "custom" ] [ "programs" "zsh" "ohMyZsh" "custom" ])
|
|
|
|
(mkRenamedOptionModule [ "programs" "zsh" "oh-my-zsh" "plugins" ] [ "programs" "zsh" "ohMyZsh" "plugins" ])
|
|
|
|
];
|
|
|
|
|
2017-04-23 12:58:07 +01:00
|
|
|
options = {
|
2017-05-25 09:51:26 +01:00
|
|
|
programs.zsh.ohMyZsh = {
|
2017-04-23 12:58:07 +01:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable oh-my-zsh.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-07-18 15:42:52 +01:00
|
|
|
package = mkOption {
|
|
|
|
default = pkgs.oh-my-zsh;
|
|
|
|
defaultText = "pkgs.oh-my-zsh";
|
|
|
|
description = ''
|
|
|
|
Package to install for `oh-my-zsh` usage.
|
|
|
|
'';
|
|
|
|
|
|
|
|
type = types.package;
|
|
|
|
};
|
|
|
|
|
2017-04-23 12:58:07 +01:00
|
|
|
plugins = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = types.listOf(types.str);
|
|
|
|
description = ''
|
|
|
|
List of oh-my-zsh plugins
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
custom = mkOption {
|
2018-07-10 14:52:30 +01:00
|
|
|
default = null;
|
|
|
|
type = with types; nullOr str;
|
2017-04-23 12:58:07 +01:00
|
|
|
description = ''
|
|
|
|
Path to a custom oh-my-zsh package to override config of oh-my-zsh.
|
2018-07-10 14:52:30 +01:00
|
|
|
(Can't be used along with `customPkgs`).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
customPkgs = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = types.listOf types.package;
|
|
|
|
description = ''
|
|
|
|
List of custom packages that should be loaded into `oh-my-zsh`.
|
2017-04-23 12:58:07 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
theme = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Name of the theme to be used by oh-my-zsh.
|
|
|
|
'';
|
|
|
|
};
|
2018-01-16 17:29:46 +00:00
|
|
|
|
|
|
|
cacheDir = mkOption {
|
|
|
|
default = "$HOME/.cache/oh-my-zsh";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Cache directory to be used by `oh-my-zsh`.
|
2018-01-16 20:02:54 +00:00
|
|
|
Without this option it would default to the read-only nix store.
|
2018-01-16 17:29:46 +00:00
|
|
|
'';
|
|
|
|
};
|
2017-04-23 12:58:07 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2017-05-09 16:07:18 +01:00
|
|
|
|
|
|
|
# Prevent zsh from overwriting oh-my-zsh's prompt
|
|
|
|
programs.zsh.promptInit = mkDefault "";
|
|
|
|
|
2017-07-18 15:42:52 +01:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2017-04-23 12:58:07 +01:00
|
|
|
|
2018-07-10 14:52:30 +01:00
|
|
|
programs.zsh.interactiveShellInit = ''
|
2017-04-23 12:58:07 +01:00
|
|
|
# oh-my-zsh configuration generated by NixOS
|
2017-07-18 15:42:52 +01:00
|
|
|
export ZSH=${cfg.package}/share/oh-my-zsh
|
2017-04-23 12:58:07 +01:00
|
|
|
|
|
|
|
${optionalString (length(cfg.plugins) > 0)
|
|
|
|
"plugins=(${concatStringsSep " " cfg.plugins})"
|
|
|
|
}
|
|
|
|
|
2018-07-10 14:52:30 +01:00
|
|
|
${optionalString (custom != null)
|
|
|
|
"ZSH_CUSTOM=\"${custom}\""
|
2017-04-23 12:58:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
${optionalString (stringLength(cfg.theme) > 0)
|
|
|
|
"ZSH_THEME=\"${cfg.theme}\""
|
|
|
|
}
|
|
|
|
|
2018-01-16 17:29:46 +00:00
|
|
|
${optionalString (cfg.cacheDir != null) ''
|
|
|
|
if [[ ! -d "${cfg.cacheDir}" ]]; then
|
|
|
|
mkdir -p "${cfg.cacheDir}"
|
|
|
|
fi
|
|
|
|
ZSH_CACHE_DIR=${cfg.cacheDir}
|
|
|
|
''}
|
|
|
|
|
2017-04-23 12:58:07 +01:00
|
|
|
source $ZSH/oh-my-zsh.sh
|
|
|
|
'';
|
2018-07-10 14:52:30 +01:00
|
|
|
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.custom != null -> cfg.customPkgs == [];
|
|
|
|
message = "If `cfg.custom` is set for `ZSH_CUSTOM`, `customPkgs` can't be used!";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2017-04-23 12:58:07 +01:00
|
|
|
};
|
2018-08-07 14:38:20 +01:00
|
|
|
|
|
|
|
meta.doc = ./oh-my-zsh.xml;
|
2017-04-23 12:58:07 +01:00
|
|
|
}
|