{
  options,
  config,
  lib,
  pkgs,
  ...
}:
with lib;
with lib.my; let
  cfg = config.modules.shell.zsh;
  configDir = builtins.toString ../../../config;
  cfgType = config.type;
in {
  options.modules.shell.zsh = with types; {
    enable = mkBoolOpt false;

    aliases = mkOpt (attrsOf (either str path)) {};

    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 {
    programs = {
      zsh = {
        enable = true;
        enableCompletion = true;
        syntaxHighlighting.enable = true;
        shellAliases = {
          ls = "${pkgs.eza}/bin/eza -al --color=always --group-directories-first";
          la = "${pkgs.eza}/bin/eza -a --color=always --group-directories-first";
          ll = "${pkgs.eza}/bin/eza -l --color=always --group-directories-first"; 
          lt = "${pkgs.eza}/bin/eza -aT --color=always --group-directories-first"; 
          g = "git";
          v = "vim";
        };
      };
    };

    modules.${cfgType}.shell.zsh = let
      zshDir = "${configDir}/zsh";
    in {
      zshrc = ''${builtins.readFile "${zshDir}/.zshrc"}'';
      zshenv = ''${builtins.readFile "${zshDir}/.zshenv"}'';
    };

    core.userPackages = with pkgs; [
      nix-zsh-completions
      eza
      fasd
      fd
      ripgrep
    ];

    env = {
      ZDOTDIR = "$XDG_CONFIG_HOME/zsh";
      ZSH_CACHE = "$XDG_CACHE_HOME/zsh";
    };

    home.configFile = {
      "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}
      '';
    };
  };
}
