1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-22 09:49:47 +01:00

thunderbird: allow using the module on Darwin

While the Nix packages for Thunderbird are not available for macOS,
the module can still be used to manage profiles and configuration.

Fixes #3407.
This commit is contained in:
David 2022-11-11 17:31:39 +01:00 committed by Robert Helgesson
parent 6ce3493a3c
commit 651db464dc
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
2 changed files with 60 additions and 8 deletions

View file

@ -820,7 +820,27 @@ in
time = "2022-11-04T14:56:46+00:00"; time = "2022-11-04T14:56:46+00:00";
condition = hostPlatform.isLinux; condition = hostPlatform.isLinux;
message = '' message = ''
A new module is available: 'programs.thunderbird'; A new module is available: 'programs.thunderbird'.
'';
}
{
time = "2022-11-13T09:05:51+00:00";
condition = hostPlatform.isDarwin;
message = ''
A new module is available: 'programs.thunderbird'.
Please note that the Thunderbird packages provided by Nix are
currently not working on macOS. The module can still be used to manage
configuration files by installing Thunderbird manually and setting the
'programs.thunderbird.package' option to a dummy package, for example
using 'pkgs.runCommand'.
This module requires you to set the following environment variables
when using an installation of Thunderbird that is not provided by Nix:
export MOZ_LEGACY_PROFILES=1
export MOZ_ALLOW_DOWNGRADE=1
''; '';
} }
]; ];

View file

@ -3,6 +3,8 @@
with lib; with lib;
let let
inherit (pkgs.stdenv.hostPlatform) isDarwin;
cfg = config.programs.thunderbird; cfg = config.programs.thunderbird;
enabledAccounts = attrValues enabledAccounts = attrValues
@ -11,7 +13,13 @@ let
enabledAccountsWithId = enabledAccountsWithId =
map (a: a // { id = builtins.hashString "sha256" a.name; }) enabledAccounts; map (a: a // { id = builtins.hashString "sha256" a.name; }) enabledAccounts;
thunderbirdConfigPath = ".thunderbird"; thunderbirdConfigPath =
if isDarwin then "Library/Thunderbird" else ".thunderbird";
thunderbirdProfilesPath = if isDarwin then
"${thunderbirdConfigPath}/Profiles"
else
thunderbirdConfigPath;
profilesWithId = profilesWithId =
imap0 (i: v: v // { id = toString i; }) (attrValues cfg.profiles); imap0 (i: v: v // { id = toString i; }) (attrValues cfg.profiles);
@ -24,7 +32,7 @@ let
} (flip map profilesWithId (profile: { } (flip map profilesWithId (profile: {
"Profile${profile.id}" = { "Profile${profile.id}" = {
Name = profile.name; Name = profile.name;
Path = profile.name; Path = if isDarwin then "Profiles/${profile.name}" else profile.name;
IsRelative = 1; IsRelative = 1;
Default = if profile.isDefault then 1 else 0; Default = if profile.isDefault then 1 else 0;
}; };
@ -54,7 +62,7 @@ let
"mail.identity.id_${id}.sign_mail" = account.gpg.signByDefault; "mail.identity.id_${id}.sign_mail" = account.gpg.signByDefault;
} // optionalAttrs (account.imap != null) { } // optionalAttrs (account.imap != null) {
"mail.server.server_${id}.directory" = "mail.server.server_${id}.directory" =
"${thunderbirdConfigPath}/${profile.name}/ImapMail/${account.imap.host}"; "${thunderbirdProfilesPath}/${profile.name}/ImapMail/${account.imap.host}";
"mail.server.server_${id}.directory-rel" = "mail.server.server_${id}.directory-rel" =
"[ProfD]ImapMail/${account.imap.host}"; "[ProfD]ImapMail/${account.imap.host}";
"mail.server.server_${id}.hostname" = account.imap.host; "mail.server.server_${id}.hostname" = account.imap.host;
@ -168,6 +176,18 @@ in {
all profiles. all profiles.
''; '';
}; };
darwinSetupWarning = mkOption {
type = types.bool;
default = true;
example = false;
visible = isDarwin;
readOnly = !isDarwin;
description = ''
Warn to set environment variables before using this module. Only
relevant on Darwin.
'';
};
}; };
accounts.email.accounts = mkOption { accounts.email.accounts = mkOption {
@ -213,14 +233,12 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
assertions = [ assertions = [
(hm.assertions.assertPlatform "programs.thunderbird" pkgs platforms.linux)
(let defaults = catAttrs "name" (filter (a: a.isDefault) profilesWithId); (let defaults = catAttrs "name" (filter (a: a.isDefault) profilesWithId);
in { in {
assertion = cfg.profiles == { } || length defaults == 1; assertion = cfg.profiles == { } || length defaults == 1;
message = "Must have exactly one default Thunderbird profile but found " message = "Must have exactly one default Thunderbird profile but found "
+ toString (length defaults) + optionalString (length defaults > 1) + toString (length defaults) + optionalString (length defaults > 1)
(", namely " concatStringsSep "," defaults); (", namely " + concatStringsSep "," defaults);
}) })
(let (let
@ -237,6 +255,20 @@ in {
}) })
]; ];
warnings = optional (isDarwin && cfg.darwinSetupWarning) ''
Thunderbird packages are not yet supported on Darwin. You can still use
this module to manage your accounts and profiles by setting
'programs.thunderbird.package' to a dummy value, for example using
'pkgs.runCommand'.
Note that this module requires you to set the following environment
variables when using an installation of Thunderbird that is not provided
by Nix:
export MOZ_LEGACY_PROFILES=1
export MOZ_ALLOW_DOWNGRADE=1
'';
home.packages = [ cfg.package ] home.packages = [ cfg.package ]
++ optional (any (p: p.withExternalGnupg) (attrValues cfg.profiles)) ++ optional (any (p: p.withExternalGnupg) (attrValues cfg.profiles))
pkgs.gpgme; pkgs.gpgme;
@ -245,7 +277,7 @@ in {
"${thunderbirdConfigPath}/profiles.ini" = "${thunderbirdConfigPath}/profiles.ini" =
mkIf (cfg.profiles != { }) { text = generators.toINI { } profilesIni; }; mkIf (cfg.profiles != { }) { text = generators.toINI { } profilesIni; };
}] ++ flip mapAttrsToList cfg.profiles (name: profile: { }] ++ flip mapAttrsToList cfg.profiles (name: profile: {
"${thunderbirdConfigPath}/${name}/user.js" = let "${thunderbirdProfilesPath}/${name}/user.js" = let
accounts = filter (a: accounts = filter (a:
a.thunderbird.profiles == [ ] a.thunderbird.profiles == [ ]
|| any (p: p == name) a.thunderbird.profiles) enabledAccountsWithId; || any (p: p == name) a.thunderbird.profiles) enabledAccountsWithId;