{ pkgs
, lib
, config
, ... }: with lib; let
  cfg = config.global.flatpak;
in {
  options.global.flatpak = {
    enable = mkEnableOption "flatpak sandbox";
  };

  config = mkIf cfg.enable {
    services.flatpak.enable = true;
    xdg.portal.enable = true;
    users.home.persist.directories = [ ".local/share/flatpak" ];
    environment.persistence."/nix/persist/fhs".directories = [ "/var/lib/flatpak" ];
  };
}
