lol

Merge pull request #201033 from linsui/firefox

nixos/firefox: add more options

authored by

Anderson Torres and committed by
GitHub
3ec5fa60 4b79a324

+81 -25
+81 -25
nixos/modules/programs/firefox.nix
··· 5 5 let 6 6 cfg = config.programs.firefox; 7 7 8 + nmh = cfg.nativeMessagingHosts; 9 + 8 10 policyFormat = pkgs.formats.json { }; 9 11 10 12 organisationInfo = '' ··· 15 17 given control of your browser, unless of course they also control your 16 18 NixOS configuration. 17 19 ''; 18 - 19 - in { 20 + in 21 + { 20 22 options.programs.firefox = { 21 23 enable = mkEnableOption (mdDoc "the Firefox web browser"); 22 24 23 25 package = mkOption { 24 - description = mdDoc "Firefox package to use."; 25 26 type = types.package; 26 27 default = pkgs.firefox; 28 + description = mdDoc "Firefox package to use."; 27 29 defaultText = literalExpression "pkgs.firefox"; 28 30 relatedPackages = [ 29 31 "firefox" ··· 31 33 "firefox-bin" 32 34 "firefox-devedition-bin" 33 35 "firefox-esr" 34 - "firefox-esr-wayland" 35 - "firefox-wayland" 36 36 ]; 37 37 }; 38 38 39 39 policies = mkOption { 40 + type = policyFormat.type; 41 + default = { }; 40 42 description = mdDoc '' 41 43 Group policies to install. 42 44 ··· 48 50 49 51 ${organisationInfo} 50 52 ''; 51 - type = policyFormat.type; 52 - default = {}; 53 53 }; 54 54 55 55 preferences = mkOption { 56 + type = with types; attrsOf (oneOf [ bool int string ]); 57 + default = { }; 56 58 description = mdDoc '' 57 - Preferences to set from `about://config`. 59 + Preferences to set from `about:config`. 58 60 59 61 Some of these might be able to be configured more ergonomically 60 62 using policies. 61 63 62 64 ${organisationInfo} 63 65 ''; 64 - type = with types; attrsOf (oneOf [ bool int string ]); 65 - default = {}; 66 + }; 67 + 68 + preferencesStatus = mkOption { 69 + type = types.enum [ "default" "locked" "user" "clear" ]; 70 + default = "locked"; 71 + description = mdDoc '' 72 + The status of `firefox.preferences`. 73 + 74 + `status` can assume the following values: 75 + - `"default"`: Preferences appear as default. 76 + - `"locked"`: Preferences appear as default and can't be changed. 77 + - `"user"`: Preferences appear as changed. 78 + - `"clear"`: Value has no effect. Resets to factory defaults on each startup. 79 + ''; 80 + }; 81 + 82 + autoConfig = mkOption { 83 + type = types.lines; 84 + default = ""; 85 + description = mdDoc '' 86 + AutoConfig files can be used to set and lock preferences that are not covered 87 + by the policies.json for Mac and Linux. This method can be used to automatically 88 + change user preferences or prevent the end user from modifiying specific 89 + preferences by locking them. More info can be found in https://support.mozilla.org/en-US/kb/customizing-firefox-using-autoconfig. 90 + ''; 91 + }; 92 + 93 + nativeMessagingHosts = mapAttrs (_: v: mkEnableOption (mdDoc v)) { 94 + browserpass = "Browserpass support"; 95 + bukubrow = "Bukubrow support"; 96 + ff2mpv = "ff2mpv support"; 97 + fxCast = "fx_cast support"; 98 + gsconnect = "GSConnect support"; 99 + jabref = "JabRef support"; 100 + passff = "PassFF support"; 101 + tridactyl = "Tridactyl support"; 102 + ugetIntegrator = "Uget Integrator support"; 66 103 }; 67 104 }; 68 105 69 106 config = mkIf cfg.enable { 70 - environment.systemPackages = [ cfg.package ]; 107 + environment.systemPackages = [ 108 + (cfg.package.override { 109 + extraPrefs = cfg.autoConfig; 110 + extraNativeMessagingHosts = with pkgs; optionals nmh.ff2mpv [ 111 + ff2mpv 112 + ] ++ optionals nmh.gsconnect [ 113 + gnomeExtensions.gsconnect 114 + ] ++ optionals nmh.jabref [ 115 + jabref 116 + ] ++ optionals nmh.passff [ 117 + passff-host 118 + ]; 119 + }) 120 + ]; 121 + 122 + nixpkgs.config.firefox = { 123 + enableBrowserpass = nmh.browserpass; 124 + enableBukubrow = nmh.bukubrow; 125 + enableTridactylNative = nmh.tridactyl; 126 + enableUgetIntegrator = nmh.ugetIntegrator; 127 + enableFXCastBridge = nmh.fxCast; 128 + }; 71 129 72 - environment.etc."firefox/policies/policies.json".source = 73 - let policiesJSON = 74 - policyFormat.generate 75 - "firefox-policies.json" 76 - { inherit (cfg) policies; }; 77 - in mkIf (cfg.policies != {}) "${policiesJSON}"; 130 + environment.etc = 131 + let 132 + policiesJSON = policyFormat.generate "firefox-policies.json" { inherit (cfg) policies; }; 133 + in 134 + mkIf (cfg.policies != { }) { 135 + "firefox/policies/policies.json".source = "${policiesJSON}"; 136 + }; 78 137 79 138 # Preferences are converted into a policy 80 - programs.firefox.policies = 81 - mkIf (cfg.preferences != {}) 82 - { 83 - Preferences = (mapAttrs (name: value: { 84 - Value = value; 85 - Status = "locked"; 86 - }) cfg.preferences); 87 - }; 139 + programs.firefox.policies = mkIf (cfg.preferences != { }) { 140 + Preferences = (mapAttrs 141 + (_: value: { Value = value; Status = cfg.preferencesStatus; }) 142 + cfg.preferences); 143 + }; 88 144 }; 89 145 90 146 meta.maintainers = with maintainers; [ danth ];