From a0d7e43a9d690d49804c1f245efcab6881fe8216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Sat, 9 Mar 2024 23:50:31 +0100 Subject: [PATCH] account: Add support --- hm/accounts/default.nix | 103 ++++++++++++++++++++++++++++++++++++++++ hm/default.nix | 1 + hm/desktop/default.nix | 3 -- 3 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 hm/accounts/default.nix diff --git a/hm/accounts/default.nix b/hm/accounts/default.nix new file mode 100644 index 0000000..018151d --- /dev/null +++ b/hm/accounts/default.nix @@ -0,0 +1,103 @@ +{ pkgs, config, lib, ... }: +let + mkUserJs = with lib; prefs: extraPrefs: '' + // Generated by Geoffrey's dotfiles. + + ${concatStrings (mapAttrsToList (name: value: '' + user_pref("${name}", ${builtins.toJSON value}); + '') prefs)} + ${extraPrefs} + ''; + + toThunderbirdCalendar = account: + let + id = builtins.hashString "sha256" account.name; + thunderbird = config.frogeye.accounts.calendar.accounts.${account.name}; + in + { + "calendar.registry.${id}.cache.enabled" = thunderbird.offlineSupport; # TODO Check this actually corresponds + "calendar.registry.${id}.color" = thunderbird.color; + "calendar.registry.${id}.forceEmailScheduling" = thunderbird.clientSideEmailScheduling; + "calendar.registry.${id}.imip.identity.key" = "id_${builtins.hashString "sha256" thunderbird.email}"; + "calendar.registry.${id}.name" = account.name; + "calendar.registry.${id}.readOnly" = thunderbird.readOnly; + "calendar.registry.${id}.refreshInterval" = builtins.toString thunderbird.refreshInterval; + "calendar.registry.${id}.suppressAlarms" = !thunderbird.showReminders; # TODO Check this actually corresponds + "calendar.registry.${id}.type" = account.remote.type; # TODO Check and validate supported types + "calendar.registry.${id}.uri" = account.remote.url; + "calendar.registry.${id}.username" = account.remote.userName; + # Unimplemented + "calendar.registry.${id}.notifications.times" = ""; + # Unknown + # "calendar.registry.${id}.calendar-main-in-composite" = true; + }; +in +{ + config = { + programs.thunderbird = { + enable = config.frogeye.desktop.xorg; + profiles.hm = { + isDefault = true; + withExternalGnupg = true; + extraConfig = mkUserJs + (lib.attrsets.mergeAttrsList ( + # Add calendar config + (lib.mapAttrsToList (name: account: (toThunderbirdCalendar account)) config.accounts.calendar.accounts) ++ + # Add config for every identity (kinda) + (lib.mapAttrsToList + (name: account: ({ + # UPST Make signature be used in Thunderbird + "mail.identity.id_${builtins.hashString "sha256" account.address}.htmlSigText" = account.signature.text; + "mail.identity.id_${builtins.hashString "sha256" account.address}.compose_html" = false; + })) + config.accounts.email.accounts) ++ + # General settings + [{ + "mail.pane_config.dynamic" = 0; + }] + + )) ""; + }; + }; + }; + # UPST Thunderbird-specific options (should be named so), to be included in HM Thunderbird module + options = { + frogeye.accounts.calendar.accounts = lib.mkOption { + default = { }; + type = lib.types.attrsOf (lib.types.submodule ({ config, name, ... }: { + # TODO Set defaults as Thunderbird sets it + options = { + color = lib.mkOption { + type = lib.types.str; + default = "#5277c3"; + }; + refreshInterval = lib.mkOption { + type = lib.types.int; + default = 0; # 0 = Manual + }; + readOnly = lib.mkOption { + type = lib.types.bool; + default = false; + }; + showReminders = lib.mkOption { + type = lib.types.bool; + default = true; + }; + offlineSupport = lib.mkOption { + type = lib.types.bool; + default = true; + }; + email = lib.mkOption { + type = lib.types.str; + # TODO Nullable + # TODO Ensure it actually matches an email identity + }; + clientSideEmailScheduling = lib.mkOption { + type = lib.types.bool; + default = false; + }; + }; + })); + }; + }; +} diff --git a/hm/default.nix b/hm/default.nix index 04061d8..355533f 100644 --- a/hm/default.nix +++ b/hm/default.nix @@ -3,6 +3,7 @@ imports = [ ../common/frogarized ../options.nix + ./accounts ./brightness ./common.nix ./desktop diff --git a/hm/desktop/default.nix b/hm/desktop/default.nix index 95bb15c..5450552 100644 --- a/hm/desktop/default.nix +++ b/hm/desktop/default.nix @@ -158,9 +158,6 @@ in xclip keynav xorg.xinit - - # organisation - thunderbird ]; sessionVariables = { # XAUTHORITY = "${config.xdg.configHome}/Xauthority"; # Disabled as this causes lock-ups with DMs