{ lib, pkgs, config, ... }: let cfg = config.programs.proton-calendar-pwa; isChromium = cfg.package == pkgs.chromium; isBrowserImpermanenceSupported = cfg.package == pkgs.chromium; in { options.programs.proton-calendar-pwa = { enable = lib.mkEnableOption "enable Proton Calendar PWA"; package = lib.mkOption { type = lib.types.package; default = pkgs.chromium; description = "Browser package to use for the PWA"; }; impermanence = { enable = lib.mkOption { type = lib.types.bool; default = isBrowserImpermanenceSupported; description = "Enable impermanence configuration for the PWA. Only automatically enabled when using chromium."; }; }; }; config = lib.mkIf cfg.enable (lib.mkMerge [ { warnings = lib.optional (config.impermanence.enable && !isBrowserImpermanenceSupported) "proton-calendar-pwa: Using unsupported package. You will need to manually configure pwa for ${cfg.package.pname}. Supported package(s) ${pkgs.chromium.pname}"; } ( lib.mkIf isChromium { xdg.desktopEntries.proton-calendar-pwa = { name = "Proton Calendar"; type = "Application"; exec = "${cfg.package}/bin/${cfg.package.pname} --app=https://calendar.proton.me"; icon = "chrome-ojibjkjikcpjonjjngfkegflhmffeemk-Default"; terminal = false; }; } ) ( lib.mkIf (config.impermanence.enable && cfg.impermanence.enable && isChromium) { home.persistence."/persist${config.home.homeDirectory}" = { directories = [ "${config.xdg.configHome}/chromium" ]; allowOther = true; }; } ) ]); }