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

{
  imports = [ ];

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

  config = lib.mkIf (config.me.pcsx2.enable && config.me.graphical) {
    environment.systemPackages = with pkgs; [
      pcsx2
    ];

    environment.persistence."/state" = lib.mkIf (config.me.mountPersistence) {
      hideMounts = true;
      users.talexander = {
        directories = [
          {
            # Shaders, games list, and achievement data.
            directory = ".config/PCSX2/cache";
            user = "talexander";
            group = "talexander";
            mode = "0755";
          }
          {
            # Save states.
            directory = ".config/PCSX2/sstates";
            user = "talexander";
            group = "talexander";
            mode = "0755";
          }
          {
            # Screenshots.
            directory = ".config/PCSX2/snaps";
            user = "talexander";
            group = "talexander";
            mode = "0755";
          }
          {
            # Game covers.
            directory = ".config/PCSX2/covers";
            user = "talexander";
            group = "talexander";
            mode = "0755";
          }
          {
            # Video recordings.
            directory = ".config/PCSX2/videos";
            user = "talexander";
            group = "talexander";
            mode = "0755";
          }
        ];
      };
    };

    environment.persistence."/persist" = lib.mkIf (config.me.mountPersistence) {
      hideMounts = true;
      users.talexander = {
        directories = [
          {
            # Game saves
            directory = ".config/PCSX2/memcards";
            user = "talexander";
            group = "talexander";
            mode = "0755";
          }
        ];
      };
    };

    me.install.user.talexander.file = {
      ".config/PCSX2/inis/PCSX2.ini" = {
        source = ./files/PCSX2.ini;
      };
    };
  };
}
