diff options
author | Nick Cao <nickcao@nichi.co> | 2023-01-14 11:33:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-14 11:33:33 +0800 |
commit | 910dd09ac3190c0bf9b3fc70439c03f1612b7f3b (patch) | |
tree | 28474e9868e5d9ed5e51dcd9da5a9e25834a8704 | |
parent | fcf139f538a909dffbf57c6bd0604e1596e21668 (diff) | |
parent | 44828c98c055c0f5a20b01673a6ff1617387583c (diff) |
Merge pull request #210557 from NixOS/backport-201033-to-release-22.11
[Backport release-22.11] nixos/firefox: add more options
-rw-r--r-- | nixos/modules/programs/firefox.nix | 106 |
1 files changed, 81 insertions, 25 deletions
diff --git a/nixos/modules/programs/firefox.nix b/nixos/modules/programs/firefox.nix index 76e6c1a553f3..dfd912cdf5c1 100644 --- a/nixos/modules/programs/firefox.nix +++ b/nixos/modules/programs/firefox.nix @@ -5,6 +5,8 @@ with lib; let cfg = config.programs.firefox; + nmh = cfg.nativeMessagingHosts; + policyFormat = pkgs.formats.json { }; organisationInfo = '' @@ -15,15 +17,15 @@ let given control of your browser, unless of course they also control your NixOS configuration. ''; - -in { +in +{ options.programs.firefox = { enable = mkEnableOption (mdDoc "the Firefox web browser"); package = mkOption { - description = mdDoc "Firefox package to use."; type = types.package; default = pkgs.firefox; + description = mdDoc "Firefox package to use."; defaultText = literalExpression "pkgs.firefox"; relatedPackages = [ "firefox" @@ -31,12 +33,12 @@ in { "firefox-bin" "firefox-devedition-bin" "firefox-esr" - "firefox-esr-wayland" - "firefox-wayland" ]; }; policies = mkOption { + type = policyFormat.type; + default = { }; description = mdDoc '' Group policies to install. @@ -48,43 +50,97 @@ in { ${organisationInfo} ''; - type = policyFormat.type; - default = {}; }; preferences = mkOption { + type = with types; attrsOf (oneOf [ bool int string ]); + default = { }; description = mdDoc '' - Preferences to set from `about://config`. + Preferences to set from `about:config`. Some of these might be able to be configured more ergonomically using policies. ${organisationInfo} ''; - type = with types; attrsOf (oneOf [ bool int string ]); - default = {}; + }; + + preferencesStatus = mkOption { + type = types.enum [ "default" "locked" "user" "clear" ]; + default = "locked"; + description = mdDoc '' + The status of `firefox.preferences`. + + `status` can assume the following values: + - `"default"`: Preferences appear as default. + - `"locked"`: Preferences appear as default and can't be changed. + - `"user"`: Preferences appear as changed. + - `"clear"`: Value has no effect. Resets to factory defaults on each startup. + ''; + }; + + autoConfig = mkOption { + type = types.lines; + default = ""; + description = mdDoc '' + AutoConfig files can be used to set and lock preferences that are not covered + by the policies.json for Mac and Linux. This method can be used to automatically + change user preferences or prevent the end user from modifiying specific + preferences by locking them. More info can be found in https://support.mozilla.org/en-US/kb/customizing-firefox-using-autoconfig. + ''; + }; + + nativeMessagingHosts = mapAttrs (_: v: mkEnableOption (mdDoc v)) { + browserpass = "Browserpass support"; + bukubrow = "Bukubrow support"; + ff2mpv = "ff2mpv support"; + fxCast = "fx_cast support"; + gsconnect = "GSConnect support"; + jabref = "JabRef support"; + passff = "PassFF support"; + tridactyl = "Tridactyl support"; + ugetIntegrator = "Uget Integrator support"; }; }; config = mkIf cfg.enable { - environment.systemPackages = [ cfg.package ]; + environment.systemPackages = [ + (cfg.package.override { + extraPrefs = cfg.autoConfig; + extraNativeMessagingHosts = with pkgs; optionals nmh.ff2mpv [ + ff2mpv + ] ++ optionals nmh.gsconnect [ + gnomeExtensions.gsconnect + ] ++ optionals nmh.jabref [ + jabref + ] ++ optionals nmh.passff [ + passff-host + ]; + }) + ]; + + nixpkgs.config.firefox = { + enableBrowserpass = nmh.browserpass; + enableBukubrow = nmh.bukubrow; + enableTridactylNative = nmh.tridactyl; + enableUgetIntegrator = nmh.ugetIntegrator; + enableFXCastBridge = nmh.fxCast; + }; - environment.etc."firefox/policies/policies.json".source = - let policiesJSON = - policyFormat.generate - "firefox-policies.json" - { inherit (cfg) policies; }; - in mkIf (cfg.policies != {}) "${policiesJSON}"; + environment.etc = + let + policiesJSON = policyFormat.generate "firefox-policies.json" { inherit (cfg) policies; }; + in + mkIf (cfg.policies != { }) { + "firefox/policies/policies.json".source = "${policiesJSON}"; + }; # Preferences are converted into a policy - programs.firefox.policies = - mkIf (cfg.preferences != {}) - { - Preferences = (mapAttrs (name: value: { - Value = value; - Status = "locked"; - }) cfg.preferences); - }; + programs.firefox.policies = mkIf (cfg.preferences != { }) { + Preferences = (mapAttrs + (_: value: { Value = value; Status = cfg.preferencesStatus; }) + cfg.preferences); + }; }; meta.maintainers = with maintainers; [ danth ]; |