{
  config,
  lib,
  pkgs,
  ...
}:

let
  direnv_zsh_hook = pkgs.writeTextFile {
    name = "direnv_zsh_hook.zsh";
    text = ''
      eval "$(direnv hook zsh)"
    '';
  };
in
{
  imports = [ ];

  options.me = {
    direnv.enable = lib.mkOption {
      type = lib.types.bool;
      default = false;
      example = true;
      description = "Whether we want to install direnv.";
    };
  };

  config = lib.mkIf config.me.direnv.enable {
    environment.systemPackages = with pkgs; [
      direnv
      nix-direnv
    ];

    me.zsh.includes = [ direnv_zsh_hook ];

    environment.persistence."/persist" = lib.mkIf (config.me.mountPersistence) {
      hideMounts = true;
      users.talexander = {
        directories = [
          {
            # List of allowed directories from `direnv allow`.
            directory = ".local/share/direnv";
            user = "talexander";
            group = "talexander";
            mode = "0755";
          }
        ];
      };
    };
  };
}
