From b764068a506c6f70dba998efa0e7fcb99cb4deb2 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 21 Sep 2022 18:03:17 +0200 Subject: [PATCH] thunderbird: add module Add a new Thunderbird module that uses the configuration in `accounts.email.accounts` to setup SMTP and IMAP accounts. Multiple profiles are not supported at this point. --- .github/CODEOWNERS | 3 + modules/lib/maintainers.nix | 16 + modules/misc/news.nix | 8 + modules/modules.nix | 1 + modules/programs/thunderbird.nix | 275 ++++++++++++++++++ tests/default.nix | 1 + .../modules/programs/thunderbird/default.nix | 1 + .../thunderbird/thunderbird-expected-first.js | 61 ++++ .../thunderbird-expected-profiles.ini | 15 + .../thunderbird-expected-second.js | 31 ++ .../programs/thunderbird/thunderbird.nix | 64 ++++ 11 files changed, 476 insertions(+) create mode 100644 modules/programs/thunderbird.nix create mode 100644 tests/modules/programs/thunderbird/default.nix create mode 100644 tests/modules/programs/thunderbird/thunderbird-expected-first.js create mode 100644 tests/modules/programs/thunderbird/thunderbird-expected-profiles.ini create mode 100644 tests/modules/programs/thunderbird/thunderbird-expected-second.js create mode 100644 tests/modules/programs/thunderbird/thunderbird.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b39486cf6..68e0760df 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -312,6 +312,9 @@ Makefile @thiagokokada /modules/programs/texlive.nix @rycee +/modules/programs/thunderbird.nix @d-dervishi +/tests/modules/programs/thunderbird @d-dervishi + /modules/programs/timidity.nix @amesgen /modules/programs/tint2.nix @CarlosLoboxyz diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index cbe779682..896e47f68 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -37,12 +37,28 @@ github = "CarlosLoboxyz"; githubId = 86011416; }; + d-dervishi = { + email = "david.dervishi@epfl.ch"; + github = "d-dervishi"; + githubId = 61125355; + name = "David Dervishi"; + keys = [{ + longKeyId = "rsa4096/0xB1C012F0E7697195"; + fingerprint = "4C92 E3B0 21B5 5562 A1E0 CE3D B1C0 12F0 E769 7195"; + }]; + }; dwagenk = { email = "dwagenk@mailbox.org"; github = "dwagenk"; githubId = 32838899; name = "Daniel Wagenknecht"; }; + jkarlson = { + email = "jekarlson@gmail.com"; + github = "jkarlson"; + githubId = 1204734; + name = "Emil Karlson"; + }; justinlovinger = { name = "Justin Lovinger"; email = "git@justinlovinger.com"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index bb1e7e2be..34c2e0e1d 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -815,6 +815,14 @@ in A new module is available: 'xfconf'. ''; } + + { + time = "2022-11-04T14:56:46+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'programs.thunderbird'; + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index d465e8caa..a57925ea9 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -176,6 +176,7 @@ let ./programs/terminator.nix ./programs/termite.nix ./programs/texlive.nix + ./programs/thunderbird.nix ./programs/timidity.nix ./programs/tint2.nix ./programs/tiny.nix diff --git a/modules/programs/thunderbird.nix b/modules/programs/thunderbird.nix new file mode 100644 index 000000000..118a98a62 --- /dev/null +++ b/modules/programs/thunderbird.nix @@ -0,0 +1,275 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.programs.thunderbird; + + enabledAccounts = attrValues + (filterAttrs (_: a: a.thunderbird.enable) config.accounts.email.accounts); + + enabledAccountsWithId = + map (a: a // { id = builtins.hashString "sha256" a.name; }) enabledAccounts; + + thunderbirdConfigPath = ".thunderbird"; + + profilesWithId = + imap0 (i: v: v // { id = toString i; }) (attrValues cfg.profiles); + + profilesIni = foldl recursiveUpdate { + General = { + StartWithLastProfile = 1; + Version = 2; + }; + } (flip map profilesWithId (profile: { + "Profile${profile.id}" = { + Name = profile.name; + Path = profile.name; + IsRelative = 1; + Default = if profile.isDefault then 1 else 0; + }; + })); + + toThunderbirdAccount = account: profile: + let id = account.id; + in { + "mail.account.account_${id}.identities" = "id_${id}"; + "mail.account.account_${id}.server" = "server_${id}"; + "mail.identity.id_${id}.fullName" = account.realName; + "mail.identity.id_${id}.useremail" = account.address; + "mail.identity.id_${id}.valid" = true; + } // optionalAttrs account.primary { + "mail.accountmanager.defaultaccount" = "account_${id}"; + } // optionalAttrs (account.gpg != null) { + "mail.identity.id_${id}.attachPgpKey" = false; + "mail.identity.id_${id}.autoEncryptDrafts" = true; + "mail.identity.id_${id}.e2etechpref" = 0; + "mail.identity.id_${id}.encryptionpolicy" = + if account.gpg.encryptByDefault then 2 else 0; + "mail.identity.id_${id}.is_gnupg_key_id" = true; + "mail.identity.id_${id}.last_entered_external_gnupg_key_id" = + account.gpg.key; + "mail.identity.id_${id}.openpgp_key_id" = account.gpg.key; + "mail.identity.id_${id}.protectSubject" = true; + "mail.identity.id_${id}.sign_mail" = account.gpg.signByDefault; + } // optionalAttrs (account.imap != null) { + "mail.server.server_${id}.directory" = + "${thunderbirdConfigPath}/${profile.name}/ImapMail/${account.imap.host}"; + "mail.server.server_${id}.directory-rel" = + "[ProfD]ImapMail/${account.imap.host}"; + "mail.server.server_${id}.hostname" = account.imap.host; + "mail.server.server_${id}.login_at_startup" = true; + "mail.server.server_${id}.name" = account.name; + "mail.server.server_${id}.port" = + if (account.imap.port != null) then account.imap.port else 143; + "mail.server.server_${id}.socketType" = if !account.imap.tls.enable then + 0 + else if account.imap.tls.useStartTls then + 2 + else + 3; + "mail.server.server_${id}.type" = "imap"; + "mail.server.server_${id}.userName" = account.userName; + } // optionalAttrs (account.smtp != null) { + "mail.identity.id_${id}.smtpServer" = "smtp_${id}"; + "mail.smtpserver.smtp_${id}.authMethod" = 3; + "mail.smtpserver.smtp_${id}.hostname" = account.smtp.host; + "mail.smtpserver.smtp_${id}.port" = + if (account.smtp.port != null) then account.smtp.port else 587; + "mail.smtpserver.smtp_${id}.try_ssl" = if !account.smtp.tls.enable then + 0 + else if account.smtp.tls.useStartTls then + 2 + else + 3; + "mail.smtpserver.smtp_${id}.username" = account.userName; + } // optionalAttrs (account.smtp != null && account.primary) { + "mail.smtp.defaultserver" = "smtp_${id}"; + } // account.thunderbird.settings id; + + mkUserJs = prefs: '' + // Generated by Home Manager. + + ${concatStrings (mapAttrsToList (name: value: '' + user_pref("${name}", ${builtins.toJSON value}); + '') prefs)} + ''; +in { + meta.maintainers = with hm.maintainers; [ d-dervishi jkarlson ]; + + options = { + programs.thunderbird = { + enable = mkEnableOption "Thunderbird"; + + package = mkOption { + type = types.package; + default = pkgs.thunderbird; + defaultText = literalExpression "pkgs.thunderbird"; + example = literalExpression "pkgs.thunderbird-91"; + description = "The Thunderbird package to use."; + }; + + profiles = mkOption { + type = with types; + attrsOf (submodule ({ config, name, ... }: { + options = { + name = mkOption { + type = types.str; + default = name; + readOnly = true; + description = "This profile's name."; + }; + + isDefault = mkOption { + type = types.bool; + default = false; + example = true; + description = '' + Whether this is a default profile. There must be exactly one + default profile. + ''; + }; + + settings = mkOption { + type = with types; attrsOf (oneOf [ bool int str ]); + default = { }; + example = literalExpression '' + { + "mail.spellcheck.inline" = false; + } + ''; + description = '' + Preferences to add to this profile's + user.js. + ''; + }; + + withExternalGnupg = mkOption { + type = types.bool; + default = false; + example = true; + description = "Allow using external GPG keys with GPGME."; + }; + }; + })); + }; + + settings = mkOption { + type = with types; attrsOf (oneOf [ bool int str ]); + default = { }; + example = literalExpression '' + { + "general.useragent.override" = ""; + "privacy.donottrackheader.enabled" = true; + } + ''; + description = '' + Attribute set of Thunderbird preferences to be added to + all profiles. + ''; + }; + }; + + accounts.email.accounts = mkOption { + type = with types; + attrsOf (submodule { + options.thunderbird = { + enable = + mkEnableOption "the Thunderbird mail client for this account"; + + profiles = mkOption { + type = with types; listOf str; + default = [ ]; + example = literalExpression '' + [ "profile1" "profile2" ] + ''; + description = '' + List of Thunderbird profiles for which this account should be + enabled. If this list is empty (the default), this account will + be enabled for all declared profiles. + ''; + }; + + settings = mkOption { + type = with types; functionTo (attrsOf (oneOf [ bool int str ])); + default = _: { }; + defaultText = literalExpression "_: { }"; + example = literalExpression '' + id: { + "mail.identity.id_''${id}.protectSubject" = false; + "mail.identity.id_''${id}.autoEncryptDrafts" = false; + }; + ''; + description = '' + Extra settings to add to this Thunderbird account configuration. + The id given as argument is an automatically + generated account identifier. + ''; + }; + }; + }); + }; + }; + + config = mkIf cfg.enable { + assertions = [ + (hm.assertions.assertPlatform "programs.thunderbird" pkgs platforms.linux) + + (let defaults = catAttrs "name" (filter (a: a.isDefault) profilesWithId); + in { + assertion = cfg.profiles == { } || length defaults == 1; + message = "Must have exactly one default Thunderbird profile but found " + + toString (length defaults) + optionalString (length defaults > 1) + (", namely " concatStringsSep "," defaults); + }) + + (let + profiles = catAttrs "name" profilesWithId; + selectedProfiles = + concatMap (a: a.thunderbird.profiles) enabledAccounts; + in { + assertion = (intersectLists profiles selectedProfiles) + == selectedProfiles; + message = "Cannot enable an account for a non-declared profile. " + + "The declared profiles are " + (concatStringsSep "," profiles) + + ", but the used profiles are " + + (concatStringsSep "," selectedProfiles); + }) + ]; + + home.packages = [ cfg.package ] + ++ optional (any (p: p.withExternalGnupg) (attrValues cfg.profiles)) + pkgs.gpgme; + + home.file = mkMerge ([{ + "${thunderbirdConfigPath}/profiles.ini" = + mkIf (cfg.profiles != { }) { text = generators.toINI { } profilesIni; }; + }] ++ flip mapAttrsToList cfg.profiles (name: profile: { + "${thunderbirdConfigPath}/${name}/user.js" = let + accounts = filter (a: + a.thunderbird.profiles == [ ] + || any (p: p == name) a.thunderbird.profiles) enabledAccountsWithId; + + smtp = filter (a: a.smtp != null) accounts; + in { + text = mkUserJs (builtins.foldl' (a: b: a // b) { } ([ + cfg.settings + + (optionalAttrs (length accounts != 0) { + "mail.accountmanager.accounts" = + concatStringsSep "," (map (a: "account_${a.id}") accounts); + }) + + (optionalAttrs (length smtp != 0) { + "mail.smtpservers" = + concatStringsSep "," (map (a: "smtp_${a.id}") smtp); + }) + + { "mail.openpgp.allow_external_gnupg" = profile.withExternalGnupg; } + + profile.settings + ] ++ (map (a: toThunderbirdAccount a profile) accounts))); + }; + })); + }; +} diff --git a/tests/default.nix b/tests/default.nix index e78e24369..f4f8d877e 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -160,6 +160,7 @@ import nmt { ./modules/programs/rofi-pass ./modules/programs/swaylock ./modules/programs/terminator + ./modules/programs/thunderbird ./modules/programs/waybar ./modules/programs/xmobar ./modules/programs/yt-dlp diff --git a/tests/modules/programs/thunderbird/default.nix b/tests/modules/programs/thunderbird/default.nix new file mode 100644 index 000000000..487297784 --- /dev/null +++ b/tests/modules/programs/thunderbird/default.nix @@ -0,0 +1 @@ +{ thunderbird = ./thunderbird.nix; } diff --git a/tests/modules/programs/thunderbird/thunderbird-expected-first.js b/tests/modules/programs/thunderbird/thunderbird-expected-first.js new file mode 100644 index 000000000..6fc45b0e8 --- /dev/null +++ b/tests/modules/programs/thunderbird/thunderbird-expected-first.js @@ -0,0 +1,61 @@ +// Generated by Home Manager. + +user_pref("general.useragent.override", ""); +user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.identities", "id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); +user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.server", "server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); +user_pref("mail.account.account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.identities", "id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); +user_pref("mail.account.account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.server", "server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); +user_pref("mail.accountmanager.accounts", "account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc,account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); +user_pref("mail.accountmanager.defaultaccount", "account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.autoEncryptDrafts", false); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.fullName", "H. M. Test Jr."); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.protectSubject", false); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.smtpServer", "smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.useremail", "hm@example.org"); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.valid", true); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.attachPgpKey", false); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.autoEncryptDrafts", true); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.e2etechpref", 0); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.encryptionpolicy", 0); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.fullName", "H. M. Test"); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.is_gnupg_key_id", true); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.last_entered_external_gnupg_key_id", "ABC"); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.openpgp_key_id", "ABC"); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.protectSubject", true); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.sign_mail", false); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.smtpServer", "smtp_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.useremail", "hm@example.com"); +user_pref("mail.identity.id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.valid", true); +user_pref("mail.openpgp.allow_external_gnupg", true); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.directory", ".thunderbird/first/ImapMail/imap.example.org"); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.directory-rel", "[ProfD]ImapMail/imap.example.org"); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.hostname", "imap.example.org"); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.login_at_startup", true); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.name", "hm-account"); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.port", 143); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.socketType", 3); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.type", "imap"); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.userName", "home.manager.jr"); +user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.directory", ".thunderbird/first/ImapMail/imap.example.com"); +user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.directory-rel", "[ProfD]ImapMail/imap.example.com"); +user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.hostname", "imap.example.com"); +user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.login_at_startup", true); +user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.name", "hm@example.com"); +user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.port", 123); +user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.socketType", 3); +user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.type", "imap"); +user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.userName", "home.manager"); +user_pref("mail.smtp.defaultserver", "smtp_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); +user_pref("mail.smtpserver.smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.authMethod", 3); +user_pref("mail.smtpserver.smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.hostname", "smtp.example.org"); +user_pref("mail.smtpserver.smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.port", 587); +user_pref("mail.smtpserver.smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.try_ssl", 2); +user_pref("mail.smtpserver.smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.username", "home.manager.jr"); +user_pref("mail.smtpserver.smtp_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.authMethod", 3); +user_pref("mail.smtpserver.smtp_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.hostname", "smtp.example.com"); +user_pref("mail.smtpserver.smtp_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.port", 456); +user_pref("mail.smtpserver.smtp_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.try_ssl", 3); +user_pref("mail.smtpserver.smtp_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.username", "home.manager"); +user_pref("mail.smtpservers", "smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc,smtp_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); +user_pref("privacy.donottrackheader.enabled", true); + diff --git a/tests/modules/programs/thunderbird/thunderbird-expected-profiles.ini b/tests/modules/programs/thunderbird/thunderbird-expected-profiles.ini new file mode 100644 index 000000000..4191f1607 --- /dev/null +++ b/tests/modules/programs/thunderbird/thunderbird-expected-profiles.ini @@ -0,0 +1,15 @@ +[General] +StartWithLastProfile=1 +Version=2 + +[Profile0] +Default=1 +IsRelative=1 +Name=first +Path=first + +[Profile1] +Default=0 +IsRelative=1 +Name=second +Path=second diff --git a/tests/modules/programs/thunderbird/thunderbird-expected-second.js b/tests/modules/programs/thunderbird/thunderbird-expected-second.js new file mode 100644 index 000000000..f18427a95 --- /dev/null +++ b/tests/modules/programs/thunderbird/thunderbird-expected-second.js @@ -0,0 +1,31 @@ +// Generated by Home Manager. + +user_pref("general.useragent.override", ""); +user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.identities", "id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); +user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.server", "server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); +user_pref("mail.accountmanager.accounts", "account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.autoEncryptDrafts", false); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.fullName", "H. M. Test Jr."); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.protectSubject", false); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.smtpServer", "smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.useremail", "hm@example.org"); +user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.valid", true); +user_pref("mail.openpgp.allow_external_gnupg", false); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.directory", ".thunderbird/second/ImapMail/imap.example.org"); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.directory-rel", "[ProfD]ImapMail/imap.example.org"); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.hostname", "imap.example.org"); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.login_at_startup", true); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.name", "hm-account"); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.port", 143); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.socketType", 3); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.type", "imap"); +user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.userName", "home.manager.jr"); +user_pref("mail.smtpserver.smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.authMethod", 3); +user_pref("mail.smtpserver.smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.hostname", "smtp.example.org"); +user_pref("mail.smtpserver.smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.port", 587); +user_pref("mail.smtpserver.smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.try_ssl", 2); +user_pref("mail.smtpserver.smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.username", "home.manager.jr"); +user_pref("mail.smtpservers", "smtp_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); +user_pref("privacy.donottrackheader.enabled", true); +user_pref("second.setting", "some-test-setting"); + diff --git a/tests/modules/programs/thunderbird/thunderbird.nix b/tests/modules/programs/thunderbird/thunderbird.nix new file mode 100644 index 000000000..ee16efa06 --- /dev/null +++ b/tests/modules/programs/thunderbird/thunderbird.nix @@ -0,0 +1,64 @@ +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + accounts.email.accounts = { + "hm@example.com" = { + thunderbird = { + enable = true; + profiles = [ "first" ]; + }; + + gpg.key = "ABC"; + + imap = { + port = 123; + tls.enable = true; + }; + smtp.port = 456; + }; + + hm-account = { + thunderbird = { + enable = true; + settings = id: { + "mail.identity.id_${id}.protectSubject" = false; + "mail.identity.id_${id}.autoEncryptDrafts" = false; + }; + }; + }; + }; + + programs.thunderbird = { + enable = true; + + profiles = { + first = { + isDefault = true; + withExternalGnupg = true; + }; + + second.settings = { "second.setting" = "some-test-setting"; }; + }; + + settings = { + "general.useragent.override" = ""; + "privacy.donottrackheader.enabled" = true; + }; + }; + + test.stubs.thunderbird = { }; + + nmt.script = '' + assertFileExists home-files/.thunderbird/profiles.ini + assertFileContent home-files/.thunderbird/profiles.ini \ + ${./thunderbird-expected-profiles.ini} + + assertFileExists home-files/.thunderbird/first/user.js + assertFileContent home-files/.thunderbird/first/user.js \ + ${./thunderbird-expected-first.js} + + assertFileExists home-files/.thunderbird/second/user.js + assertFileContent home-files/.thunderbird/second/user.js \ + ${./thunderbird-expected-second.js} + ''; +}