{
  config,
  lib,
  pkgs,
  home-manager,
  ...
}:

{
  imports = [ ];

  options.me = {
    persist.directories = lib.mkOption {
      type = lib.types.listOf lib.types.str;
      default = [ ];
      example = [ ".local/share/dolphin-emu/Wii" ];
      description = "List of folders relative to the home directory to persist.";
    };
    persist.files = lib.mkOption {
      type = lib.types.listOf lib.types.str;
      default = [ ];
      example = [ ".local/share/foo.sqlite3" ];
      description = "List of files relative to the home directory to persist.";
    };
    state.directories = lib.mkOption {
      type = lib.types.listOf lib.types.str;
      default = [ ];
      example = [ ".local/share/dolphin-emu/Shaders" ];
      description = "List of folders relative to the home directory to keep as state.";
    };
  };

  config = lib.mkMerge [
    (lib.mkIf (config.me.persist.directories != [ ]) {
      home.persistence."/home/deck/.persist" = {
        directories = (
          builtins.map (entry: {
            directory = entry;
            method = "symlink";
          }) config.me.persist.directories
        );
      };

      home.activation = {
        createPersistDirectories = home-manager.lib.hm.dag.entryAfter [ "writeBoundary" ] (
          let
            dirlist = lib.strings.escapeShellArgs config.me.persist.directories;
          in
          ''
            for dir in ${dirlist} ; do
              if [[ ! -d "$HOME/.persist/$dir" ]]; then
                $DRY_RUN_CMD mkdir $VERBOSE_ARG -p "$HOME/.persist/$dir"
              fi
            done
          ''
        );
      };
    })
    (lib.mkIf (config.me.persist.files != [ ]) {
      home.persistence."/home/deck/.persist" = {
        files = config.me.persist.files;
      };
    })
    (lib.mkIf (config.me.state.directories != [ ]) {
      home.persistence."/home/deck/.state" = {
        directories = (
          builtins.map (entry: {
            directory = entry;
            method = "symlink";
          }) config.me.state.directories
        );
      };

      home.activation = {
        createStateDirectories = home-manager.lib.hm.dag.entryAfter [ "writeBoundary" ] (
          let
            dirlist = lib.strings.escapeShellArgs config.me.state.directories;
          in
          ''
            for dir in ${dirlist} ; do
              if [[ ! -d "$HOME/.state/$dir" ]]; then
                $DRY_RUN_CMD mkdir $VERBOSE_ARG -p "$HOME/.state/$dir"
              fi
            done
          ''
        );
      };
    })
  ];
}
