2020-03-28 22:48:43 -07:00
|
|
|
{ config, options, pkgs, lib, ... }:
|
2020-10-01 15:46:04 -07:00
|
|
|
|
2020-03-28 22:48:43 -07:00
|
|
|
with lib;
|
2020-10-01 15:46:04 -07:00
|
|
|
with lib.my;
|
|
|
|
let cfg = config.modules.shell.zsh;
|
|
|
|
in {
|
|
|
|
options.modules.shell.zsh = with types; {
|
|
|
|
enable = mkBoolOpt false;
|
2020-01-12 15:17:17 -08:00
|
|
|
|
2020-10-01 15:46:04 -07:00
|
|
|
aliases = mkOpt (attrsOf (either str path)) {};
|
2020-03-28 22:48:43 -07:00
|
|
|
|
2020-10-01 15:46:04 -07:00
|
|
|
rcInit = mkOpt' lines "" ''
|
|
|
|
Zsh lines to be written to $XDG_CONFIG_HOME/zsh/extra.zshrc and sourced by
|
|
|
|
$XDG_CONFIG_HOME/zsh/.zshrc
|
|
|
|
'';
|
|
|
|
envInit = mkOpt' lines "" ''
|
|
|
|
Zsh lines to be written to $XDG_CONFIG_HOME/zsh/extra.zshenv and sourced
|
|
|
|
by $XDG_CONFIG_HOME/zsh/.zshenv
|
|
|
|
'';
|
|
|
|
|
|
|
|
rcFiles = mkOpt (listOf (either str path)) [];
|
|
|
|
envFiles = mkOpt (listOf (either str path)) [];
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
users.defaultUserShell = pkgs.zsh;
|
2019-08-06 10:56:54 -07:00
|
|
|
|
2020-03-28 22:48:43 -07:00
|
|
|
programs.zsh = {
|
|
|
|
enable = true;
|
|
|
|
enableCompletion = true;
|
2020-10-01 15:46:04 -07:00
|
|
|
# I init completion myself, because enableGlobalCompInit initializes it
|
|
|
|
# too soon, which means commands initialized later in my config won't get
|
2020-03-28 22:48:43 -07:00
|
|
|
# completion, and running compinit twice is slow.
|
|
|
|
enableGlobalCompInit = false;
|
|
|
|
promptInit = "";
|
|
|
|
};
|
2020-01-17 01:22:50 -08:00
|
|
|
|
2020-10-01 15:46:04 -07:00
|
|
|
user.packages = with pkgs; [
|
|
|
|
zsh
|
|
|
|
nix-zsh-completions
|
|
|
|
bat
|
|
|
|
exa
|
|
|
|
fasd
|
|
|
|
fd
|
|
|
|
fzf
|
|
|
|
tldr
|
2021-01-20 19:27:43 -08:00
|
|
|
ripgrep
|
2020-10-01 15:46:04 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
env = {
|
|
|
|
ZDOTDIR = "$XDG_CONFIG_HOME/zsh";
|
|
|
|
ZSH_CACHE = "$XDG_CACHE_HOME/zsh";
|
|
|
|
ZGEN_DIR = "$XDG_DATA_HOME/zsh";
|
|
|
|
ZGEN_SOURCE = "$ZGEN_DIR/zgen.zsh";
|
|
|
|
};
|
|
|
|
|
|
|
|
home.configFile = {
|
|
|
|
# Write it recursively so other modules can write files to it
|
|
|
|
"zsh" = { source = "${configDir}/zsh"; recursive = true; };
|
|
|
|
|
|
|
|
# Why am I creating extra.zsh{rc,env} when I could be using extraInit?
|
|
|
|
# Because extraInit generates those files in /etc/profile, and mine just
|
|
|
|
# write the files to ~/.config/zsh; where it's easier to edit and tweak
|
|
|
|
# them in case of issues or when experimenting.
|
|
|
|
"zsh/extra.zshrc".text =
|
|
|
|
let aliasLines = mapAttrsToList (n: v: "alias ${n}=\"${v}\"") cfg.aliases;
|
|
|
|
in ''
|
|
|
|
# This file was autogenerated, do not edit it!
|
|
|
|
${concatStringsSep "\n" aliasLines}
|
|
|
|
${concatMapStrings (path: "source '${path}'\n") cfg.rcFiles}
|
|
|
|
${cfg.rcInit}
|
|
|
|
'';
|
|
|
|
|
|
|
|
"zsh/extra.zshenv".text = ''
|
|
|
|
# This file is autogenerated, do not edit it!
|
|
|
|
${concatMapStrings (path: "source '${path}'\n") cfg.envFiles}
|
|
|
|
${cfg.envInit}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-05 22:57:44 -07:00
|
|
|
system.userActivationScripts.cleanupZgen = "rm -fv $XDG_CACHE_HOME/zsh/*";
|
2020-03-28 22:48:43 -07:00
|
|
|
};
|
2019-08-06 10:56:54 -07:00
|
|
|
}
|