main
 1{lib, ...}: {
 2  flake.modules.homeManager.desktop = {
 3    pkgs,
 4    config,
 5    osConfig,
 6    ...
 7  }: let
 8    getThunderbirdAccountPath = accountName: profileName: let
 9      accountId = builtins.hashString "sha256" accountName;
10      thunderbirdProfilesPath = ".thunderbird";
11    in "${config.home.homeDirectory}/${thunderbirdProfilesPath}/${profileName}/ImapMail/${accountId}";
12    thunderbird-x = pkgs.thunderbird-bin.overrideAttrs (oldAttrs: {
13      makeWrapperArgs = oldAttrs.makeWrapperArgs ++ ["--set" "MOZ_ENABLE_WAYLAND" "0"];
14    });
15
16    isNiri = osConfig.programs.niri.enable;
17  in
18    lib.mkIf (pkgs.stdenv.hostPlatform.isLinux && !isNiri) {
19      programs.thunderbird.package = thunderbird-x;
20
21      home.packages = with pkgs; [
22        birdtray
23      ];
24
25      xdg.configFile."birdtray-config.json" = {
26        force = true;
27        text = builtins.toJSON (
28          (builtins.fromJSON (builtins.readFile ./birdtray-default-config.json))
29          // {
30            accounts =
31              lib.mapAttrsToList (n: v: {
32                path = "${getThunderbirdAccountPath v.name "Default"}/INBOX.msf";
33              })
34              (lib.filterAttrs (n: v: v.thunderbird.enable) config.accounts.email.accounts);
35          }
36          // (lib.mapAttrs' (n: v: lib.nameValuePair "common/${n}" v) {
37            launchthunderbird = true;
38            exitthunderbirdonquit = true;
39            defaultcolor = "#c6a0f6"; # Catppucin Macchiato Mauve
40            hideWhenStartedManually = false;
41            hidewhenminimized = true;
42            hidewhenrestarted = true;
43            hidewhenstarted = true;
44            showhidethunderbird = true;
45            restartthunderbird = true;
46            startClosedThunderbird = true;
47          })
48          // (lib.mapAttrs' (n: v: lib.nameValuePair "advanced/${n}" v) {
49            tbcmdline = [(lib.getExe thunderbird-x)];
50            tbwindowmatch = "Thunderbird";
51            updateOnStartup = false;
52            unreadopacitylevel = 0.80;
53          })
54        );
55      };
56
57      xdg.autostart = {
58        enable = true;
59        entries = ["${pkgs.birdtray}/share/applications/com.ulduzsoft.Birdtray.desktop"];
60      };
61    };
62}