at 23.05-pre 2.5 kB view raw
1{ pkgs, config, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.programs.firefox; 7 8 policyFormat = pkgs.formats.json { }; 9 10 organisationInfo = '' 11 When this option is in use, Firefox will inform you that "your browser 12 is managed by your organisation". That message appears because NixOS 13 installs what you have declared here such that it cannot be overridden 14 through the user interface. It does not mean that someone else has been 15 given control of your browser, unless of course they also control your 16 NixOS configuration. 17 ''; 18 19in { 20 options.programs.firefox = { 21 enable = mkEnableOption (mdDoc "the Firefox web browser"); 22 23 package = mkOption { 24 description = mdDoc "Firefox package to use."; 25 type = types.package; 26 default = pkgs.firefox; 27 defaultText = literalExpression "pkgs.firefox"; 28 relatedPackages = [ 29 "firefox" 30 "firefox-beta-bin" 31 "firefox-bin" 32 "firefox-devedition-bin" 33 "firefox-esr" 34 "firefox-esr-wayland" 35 "firefox-wayland" 36 ]; 37 }; 38 39 policies = mkOption { 40 description = mdDoc '' 41 Group policies to install. 42 43 See [Mozilla's documentation](https://github.com/mozilla/policy-templates/blob/master/README.md") 44 for a list of available options. 45 46 This can be used to install extensions declaratively! Check out the 47 documentation of the `ExtensionSettings` policy for details. 48 49 ${organisationInfo} 50 ''; 51 type = policyFormat.type; 52 default = {}; 53 }; 54 55 preferences = mkOption { 56 description = mdDoc '' 57 Preferences to set from `about://config`. 58 59 Some of these might be able to be configured more ergonomically 60 using policies. 61 62 ${organisationInfo} 63 ''; 64 type = with types; attrsOf (oneOf [ bool int string ]); 65 default = {}; 66 }; 67 }; 68 69 config = mkIf cfg.enable { 70 environment.systemPackages = [ cfg.package ]; 71 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}"; 78 79 # 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 }; 88 }; 89 90 meta.maintainers = with maintainers; [ danth ]; 91}