Mozilla Thunderbird (birdtray) on Wayland

I’m stretching the word “guide” here, but thought I’d toss up these snippets from my configuration.

Problem:
Mozilla Thunderbird lacks a system-tray status notification and I’d like to know when new-mail has arrived. I don’t mind Thunderbird running in the background but it can’t be simply open and minimized (as I don’t want it showing up in task-switchers or taking up screen/workspace space).

Solution:

  • birdtray: Wayland support is rough, but it scans Thunderbirds mail folders to know when new-mail has arrived and can launch thunderbird when clicked
  • Thunderbird: Has a --headless flag to run without spawning the GUI. Thunderbird still has a single instance policy though so this will need to be started and stopped when I actually want to use the GUI client
  • Systemd user services: To keep the single-instance of Thunderbird true and start and stop the headless Thunderbird.

Implementation:

Systemd user services to start and stop Thunderbird in headless mode:

      systemd.user.services.thunderbird-monitor = {
         Unit = {
            Description = "Mozilla Thunderbird Monitoring service";
            PartOf = "graphical-session.target";
         };
         Service = {
            # I also use connman, so I delay starting Thunderbird-headless until WAN-connectivity is up
            ExecStartPre = "-${pkgs.connman}/bin/connmand-wait-online --timeout=60";
            ExecStart = "${pkgs.thunderbird}/bin/.thunderbird-wrapped__ --headless";
            Restart = "on-failure";
         };
         Install.WantedBy = [ "graphical-session.target" ];
      };
      systemd.user.services.thunderbird-gui = {
         Unit = {
            Description = "Mozilla Thunderbird GUI service";
            PartOf = "graphical-session.target";
            Conflicts = "thunderbird-monitor.service";
            After = "thunderbird-monitor.service";
         };
         Service = {
            Type = "notify";
            NotifyAccess = "all";
            ExecStart = let
               # Best-effort guess when Thunderbird is "ready" (i.e. started up
               # enough to reject subsequent instance starts), as subsequent
               # thunderbird invocations shouldn't spawn a new-instance but
               # can change the active instance (i.e. thunderbird -mail)
               thunderbird-gui = pkgs.writeShellScriptBin "thunderbird-gui" ''
                  ${pkgs.thunderbird}/bin/.thunderbird-wrapped__ &
                  pid="$!"
                  sleep 3
                  systemd-notify --ready
                  wait "$pid"
               '';
            in "${thunderbird-gui}/bin/thunderbird-gui";
            ExecStopPost = "systemctl --user --no-block start thunderbird-monitor";
         };
      };
      systemd.user.services.thunderbird-tray = {
         Unit = {
            Description = "Mozilla Thunderbird System Tray (birdtray) service";
            # I also run xfce4-panel in a user service which provides my
            # system-tray (its service is called shell-panel.service)
            PartOf = "shell-panel.service";
            After = "shell-panel.service";
         };
         Service = {
            ExecStart = "${pkgs.birdtray}/bin/birdtray";
            Restart = "on-failure";
         };
         Install.WantedBy = [ "shell-panel.service" ];
      };

Overlay Thunderbird to use a wrapped binary which goes through the above services:

      nixpkgs = {
         overlays = [
            (self: super: {
               thunderbird = super.symlinkJoin {
                 name = "thunderbird-gui-wrap";
                 paths = [ super.thunderbird ];
                 buildInputs = [ super.makeWrapper ];
                 postBuild = ''
                   wrapProgram $out/bin/thunderbird \
                     --run 'systemctl --user start thunderbird-gui'
                 '';
               };
            })

Switch to the new configuration, configure birdtray to monitor the account folders I care about, and I’ve got a background running Thunderbird (which updates its folders for birdtray to notice and pops up nice new-email notifications). Open Thunderbird and the background instance is stopped until I close the GUI client, at which point its restarted to keep on monitoring my e-mail.

All made possible by a nice configuration of NixOS (and home-manager).

Thanks,
simplejack

1 Like