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

with lib;

let
  cfg = config.sydnix.impermanence;
in {
  options = {
    sydnix.impermanence = {
      enable = mkEnableOption "impermanence";

      directories = mkOption {
        default = [];
        type = types.listOf types.anything;
      };

      files = mkOption {
        default = [];
        type = types.listOf types.anything;
      };

      cache = {
        directories = mkOption {
          description = ''
            While functionally identical to `directories` (at the moment),
            `cache.directories` carries additional semantics: these directories
            /can/ be erased, but typically /shouldn't/ be.
          '';
          default = [];
          type = types.listOf types.anything;
        };

        files = mkOption {
          description = ''
            While functionally identical to `files` (at the moment),
            `cache.files` carries additional semantics: these files /can/ be
            erased, but typically /shouldn't/ be.
          '';
          default = [];
          type = types.listOf types.anything;
        };
      };
    };
  };

  config = mkIf cfg.enable {
    home.persistence = {
      "/persist/home/${config.home.username}" = {
        allowOther = true;
        directories = cfg.directories ++ cfg.cache.directories;
        files = cfg.files ++ cfg.cache.files;
      };
    };
  };
}
