1{
2 pkgs,
3 config,
4 lib,
5 ...
6}:
7let
8 cfg = config.programs.thunderbird;
9 policyFormat = pkgs.formats.json { };
10 policyDoc = "https://github.com/thunderbird/policy-templates";
11in
12{
13 options.programs.thunderbird = {
14 enable = lib.mkEnableOption "Thunderbird mail client";
15
16 package = lib.mkPackageOption pkgs "thunderbird" { };
17
18 policies = lib.mkOption {
19 type = policyFormat.type;
20 default = { };
21 description = ''
22 Group policies to install.
23
24 See [Thunderbird's documentation](${policyDoc})
25 for a list of available options.
26
27 This can be used to install extensions declaratively! Check out the
28 documentation of the `ExtensionSettings` policy for details.
29
30 '';
31 };
32
33 preferences = lib.mkOption {
34 type =
35 with lib.types;
36 attrsOf (oneOf [
37 bool
38 int
39 str
40 ]);
41 default = { };
42 description = ''
43 Preferences to set from `about:config`.
44
45 Some of these might be able to be configured more ergonomically
46 using policies.
47 '';
48 };
49
50 preferencesStatus = lib.mkOption {
51 type = lib.types.enum [
52 "default"
53 "locked"
54 "user"
55 "clear"
56 ];
57 default = "locked";
58 description = ''
59 The status of `thunderbird.preferences`.
60
61 `status` can assume the following values:
62 - `"default"`: Preferences appear as default.
63 - `"locked"`: Preferences appear as default and can't be changed.
64 - `"user"`: Preferences appear as changed.
65 - `"clear"`: Value has no effect. Resets to factory defaults on each startup.
66 '';
67 };
68 };
69
70 config = lib.mkIf cfg.enable {
71 environment.systemPackages = [ cfg.package ];
72
73 environment.etc =
74 let
75 policiesJSON = policyFormat.generate "thunderbird-policies.json" { inherit (cfg) policies; };
76 in
77 lib.mkIf (cfg.policies != { }) { "thunderbird/policies/policies.json".source = policiesJSON; };
78
79 programs.thunderbird.policies = {
80 DisableAppUpdate = true;
81 Preferences = builtins.mapAttrs (_: value: {
82 Value = value;
83 Status = cfg.preferencesStatus;
84 }) cfg.preferences;
85 };
86 };
87
88 meta.maintainers = with lib.maintainers; [ nydragon ];
89}