1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-01 00:39:45 +01:00
home-manager/modules/programs/zsh.nix

124 lines
3.1 KiB
Nix
Raw Normal View History

2017-08-15 13:54:33 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.zsh;
2017-08-23 12:51:54 +02:00
historyModule = types.submodule {
options = {
size = mkOption {
type = types.int;
default = 10000;
description = "Number of history lines to keep.";
};
path = mkOption {
type = types.str;
default = "$HOME/.zsh_history";
description = "History file location";
};
ignoreDups = mkOption {
type = types.bool;
default = true;
description = ''
Do not enter command lines into the history list
if they are duplicates of the previous event.
'';
};
share = mkOption {
type = types.bool;
default = true;
description = "Share command history between zsh sessions.";
};
};
};
2017-08-15 13:54:33 +02:00
in
{
options = {
programs.zsh = {
enable = mkEnableOption "Z shell (Zsh)";
shellAliases = mkOption {
default = {};
example = { ll = "ls -l"; ".." = "cd .."; };
description = ''
An attribute set that maps aliases (the top level attribute names in
this option) to command strings or directly to build outputs.
'';
type = types.attrs;
};
enableCompletion = mkOption {
default = true;
2017-08-23 12:51:54 +02:00
description = "Enable zsh completion.";
2017-08-15 13:54:33 +02:00
type = types.bool;
};
enableAutosuggestions = mkOption {
default = false;
2017-08-23 12:51:54 +02:00
description = "Enable zsh autosuggestions";
};
history = mkOption {
type = historyModule;
default = {};
description = "Options related to commands history configuration.";
2017-08-15 13:54:33 +02:00
};
initExtra = mkOption {
default = "";
type = types.lines;
description = "Extra commands that should be added to .zshrc.";
};
};
};
config = (
let
aliasesStr = concatStringsSep "\n" (
mapAttrsToList (k: v: "alias ${k}='${v}'") cfg.shellAliases
);
export = n: v: "export ${n}=\"${toString v}\"";
envVarsStr = concatStringsSep "\n" (
mapAttrsToList export config.home.sessionVariables
);
in mkIf cfg.enable {
home.packages = [ pkgs.zsh ]
++ optional cfg.enableCompletion pkgs.nix-zsh-completions;
2017-08-21 14:13:03 +02:00
home.file.".zshenv".text = ''
2017-08-15 13:54:33 +02:00
${optionalString (config.home.sessionVariableSetter == "zsh")
envVarsStr}
'';
home.file.".zshrc".text = ''
2017-08-23 12:51:54 +02:00
${export "HISTSIZE" cfg.history.size}
${export "HISTFILE" cfg.history.path}
setopt HIST_FCNTL_LOCK
${if cfg.history.ignoreDups then "setopt" else "unsetopt"} HIST_IGNORE_DUPS
${if cfg.history.share then "setopt" else "unsetopt"} SHARE_HISTORY
2017-08-15 13:54:33 +02:00
2017-08-23 13:06:19 +02:00
HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help"
2017-08-15 13:54:33 +02:00
${if cfg.enableCompletion then "autoload -U compinit && compinit" else ""}
${optionalString (cfg.enableAutosuggestions)
"source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
}
${aliasesStr}
${cfg.initExtra}
'';
}
);
}